Merge "Show disabled seek bar when session is destroyed" into rvc-dev am: c52300ea49 am: 2e1453a79d
Change-Id: I44fb14e3f348bb532ef6a60ce2247218696e0f63
This commit is contained in:
@@ -61,6 +61,7 @@ class SeekBarObserver(view: View) : Observer<SeekBarViewModel.Progress> {
|
|||||||
if (!data.enabled) {
|
if (!data.enabled) {
|
||||||
seekBarView.setEnabled(false)
|
seekBarView.setEnabled(false)
|
||||||
seekBarView.getThumb().setAlpha(0)
|
seekBarView.getThumb().setAlpha(0)
|
||||||
|
seekBarView.setProgress(0)
|
||||||
elapsedTimeView.setText("")
|
elapsedTimeView.setText("")
|
||||||
totalTimeView.setText("")
|
totalTimeView.setText("")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -77,13 +77,25 @@ class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
|
|||||||
val seekAvailable = ((playbackState?.actions ?: 0L) and PlaybackState.ACTION_SEEK_TO) != 0L
|
val seekAvailable = ((playbackState?.actions ?: 0L) and PlaybackState.ACTION_SEEK_TO) != 0L
|
||||||
val position = playbackState?.position?.toInt()
|
val position = playbackState?.position?.toInt()
|
||||||
val duration = mediaMetadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.toInt()
|
val duration = mediaMetadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.toInt()
|
||||||
val enabled = if (duration != null && duration <= 0) false else true
|
val enabled = if (playbackState == null ||
|
||||||
|
playbackState?.getState() == PlaybackState.STATE_NONE ||
|
||||||
|
(duration != null && duration <= 0)) false else true
|
||||||
_data = Progress(enabled, seekAvailable, position, duration, color)
|
_data = Progress(enabled, seekAvailable, position, duration, color)
|
||||||
if (shouldPollPlaybackPosition()) {
|
if (shouldPollPlaybackPosition()) {
|
||||||
checkPlaybackPosition()
|
checkPlaybackPosition()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts the seek bar into a resumption state.
|
||||||
|
*
|
||||||
|
* This should be called when the media session behind the controller has been destroyed.
|
||||||
|
*/
|
||||||
|
@AnyThread
|
||||||
|
fun clearController() = bgExecutor.execute {
|
||||||
|
_data = _data.copy(enabled = false)
|
||||||
|
}
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
private fun checkPlaybackPosition(): Runnable = bgExecutor.executeDelayed({
|
private fun checkPlaybackPosition(): Runnable = bgExecutor.executeDelayed({
|
||||||
val currentPosition = controller?.playbackState?.position?.toInt()
|
val currentPosition = controller?.playbackState?.position?.toInt()
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ public class QSMediaPlayer extends MediaControlPanel {
|
|||||||
public void clearControls() {
|
public void clearControls() {
|
||||||
super.clearControls();
|
super.clearControls();
|
||||||
|
|
||||||
|
mSeekBarViewModel.clearController();
|
||||||
|
|
||||||
View guts = mMediaNotifView.findViewById(R.id.media_guts);
|
View guts = mMediaNotifView.findViewById(R.id.media_guts);
|
||||||
View options = mMediaNotifView.findViewById(R.id.qs_media_controls_options);
|
View options = mMediaNotifView.findViewById(R.id.qs_media_controls_options);
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,29 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun updateDuration() {
|
fun updateDurationWithPlayback() {
|
||||||
|
// GIVEN that the duration is contained within the metadata
|
||||||
|
val duration = 12000L
|
||||||
|
val metadata = MediaMetadata.Builder().run {
|
||||||
|
putLong(MediaMetadata.METADATA_KEY_DURATION, duration)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getMetadata()).thenReturn(metadata)
|
||||||
|
// AND a valid playback state (ie. media session is not destroyed)
|
||||||
|
val state = PlaybackState.Builder().run {
|
||||||
|
setState(PlaybackState.STATE_PLAYING, 200L, 1f)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getPlaybackState()).thenReturn(state)
|
||||||
|
// WHEN the controller is updated
|
||||||
|
viewModel.updateController(mockController, Color.RED)
|
||||||
|
// THEN the duration is extracted
|
||||||
|
assertThat(viewModel.progress.value!!.duration).isEqualTo(duration)
|
||||||
|
assertThat(viewModel.progress.value!!.enabled).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun updateDurationWithoutPlayback() {
|
||||||
// GIVEN that the duration is contained within the metadata
|
// GIVEN that the duration is contained within the metadata
|
||||||
val duration = 12000L
|
val duration = 12000L
|
||||||
val metadata = MediaMetadata.Builder().run {
|
val metadata = MediaMetadata.Builder().run {
|
||||||
@@ -98,7 +120,7 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
viewModel.updateController(mockController, Color.RED)
|
viewModel.updateController(mockController, Color.RED)
|
||||||
// THEN the duration is extracted
|
// THEN the duration is extracted
|
||||||
assertThat(viewModel.progress.value!!.duration).isEqualTo(duration)
|
assertThat(viewModel.progress.value!!.duration).isEqualTo(duration)
|
||||||
assertThat(viewModel.progress.value!!.enabled).isTrue()
|
assertThat(viewModel.progress.value!!.enabled).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -110,6 +132,12 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
build()
|
build()
|
||||||
}
|
}
|
||||||
whenever(mockController.getMetadata()).thenReturn(metadata)
|
whenever(mockController.getMetadata()).thenReturn(metadata)
|
||||||
|
// AND a valid playback state (ie. media session is not destroyed)
|
||||||
|
val state = PlaybackState.Builder().run {
|
||||||
|
setState(PlaybackState.STATE_PLAYING, 200L, 1f)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getPlaybackState()).thenReturn(state)
|
||||||
// WHEN the controller is updated
|
// WHEN the controller is updated
|
||||||
viewModel.updateController(mockController, Color.RED)
|
viewModel.updateController(mockController, Color.RED)
|
||||||
// THEN the seek bar is disabled
|
// THEN the seek bar is disabled
|
||||||
@@ -125,6 +153,12 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
build()
|
build()
|
||||||
}
|
}
|
||||||
whenever(mockController.getMetadata()).thenReturn(metadata)
|
whenever(mockController.getMetadata()).thenReturn(metadata)
|
||||||
|
// AND a valid playback state (ie. media session is not destroyed)
|
||||||
|
val state = PlaybackState.Builder().run {
|
||||||
|
setState(PlaybackState.STATE_PLAYING, 200L, 1f)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getPlaybackState()).thenReturn(state)
|
||||||
// WHEN the controller is updated
|
// WHEN the controller is updated
|
||||||
viewModel.updateController(mockController, Color.RED)
|
viewModel.updateController(mockController, Color.RED)
|
||||||
// THEN the seek bar is disabled
|
// THEN the seek bar is disabled
|
||||||
@@ -372,4 +406,30 @@ public class SeekBarViewModelTest : SysuiTestCase() {
|
|||||||
// THEN an update task is queued
|
// THEN an update task is queued
|
||||||
assertThat(fakeExecutor.numPending()).isEqualTo(1)
|
assertThat(fakeExecutor.numPending()).isEqualTo(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun clearSeekBar() {
|
||||||
|
// GIVEN that the duration is contained within the metadata
|
||||||
|
val metadata = MediaMetadata.Builder().run {
|
||||||
|
putLong(MediaMetadata.METADATA_KEY_DURATION, 12000L)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getMetadata()).thenReturn(metadata)
|
||||||
|
// AND a valid playback state (ie. media session is not destroyed)
|
||||||
|
val state = PlaybackState.Builder().run {
|
||||||
|
setState(PlaybackState.STATE_PLAYING, 200L, 1f)
|
||||||
|
build()
|
||||||
|
}
|
||||||
|
whenever(mockController.getPlaybackState()).thenReturn(state)
|
||||||
|
// AND the controller has been updated
|
||||||
|
viewModel.updateController(mockController, Color.RED)
|
||||||
|
// WHEN the controller is cleared on the event when the session is destroyed
|
||||||
|
viewModel.clearController()
|
||||||
|
with(fakeExecutor) {
|
||||||
|
advanceClockToNext()
|
||||||
|
runAllReady()
|
||||||
|
}
|
||||||
|
// THEN the seek bar is disabled
|
||||||
|
assertThat(viewModel.progress.value!!.enabled).isFalse()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user