Shutdown service on exit button press
This commit is contained in:
parent
53ae0cd232
commit
5e0dd14c4f
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||
)
|
||||
|
||||
mediaPlayerController.clear(false)
|
||||
RxBus.shutdownCommandPublisher.onNext(Unit)
|
||||
|
||||
applicationContext().unregisterReceiver(headsetEventReceiver)
|
||||
mediaPlayerController.onDestroy()
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ class RxBus {
|
|||
PublishSubject.create()
|
||||
val dismissNowPlayingCommandObservable: Observable<Unit> =
|
||||
dismissNowPlayingCommandPublisher.observeOn(mainThread())
|
||||
|
||||
val shutdownCommandPublisher: PublishSubject<Unit> =
|
||||
PublishSubject.create()
|
||||
val shutdownCommandObservable: Observable<Unit> =
|
||||
shutdownCommandPublisher.observeOn(mainThread())
|
||||
}
|
||||
|
||||
data class StateWithTrack(
|
||||
|
|
Loading…
Reference in New Issue