Merge "Simplifies view-binder." into tm-qpr-dev am: 345fc0cffc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19610381

Change-Id: I1a28debd4d4bb7d313fe286e4e594b4979ca6d75
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Alejandro Nijamkin
2022-08-13 16:42:59 +00:00
committed by Automerger Merge Worker
4 changed files with 46 additions and 40 deletions

View File

@@ -95,35 +95,23 @@ object KeyguardBottomAreaViewBinder {
view.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
combine(viewModel.startButton, viewModel.animateButtonReveal) {
buttonModel,
animateReveal ->
Pair(buttonModel, animateReveal)
}
.collect { (buttonModel, animateReveal) ->
updateButton(
view = startButton,
viewModel = buttonModel,
animateReveal = animateReveal,
falsingManager = falsingManager,
)
}
viewModel.startButton.collect { buttonModel ->
updateButton(
view = startButton,
viewModel = buttonModel,
falsingManager = falsingManager,
)
}
}
launch {
combine(viewModel.endButton, viewModel.animateButtonReveal) {
buttonModel,
animateReveal ->
Pair(buttonModel, animateReveal)
}
.collect { (buttonModel, animateReveal) ->
updateButton(
view = endButton,
viewModel = buttonModel,
animateReveal = animateReveal,
falsingManager = falsingManager,
)
}
viewModel.endButton.collect { buttonModel ->
updateButton(
view = endButton,
viewModel = buttonModel,
falsingManager = falsingManager,
)
}
}
launch {
@@ -226,7 +214,6 @@ object KeyguardBottomAreaViewBinder {
private fun updateButton(
view: ImageView,
viewModel: KeyguardQuickAffordanceViewModel,
animateReveal: Boolean,
falsingManager: FalsingManager,
) {
if (!viewModel.isVisible) {
@@ -236,7 +223,7 @@ object KeyguardBottomAreaViewBinder {
if (!view.isVisible) {
view.isVisible = true
if (animateReveal) {
if (viewModel.animateReveal) {
view.alpha = 0f
view.translationY = view.height / 2f
view

View File

@@ -34,7 +34,7 @@ class KeyguardBottomAreaViewModel
constructor(
private val keyguardInteractor: KeyguardInteractor,
private val quickAffordanceInteractor: KeyguardQuickAffordanceInteractor,
bottomAreaInteractor: KeyguardBottomAreaInteractor,
private val bottomAreaInteractor: KeyguardBottomAreaInteractor,
private val burnInHelperWrapper: BurnInHelperWrapper,
) {
/** An observable for the view-model of the "start button" quick affordance. */
@@ -43,12 +43,6 @@ constructor(
/** An observable for the view-model of the "end button" quick affordance. */
val endButton: Flow<KeyguardQuickAffordanceViewModel> =
button(KeyguardQuickAffordancePosition.BOTTOM_END)
/**
* An observable for whether the next time a quick action button becomes visible, it should
* animate.
*/
val animateButtonReveal: Flow<Boolean> =
bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged()
/** An observable for whether the overlay container should be visible. */
val isOverlayContainerVisible: Flow<Boolean> =
keyguardInteractor.isDozing.map { !it }.distinctUntilChanged()
@@ -80,18 +74,24 @@ constructor(
private fun button(
position: KeyguardQuickAffordancePosition
): Flow<KeyguardQuickAffordanceViewModel> {
return quickAffordanceInteractor
.quickAffordance(position)
.map { model -> model.toViewModel() }
return combine(
quickAffordanceInteractor.quickAffordance(position),
bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged(),
) { model, animateReveal ->
model.toViewModel(animateReveal)
}
.distinctUntilChanged()
}
private fun KeyguardQuickAffordanceModel.toViewModel(): KeyguardQuickAffordanceViewModel {
private fun KeyguardQuickAffordanceModel.toViewModel(
animateReveal: Boolean,
): KeyguardQuickAffordanceViewModel {
return when (this) {
is KeyguardQuickAffordanceModel.Visible ->
KeyguardQuickAffordanceViewModel(
configKey = configKey,
isVisible = true,
animateReveal = animateReveal,
icon = icon,
contentDescriptionResourceId = contentDescriptionResourceId,
onClicked = { parameters ->

View File

@@ -26,6 +26,8 @@ import kotlin.reflect.KClass
data class KeyguardQuickAffordanceViewModel(
val configKey: KClass<out KeyguardQuickAffordanceConfig>? = null,
val isVisible: Boolean = false,
/** Whether to animate the transition of the quick affordance from invisible to visible. */
val animateReveal: Boolean = false,
val icon: ContainedDrawable = ContainedDrawable.WithResource(0),
@StringRes val contentDescriptionResourceId: Int = 0,
val onClicked: (OnClickedParameters) -> Unit = {},

View File

@@ -41,6 +41,7 @@ import kotlin.reflect.KClass
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -196,11 +197,27 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() {
@Test
fun animateButtonReveal() = runBlockingTest {
repository.setKeyguardShowing(true)
val testConfig =
TestConfig(
isVisible = true,
icon = mock(),
canShowWhileLocked = false,
intent = Intent("action"),
)
setUpQuickAffordanceModel(
position = KeyguardQuickAffordancePosition.BOTTOM_START,
testConfig = testConfig,
)
val values = mutableListOf<Boolean>()
val job = underTest.animateButtonReveal.onEach(values::add).launchIn(this)
val job = underTest.startButton.onEach { values.add(it.animateReveal) }.launchIn(this)
repository.setAnimateDozingTransitions(true)
yield()
repository.setAnimateDozingTransitions(false)
yield()
assertThat(values).isEqualTo(listOf(false, true, false))
job.cancel()