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

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

Merge "Cleanup unused icon labels shared preferences" into main

parents 5d88db21 5d48fe60
Loading
Loading
Loading
Loading
+0 −90
Original line number Original line Diff line number Diff line
/*
 * 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.qs.panels.domain.interactor

import android.content.pm.UserInfo
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.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.fakeUserRepository
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class IconLabelVisibilityInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val underTest = with(kosmos) { iconLabelVisibilityInteractor }

    @Before
    fun setUp() {
        with(kosmos) { fakeUserRepository.setUserInfos(USERS) }
    }

    @Test
    fun changingShowLabels_receivesCorrectShowLabels() =
        with(kosmos) {
            testScope.runTest {
                val showLabels by collectLastValue(underTest.showLabels)

                underTest.setShowLabels(false)
                runCurrent()
                assertThat(showLabels).isFalse()

                underTest.setShowLabels(true)
                runCurrent()
                assertThat(showLabels).isTrue()
            }
        }

    @Test
    fun changingUser_receivesCorrectShowLabels() =
        with(kosmos) {
            testScope.runTest {
                val showLabels by collectLastValue(underTest.showLabels)

                fakeUserRepository.setSelectedUserInfo(PRIMARY_USER)
                underTest.setShowLabels(false)
                runCurrent()
                assertThat(showLabels).isFalse()

                fakeUserRepository.setSelectedUserInfo(ANOTHER_USER)
                underTest.setShowLabels(true)
                runCurrent()
                assertThat(showLabels).isTrue()

                fakeUserRepository.setSelectedUserInfo(PRIMARY_USER)
                runCurrent()
                assertThat(showLabels).isFalse()
            }
        }

    companion object {
        private val PRIMARY_USER = UserInfo(0, "user 0", UserInfo.FLAG_MAIN)
        private val ANOTHER_USER = UserInfo(1, "user 1", UserInfo.FLAG_FULL)
        private val USERS = listOf(PRIMARY_USER, ANOTHER_USER)
    }
}
+0 −7
Original line number Original line Diff line number Diff line
@@ -33,8 +33,6 @@ import com.android.systemui.qs.panels.ui.compose.GridLayout
import com.android.systemui.qs.panels.ui.compose.PaginatableGridLayout
import com.android.systemui.qs.panels.ui.compose.PaginatableGridLayout
import com.android.systemui.qs.panels.ui.compose.PaginatedGridLayout
import com.android.systemui.qs.panels.ui.compose.PaginatedGridLayout
import com.android.systemui.qs.panels.ui.compose.infinitegrid.InfiniteGridLayout
import com.android.systemui.qs.panels.ui.compose.infinitegrid.InfiniteGridLayout
import com.android.systemui.qs.panels.ui.viewmodel.IconLabelVisibilityViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconLabelVisibilityViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.QSColumnsSizeViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.QSColumnsSizeViewModelImpl
@@ -62,11 +60,6 @@ interface PanelsModule {


    @Binds fun bindQSColumnsViewModel(impl: QSColumnsSizeViewModelImpl): QSColumnsViewModel
    @Binds fun bindQSColumnsViewModel(impl: QSColumnsSizeViewModelImpl): QSColumnsViewModel


    @Binds
    fun bindIconLabelVisibilityViewModel(
        impl: IconLabelVisibilityViewModelImpl
    ): IconLabelVisibilityViewModel

    @Binds
    @Binds
    @PaginatedBaseLayoutType
    @PaginatedBaseLayoutType
    fun bindPaginatedBaseGridLayout(impl: InfiniteGridLayout): PaginatableGridLayout
    fun bindPaginatedBaseGridLayout(impl: InfiniteGridLayout): PaginatableGridLayout
+0 −60
Original line number Original line Diff line number Diff line
/*
 * 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.qs.panels.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.qs.panels.shared.model.PanelsLog
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

@SysUISingleton
class IconLabelVisibilityInteractor
@Inject
constructor(
    private val preferencesInteractor: QSPreferencesInteractor,
    @PanelsLog private val logBuffer: LogBuffer,
    @Application scope: CoroutineScope,
) {
    val showLabels: StateFlow<Boolean> =
        preferencesInteractor.showLabels
            .onEach { logChange(it) }
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    fun setShowLabels(showLabels: Boolean) {
        preferencesInteractor.setShowLabels(showLabels)
    }

    private fun logChange(showLabels: Boolean) {
        logBuffer.log(
            LOG_BUFFER_ICON_TILE_LABEL_VISIBILITY_CHANGE_TAG,
            LogLevel.DEBUG,
            { bool1 = showLabels },
            { "Icon tile label visibility changed: $bool1" }
        )
    }

    private companion object {
        const val LOG_BUFFER_ICON_TILE_LABEL_VISIBILITY_CHANGE_TAG = "IconLabelVisibilityChange"
    }
}
+0 −5
Original line number Original line Diff line number Diff line
@@ -24,13 +24,8 @@ import kotlinx.coroutines.flow.Flow


@SysUISingleton
@SysUISingleton
class QSPreferencesInteractor @Inject constructor(private val repo: QSPreferencesRepository) {
class QSPreferencesInteractor @Inject constructor(private val repo: QSPreferencesRepository) {
    val showLabels: Flow<Boolean> = repo.showLabels
    val largeTilesSpecs: Flow<Set<TileSpec>> = repo.largeTilesSpecs
    val largeTilesSpecs: Flow<Set<TileSpec>> = repo.largeTilesSpecs


    fun setShowLabels(showLabels: Boolean) {
        repo.setShowLabels(showLabels)
    }

    fun setLargeTilesSpecs(specs: Set<TileSpec>) {
    fun setLargeTilesSpecs(specs: Set<TileSpec>) {
        repo.setLargeTilesSpecs(specs)
        repo.setLargeTilesSpecs(specs)
    }
    }
+0 −41
Original line number Original line Diff line number Diff line
/*
 * 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.qs.panels.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.qs.panels.domain.interactor.IconLabelVisibilityInteractor
import javax.inject.Inject
import kotlinx.coroutines.flow.StateFlow

interface IconLabelVisibilityViewModel {
    val showLabels: StateFlow<Boolean>

    fun setShowLabels(showLabels: Boolean)
}

@SysUISingleton
class IconLabelVisibilityViewModelImpl
@Inject
constructor(
    private val interactor: IconLabelVisibilityInteractor,
) : IconLabelVisibilityViewModel {
    override val showLabels: StateFlow<Boolean> = interactor.showLabels

    override fun setShowLabels(showLabels: Boolean) {
        interactor.setShowLabels(showLabels)
    }
}
Loading