diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt index bcd991ff..e243e704 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt @@ -1,6 +1,6 @@ /* * NavigationActivity.kt - * Copyright (C) 2009-2021 Ultrasonic developers + * Copyright (C) 2009-2022 Ultrasonic developers * * Distributed under terms of the GNU GPLv3 license. */ @@ -42,6 +42,7 @@ import androidx.preference.PreferenceManager import com.google.android.material.button.MaterialButton import com.google.android.material.navigation.NavigationView import io.reactivex.rxjava3.disposables.CompositeDisposable +import kotlin.system.exitProcess import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel import org.moire.ultrasonic.R @@ -66,7 +67,7 @@ import org.moire.ultrasonic.util.Util import timber.log.Timber /** - * The main Activity of Ultrasonic which loads all other screens as Fragments + * The main (and only) Activity of Ultrasonic which loads all other screens as Fragments */ @Suppress("TooManyFunctions") class NavigationActivity : AppCompatActivity() { @@ -366,7 +367,8 @@ class NavigationActivity : AppCompatActivity() { private fun exit() { lifecycleSupport.onDestroy() - finish() + finishAndRemoveTask() + exitProcess(0) } private fun showWelcomeDialog() { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt index ea65a16f..6f40a6df 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/playback/PlaybackService.kt @@ -143,6 +143,12 @@ class PlaybackService : MediaLibraryService(), KoinComponent { player.setWakeMode(getWakeModeFlag()) } + // Listen to the shutdown command + rxBusSubscription += RxBus.shutdownCommandObservable.subscribe { + Timber.i("Received destroy command via Rx") + onDestroy() + } + isStarted = true } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt index 68701102..2700747b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt @@ -82,6 +82,8 @@ class MediaPlayerLifecycleSupport : KoinComponent { ) mediaPlayerController.clear(false) + RxBus.shutdownCommandPublisher.onNext(Unit) + applicationContext().unregisterReceiver(headsetEventReceiver) mediaPlayerController.onDestroy() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt index 03859659..4bfdcdab 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt @@ -58,6 +58,11 @@ class RxBus { PublishSubject.create() val dismissNowPlayingCommandObservable: Observable = dismissNowPlayingCommandPublisher.observeOn(mainThread()) + + val shutdownCommandPublisher: PublishSubject = + PublishSubject.create() + val shutdownCommandObservable: Observable = + shutdownCommandPublisher.observeOn(mainThread()) } data class StateWithTrack(