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

Commit 6900a41a authored by Chris Göllner's avatar Chris Göllner
Browse files

Shortcut Helper - Connect UI layer to shortcuts

Test: unit tests in this CL
Test: manually
Flag: com.android.systemui.keyboard_shortcut_helper_rewrite
Bug: 341045652
Change-Id: I07345b7871e1a449fb1dfa306e0d1aa06c7b5afc
parent 71befbdb
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -227,7 +227,7 @@ private val ShortcutCategory.labelResId: Int
    get() =
    get() =
        when (type) {
        when (type) {
            ShortcutCategoryType.SYSTEM -> R.string.shortcut_helper_category_system
            ShortcutCategoryType.SYSTEM -> R.string.shortcut_helper_category_system
            ShortcutCategoryType.MULTI_TASKING -> R.string.shortcut_helper_category_system
            ShortcutCategoryType.MULTI_TASKING -> R.string.shortcut_helper_category_multitasking
            ShortcutCategoryType.IME -> R.string.shortcut_helper_category_input
            ShortcutCategoryType.IME -> R.string.shortcut_helper_category_input
        }
        }


+1 −5
Original line number Original line Diff line number Diff line
@@ -34,7 +34,6 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
import com.android.compose.theme.PlatformTheme
import com.android.compose.theme.PlatformTheme
import com.android.systemui.keyboard.shortcut.ui.composable.ShortcutHelper
import com.android.systemui.keyboard.shortcut.ui.composable.ShortcutHelper
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel
import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel
import com.android.systemui.res.R
import com.android.systemui.res.R
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetBehavior
@@ -81,10 +80,7 @@ constructor(
        requireViewById<ComposeView>(R.id.shortcut_helper_compose_container).apply {
        requireViewById<ComposeView>(R.id.shortcut_helper_compose_container).apply {
            setContent {
            setContent {
                PlatformTheme {
                PlatformTheme {
                    val shortcutsUiState by
                    val shortcutsUiState by viewModel.shortcutsUiState.collectAsStateWithLifecycle()
                        viewModel.shortcutsUiState.collectAsStateWithLifecycle(
                            initialValue = ShortcutsUiState.Inactive
                        )
                    ShortcutHelper(
                    ShortcutHelper(
                        shortcutsUiState = shortcutsUiState,
                        shortcutsUiState = shortcutsUiState,
                        onKeyboardSettingsClicked = ::onKeyboardSettingsClicked,
                        onKeyboardSettingsClicked = ::onKeyboardSettingsClicked,
+19 −9
Original line number Original line Diff line number Diff line
@@ -23,13 +23,17 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn


class ShortcutHelperViewModel
class ShortcutHelperViewModel
@Inject
@Inject
constructor(
constructor(
    @Background private val backgroundScope: CoroutineScope,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val stateInteractor: ShortcutHelperStateInteractor,
    private val stateInteractor: ShortcutHelperStateInteractor,
    categoriesInteractor: ShortcutHelperCategoriesInteractor,
    categoriesInteractor: ShortcutHelperCategoriesInteractor,
@@ -42,7 +46,8 @@ constructor(
            .flowOn(backgroundDispatcher)
            .flowOn(backgroundDispatcher)


    val shortcutsUiState =
    val shortcutsUiState =
        categoriesInteractor.shortcutCategories.map {
        categoriesInteractor.shortcutCategories
            .map {
                if (it.isEmpty()) {
                if (it.isEmpty()) {
                    ShortcutsUiState.Inactive
                    ShortcutsUiState.Inactive
                } else {
                } else {
@@ -52,6 +57,11 @@ constructor(
                    )
                    )
                }
                }
            }
            }
            .stateIn(
                scope = backgroundScope,
                started = SharingStarted.Lazily,
                initialValue = ShortcutsUiState.Inactive
            )


    fun onViewClosed() {
    fun onViewClosed() {
        stateInteractor.onViewClosed()
        stateInteractor.onViewClosed()
+1 −0
Original line number Original line Diff line number Diff line
@@ -100,6 +100,7 @@ val Kosmos.shortcutHelperCategoriesInteractor by
val Kosmos.shortcutHelperViewModel by
val Kosmos.shortcutHelperViewModel by
    Kosmos.Fixture {
    Kosmos.Fixture {
        ShortcutHelperViewModel(
        ShortcutHelperViewModel(
            applicationCoroutineScope,
            testDispatcher,
            testDispatcher,
            shortcutHelperStateInteractor,
            shortcutHelperStateInteractor,
            shortcutHelperCategoriesInteractor
            shortcutHelperCategoriesInteractor