Fix notification bug
Fix a bug where an incomplete notification will show if one changes the loop mode in PlaybackFragment.
This commit is contained in:
parent
844870f4d4
commit
c11882bc7b
2 changed files with 22 additions and 14 deletions
|
@ -141,6 +141,8 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
|
|
||||||
// --- PLAYBACKSTATEMANAGER SETUP ---
|
// --- PLAYBACKSTATEMANAGER SETUP ---
|
||||||
|
|
||||||
|
playbackManager.resetHasPlayedStatus()
|
||||||
|
|
||||||
playbackManager.addCallback(this)
|
playbackManager.addCallback(this)
|
||||||
|
|
||||||
if (playbackManager.song != null) {
|
if (playbackManager.song != null) {
|
||||||
|
@ -225,13 +227,9 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
|
|
||||||
uploadMetadataToSession(it)
|
uploadMetadataToSession(it)
|
||||||
|
|
||||||
if (playbackManager.isRestored) {
|
|
||||||
notification.setMetadata(playbackManager.song!!, this) {
|
notification.setMetadata(playbackManager.song!!, this) {
|
||||||
startForegroundOrNotify("Song")
|
startForegroundOrNotify("Song")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
notification.setMetadata(playbackManager.song!!, this) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -285,6 +283,12 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
player.seekTo(position)
|
player.seekTo(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRestoreFinish() {
|
||||||
|
Log.d(this::class.simpleName, "Restore done")
|
||||||
|
|
||||||
|
restorePlayer()
|
||||||
|
}
|
||||||
|
|
||||||
// --- OTHER FUNCTIONS ---
|
// --- OTHER FUNCTIONS ---
|
||||||
|
|
||||||
private fun restorePlayer() {
|
private fun restorePlayer() {
|
||||||
|
@ -321,12 +325,6 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreFinish() {
|
|
||||||
Log.d(this::class.simpleName, "Restore done")
|
|
||||||
|
|
||||||
restorePlayer()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun uploadMetadataToSession(song: Song) {
|
private fun uploadMetadataToSession(song: Song) {
|
||||||
val builder = MediaMetadataCompat.Builder()
|
val builder = MediaMetadataCompat.Builder()
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.name)
|
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.name)
|
||||||
|
@ -361,7 +359,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
|
|
||||||
private fun startForegroundOrNotify(reason: String) {
|
private fun startForegroundOrNotify(reason: String) {
|
||||||
// Start the service in the foreground if haven't already.
|
// Start the service in the foreground if haven't already.
|
||||||
if (playbackManager.isRestored) {
|
if (playbackManager.hasPlayed) {
|
||||||
Log.d(this::class.simpleName, "Starting foreground/notifying because of $reason")
|
Log.d(this::class.simpleName, "Starting foreground/notifying because of $reason")
|
||||||
|
|
||||||
if (!isForeground) {
|
if (!isForeground) {
|
||||||
|
|
|
@ -84,6 +84,7 @@ class PlaybackStateManager private constructor() {
|
||||||
}
|
}
|
||||||
private var mIsInUserQueue = false
|
private var mIsInUserQueue = false
|
||||||
private var mIsRestored = false
|
private var mIsRestored = false
|
||||||
|
private var mHasPlayed = false
|
||||||
private var mShuffleSeed = -1L
|
private var mShuffleSeed = -1L
|
||||||
|
|
||||||
val song: Song? get() = mSong
|
val song: Song? get() = mSong
|
||||||
|
@ -97,6 +98,7 @@ class PlaybackStateManager private constructor() {
|
||||||
val isShuffling: Boolean get() = mIsShuffling
|
val isShuffling: Boolean get() = mIsShuffling
|
||||||
val loopMode: LoopMode get() = mLoopMode
|
val loopMode: LoopMode get() = mLoopMode
|
||||||
val isRestored: Boolean get() = mIsRestored
|
val isRestored: Boolean get() = mIsRestored
|
||||||
|
val hasPlayed: Boolean get() = mHasPlayed
|
||||||
|
|
||||||
// --- CALLBACKS ---
|
// --- CALLBACKS ---
|
||||||
|
|
||||||
|
@ -210,7 +212,7 @@ class PlaybackStateManager private constructor() {
|
||||||
mPosition = 0
|
mPosition = 0
|
||||||
|
|
||||||
if (!mIsPlaying) {
|
if (!mIsPlaying) {
|
||||||
mIsPlaying = true
|
setPlayingStatus(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsInUserQueue = false
|
mIsInUserQueue = false
|
||||||
|
@ -405,6 +407,10 @@ class PlaybackStateManager private constructor() {
|
||||||
|
|
||||||
fun setPlayingStatus(value: Boolean) {
|
fun setPlayingStatus(value: Boolean) {
|
||||||
if (mIsPlaying != value) {
|
if (mIsPlaying != value) {
|
||||||
|
if (value) {
|
||||||
|
mHasPlayed = true
|
||||||
|
}
|
||||||
|
|
||||||
mIsPlaying = value
|
mIsPlaying = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,6 +429,10 @@ class PlaybackStateManager private constructor() {
|
||||||
mLoopMode = mode
|
mLoopMode = mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetHasPlayedStatus() {
|
||||||
|
mHasPlayed = false
|
||||||
|
}
|
||||||
|
|
||||||
private fun resetLoopMode() {
|
private fun resetLoopMode() {
|
||||||
// Reset the loop mode from ONCE if needed.
|
// Reset the loop mode from ONCE if needed.
|
||||||
if (mLoopMode == LoopMode.ONCE) {
|
if (mLoopMode == LoopMode.ONCE) {
|
||||||
|
|
Loading…
Reference in a new issue