Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77e03a2f authored by Tianfan Zhang's avatar Tianfan Zhang
Browse files

Debounce actions flow when actions gets empty, in order to avoid two

duplicated NavBars.

Bug: 433588173
Test: manual test
Flag: EXEMPT bugfix
Change-Id: I58aebd58351cf576514446ee3630ea7cd6d85dad
parent 7332fdce
Loading
Loading
Loading
Loading
+44 −37
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.delay
@@ -54,6 +55,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
@@ -180,12 +182,16 @@ constructor(
                    }
                },
        )

    @OptIn(FlowPreview::class)
    val actions: List<ActionViewModel> by
        hydrator.hydratedStateOf(
            traceName = "actions",
            initialValue = listOf(),
            source =
                ambientCueInteractor.actions.map { actions ->
                ambientCueInteractor.actions
                    .debounce { actions -> if (actions.isEmpty()) ACTIONS_DEBOUNCE_MS else 0L }
                    .map { actions ->
                        actions.map { action ->
                            ActionViewModel(
                                icon =
@@ -204,10 +210,10 @@ constructor(
                                onLongClick = {
                                    action.onPerformLongClick()
                                    // Long press onboarding only triggers 7 days after the initial
                                // onboarding. That said, we'd like to suppress it in case the user
                                // discovers the gesture on their own. For this reason, we don't
                                // check if the tooltip is visible before updating the shared
                                // preference.
                                    // onboarding. That said, we'd like to suppress it in case the
                                    // user discovers the gesture on their own. For this reason, we
                                    // don't check if the tooltip is visible before updating the
                                    // shared preference.
                                    sharedPreferences.value?.edit {
                                        putBoolean(KEY_SHOW_LONG_PRESS_ONBOARDING, false)
                                    }
@@ -325,5 +331,6 @@ constructor(
        private const val SHARED_PREFERENCES_FILE_NAME = "ambientcue_pref"
        private const val KEY_FIRST_TIME_ONBOARDING_SHOWN_AT = "show_first_time_onboarding"
        private const val KEY_SHOW_LONG_PRESS_ONBOARDING = "show_long_press_onboarding"
        private const val ACTIONS_DEBOUNCE_MS = 300L
    }
}