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

Commit 4713c3e0 authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge "ShortcutHelper with Open App shortcuts tab by default when triggered from app" into main

parents 63465468 f253c116
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ fun ShortcutHelper(
                ShortcutHelperSinglePane(
                    modifier,
                    shortcutsUiState.shortcutCategories,
                    shortcutsUiState.defaultSelectedCategory,
                    onKeyboardSettingsClicked
                )
            } else {
@@ -146,6 +147,7 @@ private fun shouldUseSinglePane() =
private fun ShortcutHelperSinglePane(
    modifier: Modifier = Modifier,
    categories: List<ShortcutCategory>,
    defaultSelectedCategory: ShortcutCategoryType,
    onKeyboardSettingsClicked: () -> Unit,
) {
    Column(
@@ -159,7 +161,7 @@ private fun ShortcutHelperSinglePane(
        Spacer(modifier = Modifier.height(6.dp))
        ShortcutsSearchBar()
        Spacer(modifier = Modifier.height(16.dp))
        CategoriesPanelSinglePane(categories)
        CategoriesPanelSinglePane(categories, defaultSelectedCategory)
        Spacer(modifier = Modifier.weight(1f))
        KeyboardSettings(onClick = onKeyboardSettingsClicked)
    }
@@ -168,8 +170,10 @@ private fun ShortcutHelperSinglePane(
@Composable
private fun CategoriesPanelSinglePane(
    categories: List<ShortcutCategory>,
    defaultSelectedCategory: ShortcutCategoryType,
) {
    var expandedCategory by remember { mutableStateOf<ShortcutCategory?>(null) }
    val selectedCategory = categories.firstOrNull { it.type == defaultSelectedCategory }
    var expandedCategory by remember { mutableStateOf(selectedCategory) }
    Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
        categories.fastForEachIndexed { index, category ->
            val isExpanded = expandedCategory == category
+11 −1
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperCategoriesInteractor
import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperStateInteractor
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.CurrentApp
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
@@ -52,7 +55,7 @@ constructor(
                } else {
                    ShortcutsUiState.Active(
                        shortcutCategories = it,
                        defaultSelectedCategory = it.first().type,
                        defaultSelectedCategory = getDefaultSelectedCategory(it),
                    )
                }
            }
@@ -62,6 +65,13 @@ constructor(
                initialValue = ShortcutsUiState.Inactive
            )

    private fun getDefaultSelectedCategory(
        categories: List<ShortcutCategory>
    ): ShortcutCategoryType {
        val currentAppShortcuts = categories.firstOrNull { it.type is CurrentApp }
        return currentAppShortcuts?.type ?: categories.first().type
    }

    fun onViewClosed() {
        stateInteractor.onViewClosed()
    }
+12 −0
Original line number Diff line number Diff line
@@ -189,6 +189,15 @@ object TestShortcuts {
            listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3)
        )

    private val standardPackageName1 = "standard.app.group1"

    private val standardAppGroup1 =
        KeyboardShortcutGroup(
                "Standard app group 1",
                listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3)
            )
            .apply { packageName = standardPackageName1 }

    private val standardSubCategory1 =
        ShortcutSubCategory(
            standardGroup1.label!!.toString(),
@@ -230,6 +239,9 @@ object TestShortcuts {
                )
        )

    val currentAppGroups = listOf(standardAppGroup1)
    val currentAppPackageName = standardPackageName1

    val systemGroups = listOf(standardGroup3, standardGroup2, standardGroup1)
    val systemCategory =
        ShortcutCategory(
+16 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.CurrentApp
import com.android.systemui.keyboard.shortcut.shortcutHelperAppCategoriesShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperCurrentAppShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperInputShortcutsSource
@@ -52,6 +53,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {

    private val fakeSystemSource = FakeKeyboardShortcutGroupsSource()
    private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource()
    private val fakeCurrentAppsSource = FakeKeyboardShortcutGroupsSource()

    private val kosmos =
        Kosmos().also {
@@ -61,7 +63,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            it.shortcutHelperMultiTaskingShortcutsSource = fakeMultiTaskingSource
            it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource()
            it.shortcutHelperInputShortcutsSource = FakeKeyboardShortcutGroupsSource()
            it.shortcutHelperCurrentAppShortcutsSource = FakeKeyboardShortcutGroupsSource()
            it.shortcutHelperCurrentAppShortcutsSource = fakeCurrentAppsSource
        }

    private val testScope = kosmos.testScope
@@ -216,4 +218,17 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            assertThat(activeUiState.defaultSelectedCategory)
                .isEqualTo(activeUiState.shortcutCategories.first().type)
        }

    @Test
    fun shortcutsUiState_featureActive_emitsActiveWithCurrentAppsCategorySelectedWhenPresent() =
        testScope.runTest {
            fakeCurrentAppsSource.setGroups(TestShortcuts.currentAppGroups)
            val uiState by collectLastValue(viewModel.shortcutsUiState)

            testHelper.showFromActivity()

            val activeUiState = uiState as ShortcutsUiState.Active
            assertThat(activeUiState.defaultSelectedCategory)
                .isEqualTo(CurrentApp(TestShortcuts.currentAppPackageName))
        }
}
+14 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ class ShortcutHelperTestHelper(
    }

    private var imeShortcuts: List<KeyboardShortcutGroup> = emptyList()
    private var currentAppsShortcuts: List<KeyboardShortcutGroup> = emptyList()

    init {
        whenever(windowManager.requestImeKeyboardShortcuts(any(), any())).thenAnswer {
@@ -48,6 +49,11 @@ class ShortcutHelperTestHelper(
            keyboardShortcutReceiver.onKeyboardShortcutsReceived(imeShortcuts)
            return@thenAnswer Unit
        }
        whenever(windowManager.requestAppKeyboardShortcuts(any(), any())).thenAnswer {
            val keyboardShortcutReceiver = it.getArgument<KeyboardShortcutsReceiver>(0)
            keyboardShortcutReceiver.onKeyboardShortcutsReceived(currentAppsShortcuts)
            return@thenAnswer Unit
        }
        repo.start()
    }

@@ -59,6 +65,14 @@ class ShortcutHelperTestHelper(
        this.imeShortcuts = imeShortcuts
    }

    /**
     * Use this method to set what current app shortcuts should be returned from windowManager in
     * tests. By default [WindowManager.requestAppKeyboardShortcuts] will return emptyList.
     */
    fun setCurrentAppsShortcuts(currentAppShortcuts: List<KeyboardShortcutGroup>) {
        this.currentAppsShortcuts = currentAppShortcuts
    }

    fun hideThroughCloseSystemDialogs() {
        fakeBroadcastDispatcher.sendIntentToMatchingReceiversOnly(
            context,