Merge "LiveData#getValue can return null" into rvc-dev am: 2f601f4dbe
Change-Id: I5db6a7e41c148e8e456508cd39311b2bbd59f370
This commit is contained in:
@@ -34,8 +34,13 @@ private const val POSITION_UPDATE_INTERVAL_MILLIS = 100L
|
|||||||
/** ViewModel for seek bar in QS media player. */
|
/** ViewModel for seek bar in QS media player. */
|
||||||
class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
|
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 {
|
private val _progress = MutableLiveData<Progress>().apply {
|
||||||
postValue(Progress(false, false, null, null, null))
|
postValue(_data)
|
||||||
}
|
}
|
||||||
val progress: LiveData<Progress>
|
val progress: LiveData<Progress>
|
||||||
get() = _progress
|
get() = _progress
|
||||||
@@ -73,7 +78,7 @@ class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
|
|||||||
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 (duration != null && duration <= 0) false else true
|
||||||
_progress.postValue(Progress(enabled, seekAvailable, position, duration, color))
|
_data = Progress(enabled, seekAvailable, position, duration, color)
|
||||||
if (shouldPollPlaybackPosition()) {
|
if (shouldPollPlaybackPosition()) {
|
||||||
checkPlaybackPosition()
|
checkPlaybackPosition()
|
||||||
}
|
}
|
||||||
@@ -82,8 +87,8 @@ class SeekBarViewModel(val bgExecutor: DelayableExecutor) {
|
|||||||
@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()
|
||||||
if (currentPosition != null && _progress.value!!.elapsedTime != currentPosition) {
|
if (currentPosition != null && _data.elapsedTime != currentPosition) {
|
||||||
_progress.postValue(_progress.value!!.copy(elapsedTime = currentPosition))
|
_data = _data.copy(elapsedTime = currentPosition)
|
||||||
}
|
}
|
||||||
if (shouldPollPlaybackPosition()) {
|
if (shouldPollPlaybackPosition()) {
|
||||||
checkPlaybackPosition()
|
checkPlaybackPosition()
|
||||||
|
|||||||
Reference in New Issue
Block a user