Merge "Simplifies view-binder." into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
345fc0cffc
@@ -95,35 +95,23 @@ object KeyguardBottomAreaViewBinder {
|
|||||||
view.repeatWhenAttached {
|
view.repeatWhenAttached {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
launch {
|
launch {
|
||||||
combine(viewModel.startButton, viewModel.animateButtonReveal) {
|
viewModel.startButton.collect { buttonModel ->
|
||||||
buttonModel,
|
updateButton(
|
||||||
animateReveal ->
|
view = startButton,
|
||||||
Pair(buttonModel, animateReveal)
|
viewModel = buttonModel,
|
||||||
}
|
falsingManager = falsingManager,
|
||||||
.collect { (buttonModel, animateReveal) ->
|
)
|
||||||
updateButton(
|
}
|
||||||
view = startButton,
|
|
||||||
viewModel = buttonModel,
|
|
||||||
animateReveal = animateReveal,
|
|
||||||
falsingManager = falsingManager,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
combine(viewModel.endButton, viewModel.animateButtonReveal) {
|
viewModel.endButton.collect { buttonModel ->
|
||||||
buttonModel,
|
updateButton(
|
||||||
animateReveal ->
|
view = endButton,
|
||||||
Pair(buttonModel, animateReveal)
|
viewModel = buttonModel,
|
||||||
}
|
falsingManager = falsingManager,
|
||||||
.collect { (buttonModel, animateReveal) ->
|
)
|
||||||
updateButton(
|
}
|
||||||
view = endButton,
|
|
||||||
viewModel = buttonModel,
|
|
||||||
animateReveal = animateReveal,
|
|
||||||
falsingManager = falsingManager,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
@@ -226,7 +214,6 @@ object KeyguardBottomAreaViewBinder {
|
|||||||
private fun updateButton(
|
private fun updateButton(
|
||||||
view: ImageView,
|
view: ImageView,
|
||||||
viewModel: KeyguardQuickAffordanceViewModel,
|
viewModel: KeyguardQuickAffordanceViewModel,
|
||||||
animateReveal: Boolean,
|
|
||||||
falsingManager: FalsingManager,
|
falsingManager: FalsingManager,
|
||||||
) {
|
) {
|
||||||
if (!viewModel.isVisible) {
|
if (!viewModel.isVisible) {
|
||||||
@@ -236,7 +223,7 @@ object KeyguardBottomAreaViewBinder {
|
|||||||
|
|
||||||
if (!view.isVisible) {
|
if (!view.isVisible) {
|
||||||
view.isVisible = true
|
view.isVisible = true
|
||||||
if (animateReveal) {
|
if (viewModel.animateReveal) {
|
||||||
view.alpha = 0f
|
view.alpha = 0f
|
||||||
view.translationY = view.height / 2f
|
view.translationY = view.height / 2f
|
||||||
view
|
view
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class KeyguardBottomAreaViewModel
|
|||||||
constructor(
|
constructor(
|
||||||
private val keyguardInteractor: KeyguardInteractor,
|
private val keyguardInteractor: KeyguardInteractor,
|
||||||
private val quickAffordanceInteractor: KeyguardQuickAffordanceInteractor,
|
private val quickAffordanceInteractor: KeyguardQuickAffordanceInteractor,
|
||||||
bottomAreaInteractor: KeyguardBottomAreaInteractor,
|
private val bottomAreaInteractor: KeyguardBottomAreaInteractor,
|
||||||
private val burnInHelperWrapper: BurnInHelperWrapper,
|
private val burnInHelperWrapper: BurnInHelperWrapper,
|
||||||
) {
|
) {
|
||||||
/** An observable for the view-model of the "start button" quick affordance. */
|
/** 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. */
|
/** An observable for the view-model of the "end button" quick affordance. */
|
||||||
val endButton: Flow<KeyguardQuickAffordanceViewModel> =
|
val endButton: Flow<KeyguardQuickAffordanceViewModel> =
|
||||||
button(KeyguardQuickAffordancePosition.BOTTOM_END)
|
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. */
|
/** An observable for whether the overlay container should be visible. */
|
||||||
val isOverlayContainerVisible: Flow<Boolean> =
|
val isOverlayContainerVisible: Flow<Boolean> =
|
||||||
keyguardInteractor.isDozing.map { !it }.distinctUntilChanged()
|
keyguardInteractor.isDozing.map { !it }.distinctUntilChanged()
|
||||||
@@ -80,18 +74,24 @@ constructor(
|
|||||||
private fun button(
|
private fun button(
|
||||||
position: KeyguardQuickAffordancePosition
|
position: KeyguardQuickAffordancePosition
|
||||||
): Flow<KeyguardQuickAffordanceViewModel> {
|
): Flow<KeyguardQuickAffordanceViewModel> {
|
||||||
return quickAffordanceInteractor
|
return combine(
|
||||||
.quickAffordance(position)
|
quickAffordanceInteractor.quickAffordance(position),
|
||||||
.map { model -> model.toViewModel() }
|
bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged(),
|
||||||
|
) { model, animateReveal ->
|
||||||
|
model.toViewModel(animateReveal)
|
||||||
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KeyguardQuickAffordanceModel.toViewModel(): KeyguardQuickAffordanceViewModel {
|
private fun KeyguardQuickAffordanceModel.toViewModel(
|
||||||
|
animateReveal: Boolean,
|
||||||
|
): KeyguardQuickAffordanceViewModel {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is KeyguardQuickAffordanceModel.Visible ->
|
is KeyguardQuickAffordanceModel.Visible ->
|
||||||
KeyguardQuickAffordanceViewModel(
|
KeyguardQuickAffordanceViewModel(
|
||||||
configKey = configKey,
|
configKey = configKey,
|
||||||
isVisible = true,
|
isVisible = true,
|
||||||
|
animateReveal = animateReveal,
|
||||||
icon = icon,
|
icon = icon,
|
||||||
contentDescriptionResourceId = contentDescriptionResourceId,
|
contentDescriptionResourceId = contentDescriptionResourceId,
|
||||||
onClicked = { parameters ->
|
onClicked = { parameters ->
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import kotlin.reflect.KClass
|
|||||||
data class KeyguardQuickAffordanceViewModel(
|
data class KeyguardQuickAffordanceViewModel(
|
||||||
val configKey: KClass<out KeyguardQuickAffordanceConfig>? = null,
|
val configKey: KClass<out KeyguardQuickAffordanceConfig>? = null,
|
||||||
val isVisible: Boolean = false,
|
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),
|
val icon: ContainedDrawable = ContainedDrawable.WithResource(0),
|
||||||
@StringRes val contentDescriptionResourceId: Int = 0,
|
@StringRes val contentDescriptionResourceId: Int = 0,
|
||||||
val onClicked: (OnClickedParameters) -> Unit = {},
|
val onClicked: (OnClickedParameters) -> Unit = {},
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import kotlin.reflect.KClass
|
|||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.test.runBlockingTest
|
import kotlinx.coroutines.test.runBlockingTest
|
||||||
|
import kotlinx.coroutines.yield
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
@@ -196,11 +197,27 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun animateButtonReveal() = runBlockingTest {
|
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 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)
|
repository.setAnimateDozingTransitions(true)
|
||||||
|
yield()
|
||||||
repository.setAnimateDozingTransitions(false)
|
repository.setAnimateDozingTransitions(false)
|
||||||
|
yield()
|
||||||
|
|
||||||
assertThat(values).isEqualTo(listOf(false, true, false))
|
assertThat(values).isEqualTo(listOf(false, true, false))
|
||||||
job.cancel()
|
job.cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user