Handle intent after navigator is initialized
Fixes crash if opening from widget or notification when activity isn't already launched.
This commit is contained in:
parent
a8c732d67b
commit
09cebf20f3
1 changed files with 19 additions and 20 deletions
|
@ -86,8 +86,6 @@ class MainActivity : BaseActivity() {
|
||||||
private val uiPreferences: UiPreferences by injectLazy()
|
private val uiPreferences: UiPreferences by injectLazy()
|
||||||
private val preferences: BasePreferences by injectLazy()
|
private val preferences: BasePreferences by injectLazy()
|
||||||
|
|
||||||
private var isHandlingShortcut: Boolean = false
|
|
||||||
|
|
||||||
private val chapterCache: ChapterCache by injectLazy()
|
private val chapterCache: ChapterCache by injectLazy()
|
||||||
|
|
||||||
// To be checked by splash screen. If true then splash screen will be removed.
|
// To be checked by splash screen. If true then splash screen will be removed.
|
||||||
|
@ -98,9 +96,16 @@ class MainActivity : BaseActivity() {
|
||||||
*/
|
*/
|
||||||
private var settingsSheet: LibrarySettingsSheet? = null
|
private var settingsSheet: LibrarySettingsSheet? = null
|
||||||
|
|
||||||
|
private var isHandlingShortcut: Boolean = false
|
||||||
private lateinit var navigator: Navigator
|
private lateinit var navigator: Navigator
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
// Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079
|
||||||
|
if (!isTaskRoot) {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Prevent splash screen showing up on configuration changes
|
// Prevent splash screen showing up on configuration changes
|
||||||
val splashScreen = if (savedInstanceState == null) installSplashScreen() else null
|
val splashScreen = if (savedInstanceState == null) installSplashScreen() else null
|
||||||
|
|
||||||
|
@ -128,12 +133,6 @@ class MainActivity : BaseActivity() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079
|
|
||||||
if (!isTaskRoot) {
|
|
||||||
finish()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw edge-to-edge
|
// Draw edge-to-edge
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
|
@ -151,6 +150,18 @@ class MainActivity : BaseActivity() {
|
||||||
ConfirmExit()
|
ConfirmExit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(navigator) {
|
||||||
|
this@MainActivity.navigator = navigator
|
||||||
|
|
||||||
|
if (savedInstanceState == null) {
|
||||||
|
// Set start screen
|
||||||
|
handleIntentAction(intent)
|
||||||
|
|
||||||
|
// Reset Incognito Mode on relaunch
|
||||||
|
preferences.incognitoMode().set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Shows current screen
|
// Shows current screen
|
||||||
ScreenTransition(navigator = navigator, transition = { Transition.OneWayFade })
|
ScreenTransition(navigator = navigator, transition = { Transition.OneWayFade })
|
||||||
|
|
||||||
|
@ -171,10 +182,6 @@ class MainActivity : BaseActivity() {
|
||||||
.launchIn(this)
|
.launchIn(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(navigator) {
|
|
||||||
this@MainActivity.navigator = navigator
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckForUpdate()
|
CheckForUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,14 +210,6 @@ class MainActivity : BaseActivity() {
|
||||||
elapsed <= SPLASH_MIN_DURATION || (!ready && elapsed <= SPLASH_MAX_DURATION)
|
elapsed <= SPLASH_MIN_DURATION || (!ready && elapsed <= SPLASH_MAX_DURATION)
|
||||||
}
|
}
|
||||||
setSplashScreenExitAnimation(splashScreen)
|
setSplashScreenExitAnimation(splashScreen)
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
// Set start screen
|
|
||||||
lifecycleScope.launch { handleIntentAction(intent) }
|
|
||||||
|
|
||||||
// Reset Incognito Mode on relaunch
|
|
||||||
preferences.incognitoMode().set(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSettingsSheet(category: Category? = null) {
|
private fun showSettingsSheet(category: Category? = null) {
|
||||||
|
|
Reference in a new issue