Clean up formatting/detekt

This commit is contained in:
ganfra
2026-08-06 16:16:13 +02:00
parent a7d2b86fe0
commit 0e563332ce
4 changed files with 13 additions and 8 deletions
@@ -12,6 +12,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import io.element.android.libraries.architecture.AsyncAction import io.element.android.libraries.architecture.AsyncAction
@@ -36,24 +37,24 @@ private val DefaultFailureDuration = 500.milliseconds
* never debounced) and auto-dismisses after [failureDuration]. * never debounced) and auto-dismisses after [failureDuration].
* *
* @param asyncAction the action whose progress drives the indicator. * @param asyncAction the action whose progress drives the indicator.
* @param loading the composable to display while loading.
* @param failure the composable to display on failure.
* @param modifier the modifier to apply to the underlying [AsyncIndicatorHost]. * @param modifier the modifier to apply to the underlying [AsyncIndicatorHost].
* @param state the [AsyncIndicatorState] backing the host. * @param state the [AsyncIndicatorState] backing the host.
* @param showDelay how long the loading state must persist before the indicator is shown. * @param showDelay how long the loading state must persist before the indicator is shown.
* @param minDisplayDuration the minimum duration the loading indicator stays visible once shown. * @param minDisplayDuration the minimum duration the loading indicator stays visible once shown.
* @param failureDuration how long the failure indicator stays visible before auto-dismissing. * @param failureDuration how long the failure indicator stays visible before auto-dismissing.
* @param loading the composable to display while loading.
* @param failure the composable to display on failure.
*/ */
@Composable @Composable
fun AsyncActionIndicator( fun AsyncActionIndicator(
asyncAction: AsyncAction<*>, asyncAction: AsyncAction<*>,
loading: @Composable () -> Unit,
failure: @Composable (Throwable) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
state: AsyncIndicatorState = rememberAsyncIndicatorState(), state: AsyncIndicatorState = rememberAsyncIndicatorState(),
showDelay: Duration = DefaultShowDelay, showDelay: Duration = DefaultShowDelay,
minDisplayDuration: Duration = DefaultMinDisplayDuration, minDisplayDuration: Duration = DefaultMinDisplayDuration,
failureDuration: Duration = DefaultFailureDuration, failureDuration: Duration = DefaultFailureDuration,
loading: @Composable () -> Unit,
failure: @Composable (Throwable) -> Unit,
) { ) {
AsyncIndicatorHost(modifier = modifier, state = state) AsyncIndicatorHost(modifier = modifier, state = state)
AsyncActionIndicatorEffect( AsyncActionIndicatorEffect(
@@ -78,6 +79,9 @@ internal fun AsyncActionIndicatorEffect(
failure: @Composable (Throwable) -> Unit, failure: @Composable (Throwable) -> Unit,
timeSource: TimeSource = TimeSource.Monotonic, timeSource: TimeSource = TimeSource.Monotonic,
) { ) {
// Referenced inside the restarting LaunchedEffect below, so keep them up to date.
val currentLoading by rememberUpdatedState(loading)
val currentFailure by rememberUpdatedState(failure)
// Mark set when the loader actually becomes visible, null while it is hidden. // Mark set when the loader actually becomes visible, null while it is hidden.
var loaderShownAt by remember { mutableStateOf<TimeMark?>(null) } var loaderShownAt by remember { mutableStateOf<TimeMark?>(null) }
LaunchedEffect(asyncAction) { LaunchedEffect(asyncAction) {
@@ -86,12 +90,13 @@ internal fun AsyncActionIndicatorEffect(
// If the operation completes before this delay elapses, the effect is cancelled // If the operation completes before this delay elapses, the effect is cancelled
// and the loader is never shown. // and the loader is never shown.
delay(showDelay) delay(showDelay)
state.enqueue(composable = loading) state.enqueue(composable = currentLoading)
loaderShownAt = timeSource.markNow() loaderShownAt = timeSource.markNow()
} }
is AsyncAction.Failure -> { is AsyncAction.Failure -> {
// Always surface failures immediately, even if the loader was never shown. // Always surface failures immediately, even if the loader was never shown.
state.enqueue(durationMs = failureDuration.inWholeMilliseconds, composable = { failure(asyncAction.error) }) val error = asyncAction.error
state.enqueue(durationMs = failureDuration.inWholeMilliseconds, composable = { currentFailure(error) })
loaderShownAt = null loaderShownAt = null
} }
is AsyncAction.Success -> { is AsyncAction.Success -> {
@@ -13,7 +13,6 @@ import kotlinx.parcelize.Parcelize
@Immutable @Immutable
sealed interface DisplayedStatus : Parcelable { sealed interface DisplayedStatus : Parcelable {
/** Useful for adding extension methods. */ /** Useful for adding extension methods. */
companion object companion object
@@ -42,7 +42,6 @@ import io.element.android.libraries.matrix.api.widget.MatrixWidgetDriver
import io.element.android.libraries.matrix.api.widget.MatrixWidgetSettings import io.element.android.libraries.matrix.api.widget.MatrixWidgetSettings
import io.element.android.libraries.matrix.impl.core.RustSendHandle import io.element.android.libraries.matrix.impl.core.RustSendHandle
import io.element.android.libraries.matrix.impl.mapper.map import io.element.android.libraries.matrix.impl.mapper.map
import io.element.android.libraries.matrix.impl.user.map
import io.element.android.libraries.matrix.impl.room.history.map import io.element.android.libraries.matrix.impl.room.history.map
import io.element.android.libraries.matrix.impl.room.join.map import io.element.android.libraries.matrix.impl.room.join.map
import io.element.android.libraries.matrix.impl.room.knock.RustKnockRequest import io.element.android.libraries.matrix.impl.room.knock.RustKnockRequest
@@ -54,6 +53,7 @@ import io.element.android.libraries.matrix.impl.room.threads.RustThreadsListServ
import io.element.android.libraries.matrix.impl.roomdirectory.map import io.element.android.libraries.matrix.impl.roomdirectory.map
import io.element.android.libraries.matrix.impl.timeline.RustTimeline import io.element.android.libraries.matrix.impl.timeline.RustTimeline
import io.element.android.libraries.matrix.impl.timeline.item.event.TimelineEventContentMapper import io.element.android.libraries.matrix.impl.timeline.item.event.TimelineEventContentMapper
import io.element.android.libraries.matrix.impl.user.map
import io.element.android.libraries.matrix.impl.util.MessageEventContent import io.element.android.libraries.matrix.impl.util.MessageEventContent
import io.element.android.libraries.matrix.impl.util.mxCallbackFlow import io.element.android.libraries.matrix.impl.util.mxCallbackFlow
import io.element.android.libraries.matrix.impl.widget.RustWidgetDriver import io.element.android.libraries.matrix.impl.widget.RustWidgetDriver
@@ -98,6 +98,7 @@ class KonsistPreviewTest {
"HomeTopBarSpaceFiltersSelectedPreview", "HomeTopBarSpaceFiltersSelectedPreview",
"HomeTopBarSpacesPreview", "HomeTopBarSpacesPreview",
"HomeTopBarWithIndicatorPreview", "HomeTopBarWithIndicatorPreview",
"HomeTopBarWithStatusPreview",
"IconsOtherPreview", "IconsOtherPreview",
"MarkdownTextComposerEditPreview", "MarkdownTextComposerEditPreview",
"MatrixBadgeAtomInfoPreview", "MatrixBadgeAtomInfoPreview",