mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-04 19:17:30 +01:00
Don't ecit the process, and reinit Koin on resume
This commit is contained in:
parent
5e0dd14c4f
commit
1e571e165c
@ -42,10 +42,10 @@ 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
|
||||
import org.moire.ultrasonic.app.UApp
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.data.ServerSettingDao
|
||||
import org.moire.ultrasonic.fragment.OnBackPressedHandler
|
||||
@ -99,6 +99,17 @@ class NavigationActivity : AppCompatActivity() {
|
||||
private var cachedServerCount: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
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()
|
||||
} else {
|
||||
Timber.d("No need to start Koin")
|
||||
}
|
||||
|
||||
setUncaughtExceptionHandler()
|
||||
Util.applyTheme(this)
|
||||
|
||||
@ -226,6 +237,7 @@ class NavigationActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
Timber.d("onResume called")
|
||||
super.onResume()
|
||||
|
||||
Storage.reset()
|
||||
@ -239,9 +251,11 @@ class NavigationActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
Timber.d("onDestroy called")
|
||||
rxBusSubscription.dispose()
|
||||
imageLoaderProvider.clearImageLoader()
|
||||
UApp.instance!!.shutdownKoin()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
@ -366,9 +380,9 @@ class NavigationActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun exit() {
|
||||
Timber.d("User choose to exit the app")
|
||||
lifecycleSupport.onDestroy()
|
||||
finishAndRemoveTask()
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
private fun showWelcomeDialog() {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package org.moire.ultrasonic.app
|
||||
|
||||
import android.content.Context
|
||||
import android.os.StrictMode
|
||||
import androidx.multidex.MultiDexApplication
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.core.context.startKoin
|
||||
import org.koin.core.context.stopKoin
|
||||
import org.koin.core.logger.Level
|
||||
import org.moire.ultrasonic.BuildConfig
|
||||
import org.moire.ultrasonic.di.appPermanentStorage
|
||||
@ -31,17 +31,22 @@ class UApp : MultiDexApplication() {
|
||||
|
||||
init {
|
||||
instance = this
|
||||
if (BuildConfig.DEBUG)
|
||||
StrictMode.enableDefaults()
|
||||
// if (BuildConfig.DEBUG)
|
||||
// StrictMode.enableDefaults()
|
||||
}
|
||||
|
||||
var initiated = false
|
||||
|
||||
override fun onCreate() {
|
||||
initiated = true
|
||||
super.onCreate()
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
Timber.plant(DebugTree())
|
||||
}
|
||||
|
||||
Timber.d("onCreate called")
|
||||
|
||||
// In general we should not access the settings from the main thread to avoid blocking...
|
||||
ioScope.launch {
|
||||
if (Settings.debugLogToFile) {
|
||||
@ -49,8 +54,12 @@ class UApp : MultiDexApplication() {
|
||||
}
|
||||
}
|
||||
|
||||
startKoin()
|
||||
}
|
||||
|
||||
internal fun startKoin() {
|
||||
startKoin {
|
||||
// TODO Currently there is a bug in Koin which makes necessary to set the loglevel to ERROR
|
||||
// TODO Currently there is a bug in Koin which makes necessary to set the log level to ERROR
|
||||
logger(TimberKoinLogger(Level.ERROR))
|
||||
// logger(TimberKoinLogger(Level.INFO))
|
||||
|
||||
@ -67,8 +76,13 @@ class UApp : MultiDexApplication() {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun shutdownKoin() {
|
||||
stopKoin()
|
||||
initiated = false
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var instance: UApp? = null
|
||||
var instance: UApp? = null
|
||||
|
||||
fun applicationContext(): Context {
|
||||
return instance!!.applicationContext
|
||||
|
@ -66,6 +66,7 @@ class Downloader(
|
||||
private val rxBusSubscription: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
init {
|
||||
Timber.i("Init called")
|
||||
// Check downloads if the playlist changed
|
||||
rxBusSubscription += RxBus.playlistObservable.subscribe {
|
||||
Timber.v("Playlist has changed, checking Downloads...")
|
||||
|
@ -76,6 +76,8 @@ class MediaPlayerController(
|
||||
|
||||
var controller: MediaController? = null
|
||||
|
||||
private lateinit var listeners: Player.Listener
|
||||
|
||||
fun onCreate(onCreated: () -> Unit) {
|
||||
if (created) return
|
||||
externalStorageMonitor.onCreate { reset() }
|
||||
@ -86,7 +88,7 @@ class MediaPlayerController(
|
||||
|
||||
Timber.i("MediaController Instance received")
|
||||
|
||||
controller?.addListener(object : Player.Listener {
|
||||
listeners = object : Player.Listener {
|
||||
|
||||
/*
|
||||
* Log all events
|
||||
@ -134,7 +136,9 @@ class MediaPlayerController(
|
||||
playerStateChangedHandler()
|
||||
publishPlaybackState()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
controller?.addListener(listeners)
|
||||
|
||||
onCreated()
|
||||
|
||||
@ -224,6 +228,12 @@ class MediaPlayerController(
|
||||
|
||||
fun onDestroy() {
|
||||
if (!created) return
|
||||
|
||||
// First stop listening to events
|
||||
rxBusSubscription.dispose()
|
||||
controller?.removeListener(listeners)
|
||||
|
||||
// Shutdown the rest
|
||||
val context = UApp.applicationContext()
|
||||
externalStorageMonitor.onDestroy()
|
||||
context.stopService(Intent(context, DownloadService::class.java))
|
||||
@ -457,6 +467,9 @@ class MediaPlayerController(
|
||||
|
||||
@Synchronized
|
||||
private fun serializeCurrentSession() {
|
||||
// Don't serialize invalid sessions
|
||||
if (currentMediaItemIndex == -1) return
|
||||
|
||||
playbackStateSerializer.serialize(
|
||||
legacyPlaylistManager.playlist,
|
||||
currentMediaItemIndex,
|
||||
|
Loading…
x
Reference in New Issue
Block a user