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