properly update the widget song info and state at initialization
This commit is contained in:
parent
46010a5eeb
commit
1a8ca23148
2 changed files with 16 additions and 5 deletions
|
@ -17,6 +17,7 @@ import com.simplemobiletools.musicplayer.extensions.getSharedPrefs
|
|||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
import com.simplemobiletools.musicplayer.models.Song
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import com.squareup.otto.Bus
|
||||
import com.squareup.otto.Subscribe
|
||||
|
||||
|
@ -63,6 +64,8 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||
mBus = BusProvider.instance
|
||||
}
|
||||
registerBus()
|
||||
updateSong(MusicService.mCurrSong)
|
||||
updateSongState(MusicService.getIsPlaying())
|
||||
}
|
||||
|
||||
private fun setupIntent(action: String, id: Int) {
|
||||
|
@ -84,7 +87,11 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||
|
||||
@Subscribe
|
||||
fun songChangedEvent(event: Events.SongChanged) {
|
||||
mCurrSong = event.song
|
||||
updateSong(event.song)
|
||||
}
|
||||
|
||||
private fun updateSong(song: Song?) {
|
||||
mCurrSong = song
|
||||
updateSongInfo()
|
||||
updateWidgets()
|
||||
}
|
||||
|
@ -103,10 +110,14 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||
|
||||
@Subscribe
|
||||
fun songStateChanged(event: Events.SongStateChanged) {
|
||||
if (mIsPlaying == event.isPlaying)
|
||||
updateSongState(event.isPlaying)
|
||||
}
|
||||
|
||||
private fun updateSongState(isPlaying: Boolean) {
|
||||
if (mIsPlaying == isPlaying)
|
||||
return
|
||||
|
||||
mIsPlaying = event.isPlaying
|
||||
mIsPlaying = isPlaying
|
||||
updatePlayPauseButton()
|
||||
updateWidgets()
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
private var mPlayPauseIntent: PendingIntent? = null
|
||||
|
||||
private var mWasPlayingAtCall = false
|
||||
|
||||
fun getIsPlaying() = mPlayer?.isPlaying == true
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
|
@ -319,8 +321,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
}
|
||||
|
||||
fun getIsPlaying() = mPlayer?.isPlaying == true
|
||||
|
||||
fun playPreviousSong() {
|
||||
if (mSongs!!.isEmpty())
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue