Merge "Squishy ViewState no longer mutates global album art widgetState" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4b33784612
@@ -278,13 +278,14 @@ class MediaViewController @Inject constructor(
|
|||||||
/**
|
/**
|
||||||
* Apply squishFraction to a copy of viewState such that the cached version is untouched.
|
* Apply squishFraction to a copy of viewState such that the cached version is untouched.
|
||||||
*/
|
*/
|
||||||
private fun squishViewState(
|
@VisibleForTesting
|
||||||
|
internal fun squishViewState(
|
||||||
viewState: TransitionViewState,
|
viewState: TransitionViewState,
|
||||||
squishFraction: Float
|
squishFraction: Float
|
||||||
): TransitionViewState {
|
): TransitionViewState {
|
||||||
val squishedViewState = viewState.copy()
|
val squishedViewState = viewState.copy()
|
||||||
squishedViewState.height = (squishedViewState.height * squishFraction).toInt()
|
squishedViewState.height = (squishedViewState.height * squishFraction).toInt()
|
||||||
val albumArtViewState = viewState.widgetStates.get(R.id.album_art)
|
val albumArtViewState = squishedViewState.widgetStates.get(R.id.album_art)
|
||||||
if (albumArtViewState != null) {
|
if (albumArtViewState != null) {
|
||||||
albumArtViewState.height = squishedViewState.height
|
albumArtViewState.height = squishedViewState.height
|
||||||
}
|
}
|
||||||
@@ -317,6 +318,7 @@ class MediaViewController @Inject constructor(
|
|||||||
if (transitionLayout == null) {
|
if (transitionLayout == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not cached. Let's create a new measurement
|
// Not cached. Let's create a new measurement
|
||||||
if (state.expansion == 0.0f || state.expansion == 1.0f) {
|
if (state.expansion == 0.0f || state.expansion == 1.0f) {
|
||||||
result = transitionLayout!!.calculateViewState(
|
result = transitionLayout!!.calculateViewState(
|
||||||
|
|||||||
@@ -4,16 +4,22 @@ import android.testing.AndroidTestingRunner
|
|||||||
import android.testing.TestableLooper
|
import android.testing.TestableLooper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
|
import com.android.systemui.R
|
||||||
import com.android.systemui.SysuiTestCase
|
import com.android.systemui.SysuiTestCase
|
||||||
import com.android.systemui.util.animation.MeasurementInput
|
import com.android.systemui.util.animation.MeasurementInput
|
||||||
import com.android.systemui.util.animation.TransitionLayout
|
import com.android.systemui.util.animation.TransitionLayout
|
||||||
import com.android.systemui.util.animation.TransitionViewState
|
import com.android.systemui.util.animation.TransitionViewState
|
||||||
|
import com.android.systemui.util.animation.WidgetState
|
||||||
import junit.framework.Assert.assertTrue
|
import junit.framework.Assert.assertTrue
|
||||||
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
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.times
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
|
import org.mockito.Mockito.verifyNoMoreInteractions
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
|
import org.mockito.Mockito.`when` as whenever
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link MediaViewController}.
|
* Tests for {@link MediaViewController}.
|
||||||
@@ -31,6 +37,9 @@ class MediaViewControllerTest : SysuiTestCase() {
|
|||||||
private lateinit var mediaViewController: MediaViewController
|
private lateinit var mediaViewController: MediaViewController
|
||||||
private val mediaHostStateHolder = MediaHost.MediaHostStateHolder()
|
private val mediaHostStateHolder = MediaHost.MediaHostStateHolder()
|
||||||
private var transitionLayout = TransitionLayout(context, /* attrs */ null, /* defStyleAttr */ 0)
|
private var transitionLayout = TransitionLayout(context, /* attrs */ null, /* defStyleAttr */ 0)
|
||||||
|
@Mock private lateinit var mockViewState: TransitionViewState
|
||||||
|
@Mock private lateinit var mockCopiedState: TransitionViewState
|
||||||
|
@Mock private lateinit var mockWidgetState: WidgetState
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
@@ -63,4 +72,15 @@ class MediaViewControllerTest : SysuiTestCase() {
|
|||||||
mediaHostStateHolder.squishFraction = 0.5f
|
mediaHostStateHolder.squishFraction = 0.5f
|
||||||
assertTrue(mediaViewController.obtainViewState(mediaHostStateHolder)!!.height == 50)
|
assertTrue(mediaViewController.obtainViewState(mediaHostStateHolder)!!.height == 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSquish_DoesNotMutateViewState() {
|
||||||
|
whenever(mockViewState.copy()).thenReturn(mockCopiedState)
|
||||||
|
whenever(mockCopiedState.widgetStates)
|
||||||
|
.thenReturn(mutableMapOf(R.id.album_art to mockWidgetState))
|
||||||
|
|
||||||
|
mediaViewController.squishViewState(mockViewState, 0.5f)
|
||||||
|
verify(mockViewState, times(1)).copy()
|
||||||
|
verifyNoMoreInteractions(mockViewState)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user