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

Commit 3ef50c5b authored by Beverly's avatar Beverly
Browse files

Remove Udfps's BackgroundViewModel

There's no need to unnecessarily create a new
object for every alpha change. Instead, the view binders
directly will listen for alpha and color changes in separate flows.

Test: builds
Flag: ACONFIG com.android.systemui.device_entry_udfps_refactor DEVELOPMENT
Bug: 305234447
Change-Id: I7825436baed323418830a26a9855845eaf634ac4
parent f52c85f3
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.keyguard.ui.view.DeviceEntryIconView
import com.android.systemui.keyguard.ui.viewmodel.AlternateBouncerUdfpsIconViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch

@ExperimentalCoroutinesApi
object AlternateBouncerUdfpsViewBinder {
@@ -71,11 +72,13 @@ object AlternateBouncerUdfpsViewBinder {
        bgView.visibility = View.VISIBLE
        bgView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.bgViewModel.collect { bgViewModel ->
                    bgView.alpha = bgViewModel.alpha
                    bgView.imageTintList = ColorStateList.valueOf(bgViewModel.tint)
                launch {
                    viewModel.bgColor.collect { color ->
                        bgView.imageTintList = ColorStateList.valueOf(color)
                    }
                }
                launch { viewModel.bgAlpha.collect { alpha -> bgView.alpha = alpha } }
            }
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -131,10 +131,10 @@ object DeviceEntryIconViewBinder {

        bgView.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.CREATED) {
                launch { bgViewModel.alpha.collect { alpha -> bgView.alpha = alpha } }
                launch {
                    bgViewModel.viewModel.collect { bgViewModel ->
                        bgView.alpha = bgViewModel.alpha
                        bgView.imageTintList = ColorStateList.valueOf(bgViewModel.tint)
                    bgViewModel.color.collect { color ->
                        bgView.imageTintList = ColorStateList.valueOf(color)
                    }
                }
            }
+3 −20
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ constructor(
    val context: Context,
    configurationInteractor: ConfigurationInteractor,
    deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor,
    deviceEntryBackgroundViewModel: DeviceEntryBackgroundViewModel,
    fingerprintPropertyRepository: FingerprintPropertyRepository,
) {
    private val isSupported: Flow<Boolean> = deviceEntryUdfpsInteractor.isUdfpsSupported
@@ -90,26 +91,8 @@ constructor(
            )
        }

    private val bgColor: Flow<Int> =
        configurationInteractor.onAnyConfigurationChange
            .map {
                Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorSurface)
            }
            .onStart {
                emit(
                    Utils.getColorAttrDefaultColor(
                        context,
                        com.android.internal.R.attr.colorSurface
                    )
                )
            }
    val bgViewModel: Flow<DeviceEntryBackgroundViewModel.BackgroundViewModel> =
        bgColor.map { color ->
            DeviceEntryBackgroundViewModel.BackgroundViewModel(
                alpha = 1f,
                tint = color,
            )
        }
    val bgColor: Flow<Int> = deviceEntryBackgroundViewModel.color
    val bgAlpha: Flow<Float> = flowOf(1f)

    data class IconLocation(
        val left: Int,
+5 −19
Original line number Diff line number Diff line
@@ -19,11 +19,10 @@ package com.android.systemui.keyguard.ui.viewmodel

import android.content.Context
import com.android.settingslib.Utils
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
@@ -34,7 +33,7 @@ class DeviceEntryBackgroundViewModel
@Inject
constructor(
    val context: Context,
    configurationRepository: ConfigurationRepository, // TODO (b/309655554): create & use interactor
    configurationInteractor: ConfigurationInteractor,
    lockscreenToAodTransitionViewModel: LockscreenToAodTransitionViewModel,
    aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel,
    goneToAodTransitionViewModel: GoneToAodTransitionViewModel,
@@ -44,8 +43,8 @@ constructor(
    dreamingToLockscreenTransitionViewModel: DreamingToLockscreenTransitionViewModel,
    alternateBouncerToAodTransitionViewModel: AlternateBouncerToAodTransitionViewModel,
) {
    private val color: Flow<Int> =
        configurationRepository.onAnyConfigurationChange
    val color: Flow<Int> =
        configurationInteractor.onAnyConfigurationChange
            .map {
                Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorSurface)
            }
@@ -57,7 +56,7 @@ constructor(
                    )
                )
            }
    private val alpha: Flow<Float> =
    val alpha: Flow<Float> =
        setOf(
                lockscreenToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
                aodToLockscreenTransitionViewModel.deviceEntryBackgroundViewAlpha,
@@ -69,17 +68,4 @@ constructor(
                alternateBouncerToAodTransitionViewModel.deviceEntryBackgroundViewAlpha,
            )
            .merge()

    val viewModel: Flow<BackgroundViewModel> =
        combine(color, alpha) { color, alpha ->
            BackgroundViewModel(
                alpha = alpha,
                tint = color,
            )
        }

    data class BackgroundViewModel(
        val alpha: Float,
        val tint: Int,
    )
}