summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Göllner <chrisgollner@google.com> 2024-06-26 09:44:26 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-06-26 09:44:26 +0000
commita42860d0e7ea4ecef43e6b50b32ec0063f99d3d1 (patch)
treef8ee23a45401d1028e97cfd4207a54b3c68ac053
parent71fa2dba2c24f3fe2ad54e2c795c4c160c2a8344 (diff)
parent0b3dfd55f06c8e6dd316d893fec4de9303c9af87 (diff)
Merge "Shortcut Helper - Connect interactor with system shortcuts" into main
-rw-r--r--packages/SystemUI/res/values/strings.xml16
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt38
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepository.kt (renamed from packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepository.kt)2
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt21
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt21
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt47
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperStateInteractor.kt (renamed from packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperInteractor.kt)6
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt10
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt40
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCommand.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt19
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt10
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepositoryTest.kt (renamed from packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepositoryTest.kt)6
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt81
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt48
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperTestHelper.kt2
17 files changed, 338 insertions, 37 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index abafb01cc646..f533cb84da03 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -3543,10 +3543,26 @@
shows the user which keyboard shortcuts they can use. The "System" shortcuts are for
example "Take a screenshot" or "Go back". [CHAR LIMIT=NONE] -->
<string name="shortcut_helper_category_system">System</string>
+ <!-- Title of the keyboard shortcut helper category "System controls". The helper is a component
+ that shows the user which keyboard shortcuts they can use. The "System controls" shortcuts
+ are for example "Go to home screen" or "App apps search". [CHAR LIMIT=NONE] -->
+ <string name="shortcut_helper_category_system_controls">System controls</string>
+ <!-- Title of the keyboard shortcut helper category "System apps". The helper is a component
+ that shows the user which keyboard shortcuts they can use. The "System apps" shortcuts
+ are for example "Settings" or "Take a note". [CHAR LIMIT=NONE] -->
+ <string name="shortcut_helper_category_system_apps">System apps</string>
<!-- Title of the keyboard shortcut helper category "Multitasking". The helper is a component
that shows the user which keyboard shortcuts they can use. The "Multitasking" shortcuts are
for example "Enter split screen". [CHAR LIMIT=NONE] -->
<string name="shortcut_helper_category_multitasking">Multitasking</string>
+ <!-- Title of the keyboard shortcut helper category "Recent apps". The helper is a component
+ that shows the user which keyboard shortcuts they can use. The "Recent apps" shortcuts are
+ for example "Cycle through recent apps". [CHAR LIMIT=NONE] -->
+ <string name="shortcutHelper_category_recent_apps">Recent apps</string>
+ <!-- Title of the keyboard shortcut helper category "Split screen". The helper is a component
+ that shows the user which keyboard shortcuts they can use. The "Split screen" shortcuts are
+ for example "Move current app to left split". [CHAR LIMIT=NONE] -->
+ <string name="shortcutHelper_category_split_screen">Split screen</string>
<!-- Title of the keyboard shortcut helper category "Input". The helper is a component
that shows the user which keyboard shortcuts they can use. The "Input" shortcuts are
the ones provided by the keyboard. Examples are "Access emoji" or "Switch to next language"
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
index 5635f8056b9c..8a40c0326523 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt
@@ -19,7 +19,7 @@ package com.android.systemui.keyboard.shortcut
import android.app.Activity
import com.android.systemui.CoreStartable
import com.android.systemui.Flags.keyboardShortcutHelperRewrite
-import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperRepository
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.ui.ShortcutHelperActivityStarter
import com.android.systemui.keyboard.shortcut.ui.view.ShortcutHelperActivity
import dagger.Binds
@@ -52,8 +52,8 @@ interface ShortcutHelperModule {
@Provides
@IntoMap
- @ClassKey(ShortcutHelperRepository::class)
- fun repo(implLazy: Lazy<ShortcutHelperRepository>): CoreStartable {
+ @ClassKey(ShortcutHelperStateRepository::class)
+ fun repo(implLazy: Lazy<ShortcutHelperStateRepository>): CoreStartable {
return if (keyboardShortcutHelperRewrite()) {
implLazy.get()
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt
new file mode 100644
index 000000000000..04bde26fdd88
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperCategoriesRepository.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.data.repository
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsSource
+import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
+import javax.inject.Inject
+
+@SysUISingleton
+class ShortcutHelperCategoriesRepository
+@Inject
+constructor(
+ private val systemShortcutsSource: SystemShortcutsSource,
+ private val multitaskingShortcutsSource: MultitaskingShortcutsSource,
+) {
+
+ fun systemShortcutsCategory(): ShortcutCategory =
+ systemShortcutsSource.systemShortcutsCategory()
+
+ fun multitaskingShortcutsCategory(): ShortcutCategory =
+ multitaskingShortcutsSource.multitaskingShortcutCategory()
+}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepository.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepository.kt
index b9a5a228d22b..82df95d482c2 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepository.kt
@@ -40,7 +40,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@SysUISingleton
-class ShortcutHelperRepository
+class ShortcutHelperStateRepository
@Inject
constructor(
private val commandQueue: CommandQueue,
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt
index 34b10c727cd9..7b64f872b064 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/MultitaskingShortcutsSource.kt
@@ -25,13 +25,28 @@ import android.view.KeyEvent.META_ALT_ON
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_META_ON
import android.view.KeyEvent.META_SHIFT_ON
+import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MULTI_TASKING
import com.android.systemui.keyboard.shortcut.shared.model.shortcut
+import com.android.systemui.keyboard.shortcut.shared.model.shortcutCategory
import com.android.systemui.res.R
import javax.inject.Inject
-class MultitaskingShortcutsSource @Inject constructor(private val resources: Resources) {
+class MultitaskingShortcutsSource @Inject constructor(@Main private val resources: Resources) {
- fun splitScreenShortcuts() =
+ fun multitaskingShortcutCategory() =
+ shortcutCategory(MULTI_TASKING) {
+ subCategory(
+ resources.getString(R.string.shortcutHelper_category_recent_apps),
+ recentsShortcuts()
+ )
+ subCategory(
+ resources.getString(R.string.shortcutHelper_category_split_screen),
+ splitScreenShortcuts()
+ )
+ }
+
+ private fun splitScreenShortcuts() =
listOf(
// Enter Split screen with current app to RHS:
// - Meta + Ctrl + Right arrow
@@ -60,7 +75,7 @@ class MultitaskingShortcutsSource @Inject constructor(private val resources: Res
},
)
- fun recentsShortcuts() =
+ private fun recentsShortcuts() =
listOf(
// Cycle through recent apps (forward):
// - Alt + Tab
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt
index a4304e5d1d33..51c67dfdcb4d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/source/SystemShortcutsSource.kt
@@ -31,13 +31,28 @@ import android.view.KeyEvent.KEYCODE_SLASH
import android.view.KeyEvent.KEYCODE_TAB
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_META_ON
+import com.android.systemui.dagger.qualifiers.Main
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.SYSTEM
import com.android.systemui.keyboard.shortcut.shared.model.shortcut
+import com.android.systemui.keyboard.shortcut.shared.model.shortcutCategory
import com.android.systemui.res.R
import javax.inject.Inject
-class SystemShortcutsSource @Inject constructor(private val resources: Resources) {
+class SystemShortcutsSource @Inject constructor(@Main private val resources: Resources) {
- fun generalShortcuts() =
+ fun systemShortcutsCategory() =
+ shortcutCategory(SYSTEM) {
+ subCategory(
+ resources.getString(R.string.shortcut_helper_category_system_controls),
+ systemControlsShortcuts()
+ )
+ subCategory(
+ resources.getString(R.string.shortcut_helper_category_system_apps),
+ systemAppsShortcuts()
+ )
+ }
+
+ private fun systemControlsShortcuts() =
listOf(
// Access list of all apps and search (i.e. Search/Launcher):
// - Meta
@@ -87,7 +102,7 @@ class SystemShortcutsSource @Inject constructor(private val resources: Resources
},
)
- fun systemAppsShortcuts() =
+ private fun systemAppsShortcuts() =
listOf(
// Pull up Notes app for quick memo:
// - Meta + Ctrl + N
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt
new file mode 100644
index 000000000000..883407c5f6a4
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.domain.interactor
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperCategoriesRepository
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory
+import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
+import javax.inject.Inject
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.map
+
+@SysUISingleton
+class ShortcutHelperCategoriesInteractor
+@Inject
+constructor(
+ stateRepository: ShortcutHelperStateRepository,
+ categoriesRepository: ShortcutHelperCategoriesRepository,
+) {
+
+ val shortcutCategories: Flow<List<ShortcutCategory>> =
+ stateRepository.state.map { state ->
+ when (state) {
+ is ShortcutHelperState.Active ->
+ listOf(
+ categoriesRepository.systemShortcutsCategory(),
+ categoriesRepository.multitaskingShortcutsCategory()
+ )
+ is ShortcutHelperState.Inactive -> emptyList()
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperStateInteractor.kt
index 44f1c1e8305f..3d707f70538e 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperStateInteractor.kt
@@ -18,7 +18,7 @@ package com.android.systemui.keyboard.shortcut.domain.interactor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperRepository
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import com.android.systemui.model.SysUiState
import com.android.systemui.settings.DisplayTracker
@@ -29,13 +29,13 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
@SysUISingleton
-class ShortcutHelperInteractor
+class ShortcutHelperStateInteractor
@Inject
constructor(
private val displayTracker: DisplayTracker,
@Background private val backgroundScope: CoroutineScope,
private val sysUiState: SysUiState,
- private val repository: ShortcutHelperRepository
+ private val repository: ShortcutHelperStateRepository
) {
val state: Flow<ShortcutHelperState> = repository.state
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt
index ea90b18c06b5..e5b870a983c6 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt
@@ -16,19 +16,17 @@
package com.android.systemui.keyboard.shortcut.shared.model
-import android.graphics.drawable.Icon
+data class Shortcut(val label: String, val commands: List<ShortcutCommand>)
-data class Shortcut(val label: String, val icon: Icon? = null, val commands: List<ShortcutCommand>)
-
-class ShortcutBuilder(private val label: String, private val icon: Icon? = null) {
+class ShortcutBuilder(private val label: String) {
val commands = mutableListOf<ShortcutCommand>()
fun command(vararg keyCodes: Int) {
commands += ShortcutCommand(keyCodes.toList())
}
- fun build() = Shortcut(label, icon, commands)
+ fun build() = Shortcut(label, commands)
}
-fun shortcut(label: String, icon: Icon? = null, block: ShortcutBuilder.() -> Unit): Shortcut =
+fun shortcut(label: String, block: ShortcutBuilder.() -> Unit): Shortcut =
ShortcutBuilder(label).apply(block).build()
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt
new file mode 100644
index 000000000000..c5e8d2c12fda
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCategory.kt
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.shared.model
+
+enum class ShortcutCategoryType {
+ SYSTEM,
+ MULTI_TASKING,
+}
+
+data class ShortcutCategory(
+ val type: ShortcutCategoryType,
+ val subCategories: List<ShortcutSubCategory>
+)
+
+class ShortcutCategoryBuilder(val type: ShortcutCategoryType) {
+ private val subCategories = mutableListOf<ShortcutSubCategory>()
+
+ fun subCategory(label: String, shortcuts: List<Shortcut>) {
+ subCategories += ShortcutSubCategory(label, shortcuts)
+ }
+
+ fun build() = ShortcutCategory(type, subCategories)
+}
+
+fun shortcutCategory(type: ShortcutCategoryType, block: ShortcutCategoryBuilder.() -> Unit) =
+ ShortcutCategoryBuilder(type).apply(block).build()
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCommand.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCommand.kt
index 747efbaf4838..a98a8ffb7004 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCommand.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutCommand.kt
@@ -16,4 +16,4 @@
package com.android.systemui.keyboard.shortcut.shared.model
-class ShortcutCommand(val keyCodes: List<Int>)
+data class ShortcutCommand(val keyCodes: List<Int>)
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt
new file mode 100644
index 000000000000..4545b4c5dd28
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.shared.model
+
+data class ShortcutSubCategory(val label: String, val shortcuts: List<Shortcut>)
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 c623f5c23fd9..510e55262224 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
@@ -17,7 +17,7 @@
package com.android.systemui.keyboard.shortcut.ui.viewmodel
import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperInteractor
+import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperStateInteractor
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
@@ -29,20 +29,20 @@ class ShortcutHelperViewModel
@Inject
constructor(
@Background private val backgroundDispatcher: CoroutineDispatcher,
- private val interactor: ShortcutHelperInteractor
+ private val stateInteractor: ShortcutHelperStateInteractor,
) {
val shouldShow =
- interactor.state
+ stateInteractor.state
.map { it is ShortcutHelperState.Active }
.distinctUntilChanged()
.flowOn(backgroundDispatcher)
fun onViewClosed() {
- interactor.onViewClosed()
+ stateInteractor.onViewClosed()
}
fun onViewOpened() {
- interactor.onViewOpened()
+ stateInteractor.onViewOpened()
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepositoryTest.kt
index c7e83b202cc4..3caa8f6cd138 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepositoryTest.kt
@@ -23,7 +23,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
-import com.android.systemui.keyboard.shortcut.shortcutHelperRepository
+import com.android.systemui.keyboard.shortcut.shortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
@@ -34,11 +34,11 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
-class ShortcutHelperRepositoryTest : SysuiTestCase() {
+class ShortcutHelperStateRepositoryTest : SysuiTestCase() {
private val kosmos = testKosmos()
- private val repo = kosmos.shortcutHelperRepository
+ private val repo = kosmos.shortcutHelperStateRepository
private val helper = kosmos.shortcutHelperTestHelper
private val testScope = kosmos.testScope
private val fakeInputManager = kosmos.fakeInputManager
diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt
new file mode 100644
index 000000000000..9c9e48e9200e
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.keyboard.shortcut.domain.interactor
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.keyboard.shortcut.shortcutHelperCategoriesInteractor
+import com.android.systemui.keyboard.shortcut.shortcutHelperMultiTaskingShortcutsSource
+import com.android.systemui.keyboard.shortcut.shortcutHelperSystemShortcutsSource
+import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
+import com.android.systemui.kosmos.testDispatcher
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.testKosmos
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.UnconfinedTestDispatcher
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() {
+
+ @OptIn(ExperimentalCoroutinesApi::class)
+ private val kosmos = testKosmos().also { it.testDispatcher = UnconfinedTestDispatcher() }
+ private val testScope = kosmos.testScope
+ private val interactor = kosmos.shortcutHelperCategoriesInteractor
+ private val helper = kosmos.shortcutHelperTestHelper
+ private val systemShortcutsSource = kosmos.shortcutHelperSystemShortcutsSource
+ private val multitaskingShortcutsSource = kosmos.shortcutHelperMultiTaskingShortcutsSource
+
+ @Test
+ fun categories_emptyByDefault() =
+ testScope.runTest {
+ val categories by collectLastValue(interactor.shortcutCategories)
+
+ assertThat(categories).isEmpty()
+ }
+
+ @Test
+ fun categories_stateActive_emitsAllCategoriesInOrder() =
+ testScope.runTest {
+ val categories by collectLastValue(interactor.shortcutCategories)
+
+ helper.showFromActivity()
+
+ assertThat(categories)
+ .containsExactly(
+ systemShortcutsSource.systemShortcutsCategory(),
+ multitaskingShortcutsSource.multitaskingShortcutCategory()
+ )
+ .inOrder()
+ }
+
+ @Test
+ fun categories_stateInactiveAfterActive_emitsEmpty() =
+ testScope.runTest {
+ val categories by collectLastValue(interactor.shortcutCategories)
+ helper.showFromActivity()
+ helper.hideFromActivity()
+
+ assertThat(categories).isEmpty()
+ }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
index 0b1293649755..f51036f3b54b 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt
@@ -17,11 +17,16 @@
package com.android.systemui.keyboard.shortcut
import android.content.applicationContext
+import android.content.res.mainResources
import android.hardware.input.fakeInputManager
import com.android.systemui.broadcast.broadcastDispatcher
-import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperRepository
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperCategoriesRepository
+import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperTestHelper
-import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperInteractor
+import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsSource
+import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource
+import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperCategoriesInteractor
+import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperStateInteractor
import com.android.systemui.keyboard.shortcut.ui.ShortcutHelperActivityStarter
import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel
import com.android.systemui.keyguard.data.repository.fakeCommandQueue
@@ -32,9 +37,15 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.model.sysUiState
import com.android.systemui.settings.displayTracker
-val Kosmos.shortcutHelperRepository by
+val Kosmos.shortcutHelperSystemShortcutsSource by
+ Kosmos.Fixture { SystemShortcutsSource(mainResources) }
+
+val Kosmos.shortcutHelperMultiTaskingShortcutsSource by
+ Kosmos.Fixture { MultitaskingShortcutsSource(mainResources) }
+
+val Kosmos.shortcutHelperStateRepository by
Kosmos.Fixture {
- ShortcutHelperRepository(
+ ShortcutHelperStateRepository(
fakeCommandQueue,
broadcastDispatcher,
fakeInputManager.inputManager,
@@ -43,23 +54,44 @@ val Kosmos.shortcutHelperRepository by
)
}
+val Kosmos.shortcutHelperCategoriesRepository by
+ Kosmos.Fixture {
+ ShortcutHelperCategoriesRepository(
+ shortcutHelperSystemShortcutsSource,
+ shortcutHelperMultiTaskingShortcutsSource,
+ )
+ }
+
val Kosmos.shortcutHelperTestHelper by
Kosmos.Fixture {
ShortcutHelperTestHelper(
- shortcutHelperRepository,
+ shortcutHelperStateRepository,
applicationContext,
broadcastDispatcher,
fakeCommandQueue
)
}
-val Kosmos.shortcutHelperInteractor by
+val Kosmos.shortcutHelperStateInteractor by
Kosmos.Fixture {
- ShortcutHelperInteractor(displayTracker, testScope, sysUiState, shortcutHelperRepository)
+ ShortcutHelperStateInteractor(
+ displayTracker,
+ testScope,
+ sysUiState,
+ shortcutHelperStateRepository
+ )
+ }
+
+val Kosmos.shortcutHelperCategoriesInteractor by
+ Kosmos.Fixture {
+ ShortcutHelperCategoriesInteractor(
+ shortcutHelperStateRepository,
+ shortcutHelperCategoriesRepository
+ )
}
val Kosmos.shortcutHelperViewModel by
- Kosmos.Fixture { ShortcutHelperViewModel(testDispatcher, shortcutHelperInteractor) }
+ Kosmos.Fixture { ShortcutHelperViewModel(testDispatcher, shortcutHelperStateInteractor) }
val Kosmos.fakeShortcutHelperStartActivity by Kosmos.Fixture { FakeShortcutHelperStartActivity() }
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 e6e7b8796d39..36608ff57c93 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
@@ -22,7 +22,7 @@ import com.android.systemui.broadcast.FakeBroadcastDispatcher
import com.android.systemui.keyguard.data.repository.FakeCommandQueue
class ShortcutHelperTestHelper(
- repo: ShortcutHelperRepository,
+ repo: ShortcutHelperStateRepository,
private val context: Context,
private val fakeBroadcastDispatcher: FakeBroadcastDispatcher,
private val fakeCommandQueue: FakeCommandQueue,