Shutdown service on exit button press

This commit is contained in:
tzugen 2022-05-31 10:27:29 +02:00
parent 53ae0cd232
commit 5e0dd14c4f
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
4 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/* /*
* NavigationActivity.kt * NavigationActivity.kt
* Copyright (C) 2009-2021 Ultrasonic developers * Copyright (C) 2009-2022 Ultrasonic developers
* *
* Distributed under terms of the GNU GPLv3 license. * 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.button.MaterialButton
import com.google.android.material.navigation.NavigationView import com.google.android.material.navigation.NavigationView
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import kotlin.system.exitProcess
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.androidx.viewmodel.ext.android.viewModel
import org.moire.ultrasonic.R import org.moire.ultrasonic.R
@ -66,7 +67,7 @@ import org.moire.ultrasonic.util.Util
import timber.log.Timber 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") @Suppress("TooManyFunctions")
class NavigationActivity : AppCompatActivity() { class NavigationActivity : AppCompatActivity() {
@ -366,7 +367,8 @@ class NavigationActivity : AppCompatActivity() {
private fun exit() { private fun exit() {
lifecycleSupport.onDestroy() lifecycleSupport.onDestroy()
finish() finishAndRemoveTask()
exitProcess(0)
} }
private fun showWelcomeDialog() { private fun showWelcomeDialog() {

View File

@ -143,6 +143,12 @@ class PlaybackService : MediaLibraryService(), KoinComponent {
player.setWakeMode(getWakeModeFlag()) player.setWakeMode(getWakeModeFlag())
} }
// Listen to the shutdown command
rxBusSubscription += RxBus.shutdownCommandObservable.subscribe {
Timber.i("Received destroy command via Rx")
onDestroy()
}
isStarted = true isStarted = true
} }

View File

@ -82,6 +82,8 @@ class MediaPlayerLifecycleSupport : KoinComponent {
) )
mediaPlayerController.clear(false) mediaPlayerController.clear(false)
RxBus.shutdownCommandPublisher.onNext(Unit)
applicationContext().unregisterReceiver(headsetEventReceiver) applicationContext().unregisterReceiver(headsetEventReceiver)
mediaPlayerController.onDestroy() mediaPlayerController.onDestroy()

View File

@ -58,6 +58,11 @@ class RxBus {
PublishSubject.create() PublishSubject.create()
val dismissNowPlayingCommandObservable: Observable<Unit> = val dismissNowPlayingCommandObservable: Observable<Unit> =
dismissNowPlayingCommandPublisher.observeOn(mainThread()) dismissNowPlayingCommandPublisher.observeOn(mainThread())
val shutdownCommandPublisher: PublishSubject<Unit> =
PublishSubject.create()
val shutdownCommandObservable: Observable<Unit> =
shutdownCommandPublisher.observeOn(mainThread())
} }
data class StateWithTrack( data class StateWithTrack(