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

Commit 0ed8f65f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Updated Apps Shortcut Repo to emit only when Shortcut Helper is Active" into main

parents d0993b41 22c542e1
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ 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.ShortcutIcon
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.res.R
@@ -50,6 +51,7 @@ class AppsShortcutCategoryRepositoryTest : SysuiTestCase() {
    private val fakeLauncherApps = kosmos.fakeLauncherApps
    private val userTracker = kosmos.fakeUserTracker
    private val testScope = kosmos.testScope
    private val helper = kosmos.shortcutHelperTestHelper

    @Before
    fun setup() {
@@ -76,6 +78,18 @@ class AppsShortcutCategoryRepositoryTest : SysuiTestCase() {
            ICON_RES_ID_2,
            TEST_PACKAGE_LABEL_2,
        )

        helper.showFromActivity()
    }

    @Test
    fun categories_emitsEmptyList_whenShortcutHelperIsInactive() {
        testScope.runTest {
            val categories by collectLastValue(repo.categories)
            helper.hideFromActivity()

            assertThat(categories).isEmpty()
        }
    }

    @Test
+11 −4
Original line number Diff line number Diff line
@@ -22,22 +22,29 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyboard.shortcut.shared.model.Shortcut
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.ShortcutHelperState
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutIcon
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
import com.android.systemui.res.R
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

@SysUISingleton
class AppsShortcutCategoryRepository
@Inject
constructor(userVisibleAppsRepository: UserVisibleAppsRepository, context: Context) :
    ShortcutCategoriesRepository {
constructor(
    userVisibleAppsRepository: UserVisibleAppsRepository,
    context: Context,
    stateRepository: ShortcutHelperStateRepository,
) : ShortcutCategoriesRepository {

    override val categories: Flow<List<ShortcutCategory>> =
        userVisibleAppsRepository.userVisibleApps.map { userVisibleApps ->
            if (userVisibleApps.isEmpty()) {
        stateRepository.state.combine(userVisibleAppsRepository.userVisibleApps) {
            state,
            userVisibleApps ->
            if (state is ShortcutHelperState.Inactive || userVisibleApps.isEmpty()) {
                emptyList()
            } else {
                listOf(
+7 −1
Original line number Diff line number Diff line
@@ -195,7 +195,13 @@ val Kosmos.shortcutHelperStateInteractor by
    }

var Kosmos.appsShortcutCategoryRepository: ShortcutCategoriesRepository by
    Kosmos.Fixture { AppsShortcutCategoryRepository(userVisibleAppsRepository, applicationContext) }
    Kosmos.Fixture {
        AppsShortcutCategoryRepository(
            userVisibleAppsRepository,
            applicationContext,
            shortcutHelperStateRepository,
        )
    }

val Kosmos.shortcutHelperCategoriesInteractor by
    Kosmos.Fixture {