Merge "Pause squiggle animation when seeking" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2e92c6b7f7
@@ -78,7 +78,7 @@ class SeekBarObserver(
|
|||||||
|
|
||||||
holder.seekBar.thumb.alpha = if (data.seekAvailable) 255 else 0
|
holder.seekBar.thumb.alpha = if (data.seekAvailable) 255 else 0
|
||||||
holder.seekBar.isEnabled = data.seekAvailable
|
holder.seekBar.isEnabled = data.seekAvailable
|
||||||
progressDrawable?.animate = data.playing
|
progressDrawable?.animate = data.playing && !data.scrubbing
|
||||||
|
|
||||||
if (holder.seekBar.maxHeight != seekBarEnabledMaxHeight) {
|
if (holder.seekBar.maxHeight != seekBarEnabledMaxHeight) {
|
||||||
holder.seekBar.maxHeight = seekBarEnabledMaxHeight
|
holder.seekBar.maxHeight = seekBarEnabledMaxHeight
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ private fun PlaybackState.computePosition(duration: Long): Long {
|
|||||||
class SeekBarViewModel @Inject constructor(
|
class SeekBarViewModel @Inject constructor(
|
||||||
@Background private val bgExecutor: RepeatableExecutor
|
@Background private val bgExecutor: RepeatableExecutor
|
||||||
) {
|
) {
|
||||||
private var _data = Progress(false, false, false, null, 0)
|
private var _data = Progress(false, false, false, false, null, 0)
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
_progress.postValue(value)
|
_progress.postValue(value)
|
||||||
@@ -127,6 +127,7 @@ class SeekBarViewModel @Inject constructor(
|
|||||||
if (field != value) {
|
if (field != value) {
|
||||||
field = value
|
field = value
|
||||||
checkIfPollingNeeded()
|
checkIfPollingNeeded()
|
||||||
|
_data = _data.copy(scrubbing = value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ class SeekBarViewModel @Inject constructor(
|
|||||||
val enabled = if (playbackState == null ||
|
val enabled = if (playbackState == null ||
|
||||||
playbackState?.getState() == PlaybackState.STATE_NONE ||
|
playbackState?.getState() == PlaybackState.STATE_NONE ||
|
||||||
(duration <= 0)) false else true
|
(duration <= 0)) false else true
|
||||||
_data = Progress(enabled, seekAvailable, playing, position, duration)
|
_data = Progress(enabled, seekAvailable, playing, scrubbing, position, duration)
|
||||||
checkIfPollingNeeded()
|
checkIfPollingNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,6 +419,7 @@ class SeekBarViewModel @Inject constructor(
|
|||||||
val enabled: Boolean,
|
val enabled: Boolean,
|
||||||
val seekAvailable: Boolean,
|
val seekAvailable: Boolean,
|
||||||
val playing: Boolean,
|
val playing: Boolean,
|
||||||
|
val scrubbing: Boolean,
|
||||||
val elapsedTime: Int?,
|
val elapsedTime: Int?,
|
||||||
val duration: Int
|
val duration: Int
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
|
||||||
context.orCreateTestableResources
|
context.orCreateTestableResources
|
||||||
.addOverride(R.dimen.qs_media_enabled_seekbar_height, enabledHeight)
|
.addOverride(R.dimen.qs_media_enabled_seekbar_height, enabledHeight)
|
||||||
context.orCreateTestableResources
|
context.orCreateTestableResources
|
||||||
@@ -72,7 +71,7 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
fun seekBarGone() {
|
fun seekBarGone() {
|
||||||
// WHEN seek bar is disabled
|
// WHEN seek bar is disabled
|
||||||
val isEnabled = false
|
val isEnabled = false
|
||||||
val data = SeekBarViewModel.Progress(isEnabled, false, false, null, 0)
|
val data = SeekBarViewModel.Progress(isEnabled, false, false, false, null, 0)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN seek bar shows just a thin line with no text
|
// THEN seek bar shows just a thin line with no text
|
||||||
assertThat(seekBarView.isEnabled()).isFalse()
|
assertThat(seekBarView.isEnabled()).isFalse()
|
||||||
@@ -85,7 +84,7 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
fun seekBarVisible() {
|
fun seekBarVisible() {
|
||||||
// WHEN seek bar is enabled
|
// WHEN seek bar is enabled
|
||||||
val isEnabled = true
|
val isEnabled = true
|
||||||
val data = SeekBarViewModel.Progress(isEnabled, true, false, 3000, 12000)
|
val data = SeekBarViewModel.Progress(isEnabled, true, false, false, 3000, 12000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN seek bar is visible and thick
|
// THEN seek bar is visible and thick
|
||||||
assertThat(seekBarView.getVisibility()).isEqualTo(View.VISIBLE)
|
assertThat(seekBarView.getVisibility()).isEqualTo(View.VISIBLE)
|
||||||
@@ -95,7 +94,7 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
@Test
|
@Test
|
||||||
fun seekBarProgress() {
|
fun seekBarProgress() {
|
||||||
// WHEN part of the track has been played
|
// WHEN part of the track has been played
|
||||||
val data = SeekBarViewModel.Progress(true, true, true, 3000, 120000)
|
val data = SeekBarViewModel.Progress(true, true, true, false, 3000, 120000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN seek bar shows the progress
|
// THEN seek bar shows the progress
|
||||||
assertThat(seekBarView.progress).isEqualTo(3000)
|
assertThat(seekBarView.progress).isEqualTo(3000)
|
||||||
@@ -109,7 +108,7 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
fun seekBarDisabledWhenSeekNotAvailable() {
|
fun seekBarDisabledWhenSeekNotAvailable() {
|
||||||
// WHEN seek is not available
|
// WHEN seek is not available
|
||||||
val isSeekAvailable = false
|
val isSeekAvailable = false
|
||||||
val data = SeekBarViewModel.Progress(true, isSeekAvailable, false, 3000, 120000)
|
val data = SeekBarViewModel.Progress(true, isSeekAvailable, false, false, 3000, 120000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN seek bar is not enabled
|
// THEN seek bar is not enabled
|
||||||
assertThat(seekBarView.isEnabled()).isFalse()
|
assertThat(seekBarView.isEnabled()).isFalse()
|
||||||
@@ -119,27 +118,51 @@ class SeekBarObserverTest : SysuiTestCase() {
|
|||||||
fun seekBarEnabledWhenSeekNotAvailable() {
|
fun seekBarEnabledWhenSeekNotAvailable() {
|
||||||
// WHEN seek is available
|
// WHEN seek is available
|
||||||
val isSeekAvailable = true
|
val isSeekAvailable = true
|
||||||
val data = SeekBarViewModel.Progress(true, isSeekAvailable, false, 3000, 120000)
|
val data = SeekBarViewModel.Progress(true, isSeekAvailable, false, false, 3000, 120000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN seek bar is not enabled
|
// THEN seek bar is not enabled
|
||||||
assertThat(seekBarView.isEnabled()).isTrue()
|
assertThat(seekBarView.isEnabled()).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun seekBarPlaying() {
|
fun seekBarPlayingNotScrubbing() {
|
||||||
// WHEN playing
|
// WHEN playing
|
||||||
val isPlaying = true
|
val isPlaying = true
|
||||||
val data = SeekBarViewModel.Progress(true, true, isPlaying, 3000, 120000)
|
val isScrubbing = false
|
||||||
|
val data = SeekBarViewModel.Progress(true, true, isPlaying, isScrubbing, 3000, 120000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN progress drawable is animating
|
// THEN progress drawable is animating
|
||||||
verify(mockSquigglyProgress).animate = true
|
verify(mockSquigglyProgress).animate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun seekBarNotPlaying() {
|
fun seekBarNotPlayingNotScrubbing() {
|
||||||
// WHEN not playing
|
// WHEN not playing & not scrubbing
|
||||||
val isPlaying = false
|
val isPlaying = false
|
||||||
val data = SeekBarViewModel.Progress(true, true, isPlaying, 3000, 120000)
|
val isScrubbing = false
|
||||||
|
val data = SeekBarViewModel.Progress(true, true, isPlaying, isScrubbing, 3000, 120000)
|
||||||
|
observer.onChanged(data)
|
||||||
|
// THEN progress drawable is not animating
|
||||||
|
verify(mockSquigglyProgress).animate = false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun seekBarPlayingScrubbing() {
|
||||||
|
// WHEN playing & scrubbing
|
||||||
|
val isPlaying = true
|
||||||
|
val isScrubbing = true
|
||||||
|
val data = SeekBarViewModel.Progress(true, true, isPlaying, isScrubbing, 3000, 120000)
|
||||||
|
observer.onChanged(data)
|
||||||
|
// THEN progress drawable is not animating
|
||||||
|
verify(mockSquigglyProgress).animate = false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun seekBarNotPlayingScrubbing() {
|
||||||
|
// WHEN playing & scrubbing
|
||||||
|
val isPlaying = false
|
||||||
|
val isScrubbing = true
|
||||||
|
val data = SeekBarViewModel.Progress(true, true, isPlaying, isScrubbing, 3000, 120000)
|
||||||
observer.onChanged(data)
|
observer.onChanged(data)
|
||||||
// THEN progress drawable is not animating
|
// THEN progress drawable is not animating
|
||||||
verify(mockSquigglyProgress).animate = false
|
verify(mockSquigglyProgress).animate = false
|
||||||
|
|||||||
Reference in New Issue
Block a user