#1618 Handle multi window mode lifecycle.

This commit is contained in:
sictiru 2022-02-13 22:22:20 -08:00
parent 9b85bc3a93
commit 18361d682c
3 changed files with 21 additions and 4 deletions

View file

@ -27,7 +27,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
dependencies {
implementation 'androidx.fragment:fragment-ktx:1.4.0'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
@ -40,7 +40,7 @@ dependencies {
implementation "androidx.browser:browser:1.4.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation 'androidx.lifecycle:lifecycle-process:2.4.0'
implementation 'androidx.core:core-splashscreen:1.0.0-alpha02'
implementation 'androidx.core:core-splashscreen:1.0.0-beta01'
}
android {

View file

@ -18,7 +18,7 @@ class InitActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen().also {
it.setKeepVisibleCondition {
it.setKeepOnScreenCondition() {
// keep showing the splash screen until FeedUtils.offerInitContext(...)
// finishes and UI ready to display
FeedUtils.dbHelper != null || FeedUtils.thumbnailLoader != null

View file

@ -59,6 +59,14 @@ abstract class Reading : NbActivity(), OnPageChangeListener, OnSeekBarChangeList
private var overlayRangeBotPx = 0f
private var lastVScrollPos = 0
// enabling multi window mode from recent apps on the device
// creates a different activity lifecycle compared to a device rotation
// resulting in onPause being called when the app is actually on the screen.
// calling onPause sets stopLoading as true and content wouldn't be loaded.
// track the multi window mode config change and skip stopLoading in first onPause call.
// refactor stopLoading mechanism as a cancellation signal tied to the view lifecycle.
private var isMultiWindowModeHack = false
private val pageHistory = mutableListOf<Story>()
private lateinit var volumeKeyNavigation: VolumeKeyNavigation
@ -143,8 +151,17 @@ abstract class Reading : NbActivity(), OnPageChangeListener, OnSeekBarChangeList
}
override fun onPause() {
stopLoading = true
super.onPause()
if (isMultiWindowModeHack) {
isMultiWindowModeHack = false
} else {
stopLoading = true
}
}
override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) {
super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig)
isMultiWindowModeHack = isInMultiWindowMode
}
private fun setupViews() {