diff options
| author | 2024-07-12 20:50:24 +0000 | |
|---|---|---|
| committer | 2024-07-12 20:50:24 +0000 | |
| commit | 4713c3e06dfebc0fedf3ce5cb886716a20493181 (patch) | |
| tree | 0ef142d44eef38e955291c56e22b0ca210a902ec | |
| parent | 6346546884a8b713be1d8a1de7016d55a3fce90b (diff) | |
| parent | f253c116bc339a15f2c6d6e0e00d5c6940d6a4cd (diff) | |
Merge "ShortcutHelper with Open App shortcuts tab by default when triggered from app" into main
5 files changed, 59 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt index 9e9368d3ffd3..b4828624d29c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt index ad258f435d63..25574ea551b4 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt @@ -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() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt index 4fba7e355df8..c9c39b3ebf66 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt @@ -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( diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt index 07feaa1a5047..69fc463a576a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt @@ -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)) + } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperTestHelper.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperTestHelper.kt index 3e09b2379ff1..6ca5cd81b665 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperTestHelper.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperTestHelper.kt @@ -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, |