Skip to content

Commit

Permalink
Merge pull request #5805 from vector-im/task/eric/format-project
Browse files Browse the repository at this point in the history
Formats project with new code style
  • Loading branch information
ericdecanini authored Apr 21, 2022
2 parents aebdee1 + a5eca12 commit c21ec98
Show file tree
Hide file tree
Showing 225 changed files with 850 additions and 817 deletions.
1 change: 1 addition & 0 deletions changelog.d/5805.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Autoformats entire project
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ImageLoaderTarget {
}

internal class DefaultImageLoaderTarget(val holder: AnimatedImageViewHolder, private val contextView: ImageView) :
ImageLoaderTarget {
ImageLoaderTarget {
override fun contextView(): ImageView {
return contextView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import com.airbnb.mvrx.Mavericks
class JSonViewerDialog : DialogFragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_dialog_jv, container, false)
}
Expand All @@ -39,15 +39,15 @@ class JSonViewerDialog : DialogFragment() {
val args: JSonViewerFragmentArgs = arguments?.getParcelable(Mavericks.KEY_ARG) ?: return
if (savedInstanceState == null) {
childFragmentManager.beginTransaction()
.replace(
R.id.fragmentContainer, JSonViewerFragment.newInstance(
args.jsonString,
args.defaultOpenDepth,
true,
args.styleProvider
.replace(
R.id.fragmentContainer, JSonViewerFragment.newInstance(
args.jsonString,
args.defaultOpenDepth,
true,
args.styleProvider
)
)
.commitNow()
)
.commitNow()
}
}

Expand All @@ -63,13 +63,13 @@ class JSonViewerDialog : DialogFragment() {

companion object {
fun newInstance(
jsonString: String,
initialOpenDepth: Int = -1,
styleProvider: JSonViewerStyleProvider? = null
jsonString: String,
initialOpenDepth: Int = -1,
styleProvider: JSonViewerStyleProvider? = null
): JSonViewerDialog {
val args = Bundle()
val parcelableArgs =
JSonViewerFragmentArgs(jsonString, initialOpenDepth, false, styleProvider)
JSonViewerFragmentArgs(jsonString, initialOpenDepth, false, styleProvider)
args.putParcelable(Mavericks.KEY_ARG, parcelableArgs)
return JSonViewerDialog().apply { arguments = args }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import kotlinx.parcelize.Parcelize

@Parcelize
internal data class JSonViewerFragmentArgs(
val jsonString: String,
val defaultOpenDepth: Int,
val wrap: Boolean,
val styleProvider: JSonViewerStyleProvider?
val jsonString: String,
val defaultOpenDepth: Int,
val wrap: Boolean,
val styleProvider: JSonViewerStyleProvider?
) : Parcelable

class JSonViewerFragment : Fragment(), MavericksView {
Expand All @@ -49,20 +49,20 @@ class JSonViewerFragment : Fragment(), MavericksView {
private lateinit var recyclerView: EpoxyRecyclerView

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val args: JSonViewerFragmentArgs? = arguments?.getParcelable(Mavericks.KEY_ARG)
val inflate =
if (args?.wrap == true) {
inflater.inflate(R.layout.fragment_jv_recycler_view_wrap, container, false)
} else {
inflater.inflate(R.layout.fragment_jv_recycler_view, container, false)
}
if (args?.wrap == true) {
inflater.inflate(R.layout.fragment_jv_recycler_view_wrap, container, false)
} else {
inflater.inflate(R.layout.fragment_jv_recycler_view, container, false)
}
recyclerView = inflate.findViewById(R.id.jvRecyclerView)
recyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
recyclerView.setController(epoxyController)
epoxyController.setStyle(args?.styleProvider)
registerForContextMenu(recyclerView)
Expand All @@ -79,21 +79,21 @@ class JSonViewerFragment : Fragment(), MavericksView {

companion object {
fun newInstance(
jsonString: String,
initialOpenDepth: Int = -1,
wrap: Boolean = false,
styleProvider: JSonViewerStyleProvider? = null
jsonString: String,
initialOpenDepth: Int = -1,
wrap: Boolean = false,
styleProvider: JSonViewerStyleProvider? = null
): JSonViewerFragment {
return JSonViewerFragment().apply {
arguments = Bundle().apply {
putParcelable(
Mavericks.KEY_ARG,
JSonViewerFragmentArgs(
jsonString,
initialOpenDepth,
wrap,
styleProvider
)
Mavericks.KEY_ARG,
JSonViewerFragmentArgs(
jsonString,
initialOpenDepth,
wrap,
styleProvider
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ internal interface Composed {
}

internal class JSonViewerObject(key: String?, index: Int?, jObject: JSONObject) :
JSonViewerModel(key, index, jObject),
Composed {
JSonViewerModel(key, index, jObject),
Composed {

var keys = LinkedHashMap<String, JSonViewerModel>()

Expand All @@ -41,7 +41,7 @@ internal class JSonViewerObject(key: String?, index: Int?, jObject: JSONObject)
}

internal class JSonViewerArray(key: String?, index: Int?, jObject: JSONArray) :
JSonViewerModel(key, index, jObject), Composed {
JSonViewerModel(key, index, jObject), Composed {
var items = ArrayList<JSonViewerModel>()

override fun addChild(model: JSonViewerModel) {
Expand All @@ -50,7 +50,7 @@ internal class JSonViewerArray(key: String?, index: Int?, jObject: JSONArray) :
}

internal class JSonViewerLeaf(key: String?, index: Int?, val stringRes: String, val type: JSONType) :
JSonViewerModel(key, index, stringRes)
JSonViewerModel(key, index, stringRes)

internal enum class JSONType {
STRING,
Expand All @@ -75,41 +75,41 @@ internal object ModelParser {
when (obj) {
is JSONObject -> {
val objectComposed = JSonViewerObject(key, index, obj)
.apply { isExpanded = initialOpenDepth == -1 || depth <= initialOpenDepth }
.apply { isExpanded = initialOpenDepth == -1 || depth <= initialOpenDepth }
objectComposed.depth = depth
obj.keys().forEach {
eval(objectComposed, it, null, obj.get(it), depth + 1, initialOpenDepth)
}
parent.addChild(objectComposed)
}
is JSONArray -> {
is JSONArray -> {
val objectComposed = JSonViewerArray(key, index, obj)
.apply { isExpanded = initialOpenDepth == -1 || depth <= initialOpenDepth }
.apply { isExpanded = initialOpenDepth == -1 || depth <= initialOpenDepth }
objectComposed.depth = depth
for (i in 0 until obj.length()) {
eval(objectComposed, null, i, obj[i], depth + 1, initialOpenDepth)
}
parent.addChild(objectComposed)
}
is String -> {
JSonViewerLeaf(key, index, obj, JSONType.STRING).let {
is String -> {
JSonViewerLeaf(key, index, obj, JSONType.STRING).let {
it.depth = depth
parent.addChild(it)
}
}
is Number -> {
is Number -> {
JSonViewerLeaf(key, index, obj.toString(), JSONType.NUMBER).let {
it.depth = depth
parent.addChild(it)
}
}
is Boolean -> {
is Boolean -> {
JSonViewerLeaf(key, index, obj.toString(), JSONType.BOOLEAN).let {
it.depth = depth
parent.addChild(it)
}
}
else -> {
else -> {
if (obj == JSONObject.NULL) {
JSonViewerLeaf(key, index, "null", JSONType.NULL).let {
it.depth = depth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class JSonViewerStyleProvider(
@ColorInt val keyColor: Int,
@ColorInt val stringColor: Int,
@ColorInt val booleanColor: Int,
@ColorInt val numberColor: Int,
@ColorInt val baseColor: Int,
@ColorInt val secondaryColor: Int
@ColorInt val keyColor: Int,
@ColorInt val stringColor: Int,
@ColorInt val booleanColor: Int,
@ColorInt val numberColor: Int,
@ColorInt val baseColor: Int,
@ColorInt val secondaryColor: Int
) : Parcelable {

companion object {
fun default(context: Context) = JSonViewerStyleProvider(
keyColor = ContextCompat.getColor(context, R.color.key_color),
stringColor = ContextCompat.getColor(context, R.color.string_color),
booleanColor = ContextCompat.getColor(context, R.color.bool_color),
numberColor = ContextCompat.getColor(context, R.color.number_color),
baseColor = ContextCompat.getColor(context, R.color.base_color),
secondaryColor = ContextCompat.getColor(context, R.color.secondary_color)
keyColor = ContextCompat.getColor(context, R.color.key_color),
stringColor = ContextCompat.getColor(context, R.color.string_color),
booleanColor = ContextCompat.getColor(context, R.color.bool_color),
numberColor = ContextCompat.getColor(context, R.color.number_color),
baseColor = ContextCompat.getColor(context, R.color.base_color),
secondaryColor = ContextCompat.getColor(context, R.color.secondary_color)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import com.airbnb.mvrx.ViewModelContext
import kotlinx.coroutines.launch

internal data class JSonViewerState(
val root: Async<JSonViewerObject> = Uninitialized
val root: Async<JSonViewerObject> = Uninitialized
) : MavericksState

internal class JSonViewerViewModel(initialState: JSonViewerState) :
MavericksViewModel<JSonViewerState>(initialState) {
MavericksViewModel<JSonViewerState>(initialState) {

fun setJsonSource(json: String, initialOpenDepth: Int) {
setState {
Expand All @@ -43,14 +43,14 @@ internal class JSonViewerViewModel(initialState: JSonViewerState) :
ModelParser.fromJsonString(json, initialOpenDepth).let {
setState {
copy(
root = Success(it)
root = Success(it)
)
}
}
} catch (error: Throwable) {
setState {
copy(
root = Fail(error)
root = Fail(error)
)
}
}
Expand All @@ -64,7 +64,7 @@ internal class JSonViewerViewModel(initialState: JSonViewerState) :
val arg: JSonViewerFragmentArgs = viewModelContext.args()
return try {
JSonViewerState(
Success(ModelParser.fromJsonString(arg.jsonString, arg.defaultOpenDepth))
Success(ModelParser.fromJsonString(arg.jsonString, arg.defaultOpenDepth))
)
} catch (failure: Throwable) {
JSonViewerState(Fail(failure))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import android.util.TypedValue
internal object Utils {
fun dpToPx(dp: Int, context: Context): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp.toFloat(),
context.resources.displayMetrics
TypedValue.COMPLEX_UNIT_DIP,
dp.toFloat(),
context.resources.displayMetrics
).toInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ internal abstract class ValueItem : EpoxyModelWithHolder<ValueItem.Holder>() {
}

override fun onCreateContextMenu(
menu: ContextMenu?,
v: View?,
menuInfo: ContextMenu.ContextMenuInfo?
menu: ContextMenu?,
v: View?,
menuInfo: ContextMenu.ContextMenuInfo?
) {
if (copyValue != null) {
val menuItem = menu?.add(R.string.copy_value)
val clipService =
v?.context?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
v?.context?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
menuItem?.setOnMenuItemClickListener {
clipService?.setPrimaryClip(ClipData.newPlainText("", copyValue))
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class MultiPicker<T> {
@Suppress("UNCHECKED_CAST")
fun <T> get(type: MultiPicker<T>): T {
return when (type) {
IMAGE -> ImagePicker() as T
VIDEO -> VideoPicker() as T
MEDIA -> MediaPicker() as T
FILE -> FilePicker() as T
AUDIO -> AudioPicker() as T
CONTACT -> ContactPicker() as T
CAMERA -> CameraPicker() as T
CAMERA_VIDEO -> CameraVideoPicker() as T
else -> throw IllegalArgumentException("Unsupported type $type")
IMAGE -> ImagePicker() as T
VIDEO -> VideoPicker() as T
MEDIA -> MediaPicker() as T
FILE -> FilePicker() as T
AUDIO -> AudioPicker() as T
CONTACT -> ContactPicker() as T
CAMERA -> CameraPicker() as T
CAMERA_VIDEO -> CameraVideoPicker() as T
else -> throw IllegalArgumentException("Unsupported type $type")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ class FlowRoom(private val room: Room) {
room.getAllThreadSummaries()
}
}

fun liveThreadList(): Flow<List<ThreadRootEvent>> {
return room.getAllThreadsLive().asFlow()
.startWith(room.coroutineDispatchers.io) {
room.getAllThreads()
}
}

fun liveLocalUnreadThreadList(): Flow<List<ThreadRootEvent>> {
return room.getMarkedThreadNotificationsLive().asFlow()
.startWith(room.coroutineDispatchers.io) {
Expand Down
Loading

0 comments on commit c21ec98

Please sign in to comment.