summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2020-04-11 01:19:37 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-04-11 01:19:37 +0000
commit2f601f4dbe3d95bf77b5a7352127bbaeff21571b (patch)
treed5a02363b964bd272f257031afc355e21924ff5e
parent0abf11e202e6a5d06de4a8c9be1aa0aa3000810f (diff)
parent0cf2bc2f53705f493254da4f058a1e5b78842381 (diff)
Merge "LiveData#getValue can return null" into rvc-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/SeekBarViewModel.kt13
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/SeekBarViewModel.kt b/packages/SystemUI/src/com/android/systemui/media/SeekBarViewModel.kt
index cf8f26841cf9..dd83e42cde2d 100644
--- a/packages/SystemUI/src/com/android/systemui/media/SeekBarViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/SeekBarViewModel.kt
@@ -34,8 +34,13 @@ private const val POSITION_UPDATE_INTERVAL_MILLIS = 100L
/** ViewModel for seek bar in QS media player. */
class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
+ private var _data = Progress(false, false, null, null, null)
+ set(value) {
+ field = value
+ _progress.postValue(value)
+ }
private val _progress = MutableLiveData<Progress>().apply {
- postValue(Progress(false, false, null, null, null))
+ postValue(_data)
}
val progress: LiveData<Progress>
get() = _progress
@@ -73,7 +78,7 @@ class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
val position = playbackState?.position?.toInt()
val duration = mediaMetadata?.getLong(MediaMetadata.METADATA_KEY_DURATION)?.toInt()
val enabled = if (duration != null && duration <= 0) false else true
- _progress.postValue(Progress(enabled, seekAvailable, position, duration, color))
+ _data = Progress(enabled, seekAvailable, position, duration, color)
if (shouldPollPlaybackPosition()) {
checkPlaybackPosition()
}
@@ -82,8 +87,8 @@ class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
@AnyThread
private fun checkPlaybackPosition(): Runnable = bgExecutor.executeDelayed({
val currentPosition = controller?.playbackState?.position?.toInt()
- if (currentPosition != null && _progress.value!!.elapsedTime != currentPosition) {
- _progress.postValue(_progress.value!!.copy(elapsedTime = currentPosition))
+ if (currentPosition != null && _data.elapsedTime != currentPosition) {
+ _data = _data.copy(elapsedTime = currentPosition)
}
if (shouldPollPlaybackPosition()) {
checkPlaybackPosition()