Merge develop into feature/fga/dagger_setup

This commit is contained in:
ganfra 2022-12-19 16:14:14 +01:00
commit 4c88d8e3c2
214 changed files with 2662 additions and 1833 deletions

View file

@ -1,22 +1,21 @@
package io.element.android.x.core.compose
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.remember
import io.element.android.x.core.BuildConfig
import timber.log.Timber
// Note the inline function below which ensures that this function is essentially
// copied at the call site to ensure that its logging only recompositions from the
// original call site.
@Composable
inline fun LogCompositions(tag: String, msg: String) {
fun LogCompositions(tag: String, msg: String) {
if (BuildConfig.DEBUG) {
val ref = remember { Ref(0) }
SideEffect { ref.value++ }
Log.d(tag, "Compositions: $msg ${ref.value}")
Timber.d(tag, "Compositions: $msg ${ref.value}")
}
}
class Ref(var value: Int)
class Ref(var value: Int)

View file

@ -12,7 +12,7 @@ import androidx.lifecycle.LifecycleOwner
fun OnLifecycleEvent(onEvent: (owner: LifecycleOwner, event: Lifecycle.Event) -> Unit) {
val eventHandler = rememberUpdatedState(onEvent)
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
DisposableEffect(lifecycleOwner.value) {
val lifecycle = lifecycleOwner.value.lifecycle
val observer = LifecycleEventObserver { owner, event ->
@ -24,4 +24,4 @@ fun OnLifecycleEvent(onEvent: (owner: LifecycleOwner, event: Lifecycle.Event) ->
lifecycle.removeObserver(observer)
}
}
}
}

View file

@ -5,7 +5,6 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@Composable
public fun textFieldState(stateValue: String): MutableState<String> =
remember(stateValue) { mutableStateOf(stateValue) }
remember(stateValue) { mutableStateOf(stateValue) }

View file

@ -1,4 +1,4 @@
package io.element.android.x.core.data.flow
package io.element.android.x.core.coroutine
import android.os.SystemClock
import kotlinx.coroutines.CoroutineScope

View file

@ -1,4 +1,4 @@
package io.element.android.x.core.data
package io.element.android.x.core.coroutine
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
@ -7,4 +7,4 @@ import kotlinx.coroutines.coroutineScope
// https://jivimberg.io/blog/2018/05/04/parallel-map-in-kotlin/
suspend fun <A, B> Iterable<A>.parallelMap(f: suspend (A) -> B): List<B> = coroutineScope {
map { async { f(it) } }.awaitAll()
}
}

View file

@ -1,13 +1,13 @@
package io.element.android.x.core.data
import android.util.Log
import timber.log.Timber
inline fun <A> tryOrNull(message: String? = null, operation: () -> A): A? {
return try {
operation()
} catch (any: Throwable) {
if (message != null) {
Log.e("TAG", message, any)
Timber.e("TAG", message, any)
}
null
}

View file

@ -24,18 +24,18 @@ class DimensionConverter(val resources: Resources) {
@Px
fun dpToPx(dp: Int): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp.toFloat(),
resources.displayMetrics
TypedValue.COMPLEX_UNIT_DIP,
dp.toFloat(),
resources.displayMetrics
).toInt()
}
@Px
fun spToPx(sp: Int): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
sp.toFloat(),
resources.displayMetrics
TypedValue.COMPLEX_UNIT_SP,
sp.toFloat(),
resources.displayMetrics
).toInt()
}

View file

@ -35,9 +35,9 @@ fun View.showKeyboard(andRequestFocus: Boolean = false) {
fun View.setHorizontalPadding(padding: Int) {
setPadding(
padding,
paddingTop,
padding,
paddingBottom
padding,
paddingTop,
padding,
paddingBottom
)
}