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

Commit f6bcf6a0 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Add squishiness to tiles.

Also, wire some other QSFragmentComposeViewModel values

Test: manual
Fixes: 369657526
Flag: com.android.systemui.qs_ui_refactor_compose_fragment

Change-Id: I9ee1636c19b1f519c5f9b134ea6c7c1306dc121a
parent d4ea4434
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.fgsManagerController
import com.android.systemui.qs.panels.domain.interactor.tileSquishinessInteractor
import com.android.systemui.res.R
import com.android.systemui.shade.largeScreenHeaderHelper
import com.android.systemui.statusbar.StatusBarState
@@ -40,6 +41,7 @@ import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.resetMain
@@ -205,16 +207,40 @@ class QSFragmentComposeViewModelTest : SysuiTestCase() {
            }
        }

    @Test
    fun squishinessInExpansion_setInInteractor() =
        with(kosmos) {
            testScope.testWithinLifecycle {
                val squishiness by collectLastValue(tileSquishinessInteractor.squishiness)

                underTest.squishinessFractionValue = 0.3f
                assertThat(squishiness).isWithin(epsilon).of(0.3f.constrainSquishiness())

                underTest.squishinessFractionValue = 0f
                assertThat(squishiness).isWithin(epsilon).of(0f.constrainSquishiness())

                underTest.squishinessFractionValue = 1f
                assertThat(squishiness).isWithin(epsilon).of(1f.constrainSquishiness())
            }
        }

    private inline fun TestScope.testWithinLifecycle(
        crossinline block: suspend TestScope.() -> TestResult
    ): TestResult {
        return runTest {
            lifecycleOwner.setCurrentState(Lifecycle.State.RESUMED)
            lifecycleOwner.lifecycleScope.launch { underTest.activate() }
            block().also { lifecycleOwner.setCurrentState(Lifecycle.State.DESTROYED) }
        }
    }

    companion object {
        private const val QS_DISABLE_FLAG = StatusBarManager.DISABLE2_QUICK_SETTINGS

        private fun Float.constrainSquishiness(): Float {
            return (0.1f + this * 0.9f).coerceIn(0f, 1f)
        }

        private const val epsilon = 0.001f
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -22,10 +22,8 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository
import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository
import com.android.systemui.qs.panels.ui.compose.infinitegrid.InfiniteGridLayout
import com.android.systemui.qs.panels.domain.interactor.infiniteGridLayout
import com.android.systemui.qs.panels.ui.viewmodel.MockTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.fixedColumnsSizeViewModel
import com.android.systemui.qs.panels.ui.viewmodel.iconTilesViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -44,8 +42,7 @@ class InfiniteGridLayoutTest : SysuiTestCase() {
                }
        }

    private val underTest =
        with(kosmos) { InfiniteGridLayout(iconTilesViewModel, fixedColumnsSizeViewModel) }
    private val underTest = kosmos.infiniteGridLayout

    @Test
    fun correctPagination_underOnePage_sameOrder() =
+6 −5
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ constructor(
        qqsMediaHost.init(MediaHierarchyManager.LOCATION_QQS)
        qsMediaHost.init(MediaHierarchyManager.LOCATION_QS)
        setListenerCollections()
        lifecycleScope.launch { viewModel.activate() }
    }

    override fun onCreateView(
@@ -410,11 +411,11 @@ constructor(
        qsTransitionFraction: Float,
        qsSquishinessFraction: Float,
    ) {
        super.setTransitionToFullShadeProgress(
            isTransitioningToFullShade,
            qsTransitionFraction,
            qsSquishinessFraction,
        )
        viewModel.transitioningToFullShadeValue = isTransitioningToFullShade
        viewModel.lockscreenToShadeProgressValue = qsTransitionFraction
        if (isTransitioningToFullShade) {
            viewModel.squishinessFractionValue = qsSquishinessFraction
        }
    }

    override fun setFancyClipping(
+31 −4
Original line number Diff line number Diff line
@@ -24,9 +24,11 @@ import androidx.lifecycle.LifecycleCoroutineScope
import com.android.systemui.Dumpable
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.qs.FooterActionsController
import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
import com.android.systemui.qs.panels.domain.interactor.TileSquishinessInteractor
import com.android.systemui.qs.ui.viewmodel.QuickSettingsContainerViewModel
import com.android.systemui.shade.LargeScreenHeaderHelper
import com.android.systemui.shade.transition.LargeScreenShadeInterpolator
@@ -42,7 +44,6 @@ import com.android.systemui.utils.coroutines.flow.conflatedCallbackFlow
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.io.PrintWriter
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -52,6 +53,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import java.io.PrintWriter

class QSFragmentComposeViewModel
@AssistedInject
@@ -66,8 +68,9 @@ constructor(
    private val largeScreenShadeInterpolator: LargeScreenShadeInterpolator,
    private val configurationInteractor: ConfigurationInteractor,
    private val largeScreenHeaderHelper: LargeScreenHeaderHelper,
    private val squishinessInteractor: TileSquishinessInteractor,
    @Assisted private val lifecycleScope: LifecycleCoroutineScope,
) : Dumpable {
) : Dumpable, ExclusiveActivatable() {
    val footerActionsViewModel =
        footerActionsViewModelFactory.create(lifecycleScope).also {
            lifecycleScope.launch { footerActionsController.init() }
@@ -110,7 +113,7 @@ constructor(
            _panelFraction.value = value
        }

    private val _squishinessFraction = MutableStateFlow(0f)
    private val _squishinessFraction = MutableStateFlow(1f)
    var squishinessFractionValue: Float
        get() = _squishinessFraction.value
        set(value) {
@@ -190,8 +193,18 @@ constructor(
    private val _inSplitShade = MutableStateFlow(false)

    private val _transitioningToFullShade = MutableStateFlow(false)
    var transitioningToFullShadeValue: Boolean
        get() = _transitioningToFullShade.value
        set(value) {
            _transitioningToFullShade.value = value
        }

    private val _lockscreenToShadeProgress = MutableStateFlow(false)
    private val _lockscreenToShadeProgress = MutableStateFlow(0.0f)
    var lockscreenToShadeProgressValue: Float
        get() = _lockscreenToShadeProgress.value
        set(value) {
            _lockscreenToShadeProgress.value = value
        }

    private val _overscrolling = MutableStateFlow(false)

@@ -225,6 +238,16 @@ constructor(
     */
    var collapseExpandAccessibilityAction: Runnable? = null

    override suspend fun onActivated(): Nothing {
        hydrateSquishinessInteractor()
    }

    private suspend fun hydrateSquishinessInteractor(): Nothing {
        _squishinessFraction.collect {
            squishinessInteractor.setSquishinessValue(it.constrainSquishiness())
        }
    }

    override fun dump(pw: PrintWriter, args: Array<out String>) {
        pw.asIndenting().run {
            printSection("Quick Settings state") {
@@ -257,3 +280,7 @@ constructor(
    // In the future, this will have other relevant elements like squishiness.
    data class QSExpansionState(@FloatRange(0.0, 1.0) val progress: Float)
}

private fun Float.constrainSquishiness(): Float {
    return (0.1f + this * 0.9f).coerceIn(0f, 1f)
}
+32 −0
Original line number 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.data.repository

import com.android.systemui.dagger.SysUISingleton
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

@SysUISingleton
class TileSquishinessRepository @Inject constructor() {
    private val _squishiness = MutableStateFlow(1f)
    val squishiness = _squishiness.asStateFlow()

    fun setSquishinessValue(value: Float) {
        _squishiness.value = value
    }
}
 No newline at end of file
Loading