fix: 使用 savedInstanceState 判断默认阅读首启逻辑
This commit is contained in:
@@ -66,8 +66,6 @@ import kotlin.coroutines.suspendCoroutine
|
|||||||
open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var isFirstLaunch = true
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
var hasActiveReadBookRoute: Boolean = false
|
var hasActiveReadBookRoute: Boolean = false
|
||||||
|
|
||||||
@@ -143,9 +141,11 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
|||||||
private val viewModel by viewModel<MainViewModel>()
|
private val viewModel by viewModel<MainViewModel>()
|
||||||
private val routeEvents = MutableSharedFlow<NavKey>(extraBufferCapacity = 1)
|
private val routeEvents = MutableSharedFlow<NavKey>(extraBufferCapacity = 1)
|
||||||
private var bookInfoVariableSetter: ((String, String?) -> Unit)? = null
|
private var bookInfoVariableSetter: ((String, String?) -> Unit)? = null
|
||||||
|
private var shouldApplyDefaultToRead = true
|
||||||
internal var activeReadBookInputHandler: ReadBookInputHandler? = null
|
internal var activeReadBookInputHandler: ReadBookInputHandler? = null
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
installSplashScreen()
|
installSplashScreen()
|
||||||
|
shouldApplyDefaultToRead = savedInstanceState == null
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
if (checkStartupRoute()) return
|
if (checkStartupRoute()) return
|
||||||
@@ -193,14 +193,13 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val startRoutes = remember {
|
val startRoutes = remember {
|
||||||
val resolved = MainNavigator.resolveStartRoute(intent)
|
val routes = resolveInitialStartRoutes(
|
||||||
if (isFirstLaunch && OtherConfig.defaultToRead && resolved == MainRouteHome) {
|
resolved = MainNavigator.resolveStartRoute(intent),
|
||||||
isFirstLaunch = false
|
defaultToRead = OtherConfig.defaultToRead,
|
||||||
arrayOf(MainRouteHome, MainRouteReadBook())
|
isFreshCreate = shouldApplyDefaultToRead,
|
||||||
} else {
|
)
|
||||||
isFirstLaunch = false
|
shouldApplyDefaultToRead = false
|
||||||
arrayOf(resolved)
|
routes.toTypedArray()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val backStack = rememberNavBackStack(*startRoutes)
|
val backStack = rememberNavBackStack(*startRoutes)
|
||||||
|
|
||||||
@@ -422,9 +421,6 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
if (!isChangingConfigurations) {
|
|
||||||
isFirstLaunch = true
|
|
||||||
}
|
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
BookHelp.clearInvalidCache()
|
BookHelp.clearInvalidCache()
|
||||||
}
|
}
|
||||||
@@ -439,6 +435,18 @@ open class MainActivity : BaseComposeActivity(), VariableDialog.Callback {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun resolveInitialStartRoutes(
|
||||||
|
resolved: NavKey,
|
||||||
|
defaultToRead: Boolean,
|
||||||
|
isFreshCreate: Boolean,
|
||||||
|
): List<NavKey> {
|
||||||
|
return if (isFreshCreate && defaultToRead && resolved == MainRouteHome) {
|
||||||
|
listOf(MainRouteHome, MainRouteReadBook())
|
||||||
|
} else {
|
||||||
|
listOf(resolved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class LauncherW : MainActivity()
|
class LauncherW : MainActivity()
|
||||||
class Launcher1 : MainActivity()
|
class Launcher1 : MainActivity()
|
||||||
class Launcher2 : MainActivity()
|
class Launcher2 : MainActivity()
|
||||||
|
|||||||
Reference in New Issue
Block a user