Clear widget when service is being shutdown

This commit is contained in:
tzugen 2022-06-08 09:17:14 +02:00
parent 70f8b75019
commit 87c160610f
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
5 changed files with 15 additions and 1 deletions

View File

@ -102,7 +102,6 @@ class NavigationActivity : AppCompatActivity() {
Timber.d("onCreate called")
// First check if Koin has been started
if (UApp.instance != null && !UApp.instance!!.initiated) {
Timber.d("Starting Koin")
UApp.instance!!.startKoin()

View File

@ -87,6 +87,9 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
}
private fun releasePlayerAndSession() {
// Broadcast that the service is being shutdown
RxBus.stopCommandPublisher.onNext(Unit)
player.release()
mediaLibrarySession.release()
rxBusSubscription.dispose()

View File

@ -97,6 +97,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() {
playing: Boolean,
setAlbum: Boolean
) {
Timber.d("Updating Widget")
val res = context.resources
val views = RemoteViews(context.packageName, layoutId)
val title = currentSong?.title

View File

@ -166,6 +166,11 @@ class MediaPlayerController(
}
}
rxBusSubscription += RxBus.stopCommandObservable.subscribe {
// Clear the widget when we stop the service
updateWidget(null)
}
created = true
Timber.i("MediaPlayerController started")
}

View File

@ -63,6 +63,12 @@ class RxBus {
PublishSubject.create()
val shutdownCommandObservable: Observable<Unit> =
shutdownCommandPublisher.observeOn(mainThread())
val stopCommandPublisher: PublishSubject<Unit> =
PublishSubject.create()
val stopCommandObservable: Observable<Unit> =
stopCommandPublisher.observeOn(mainThread())
}
data class StateWithTrack(