|
|
|
@ -3,6 +3,7 @@ package org.koitharu.kotatsu.reader.ui
|
|
|
|
import android.app.assist.AssistContent
|
|
|
|
import android.app.assist.AssistContent
|
|
|
|
import android.content.DialogInterface
|
|
|
|
import android.content.DialogInterface
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.Gravity
|
|
|
|
import android.view.Gravity
|
|
|
|
import android.view.KeyEvent
|
|
|
|
import android.view.KeyEvent
|
|
|
|
@ -26,17 +27,16 @@ import androidx.transition.TransitionManager
|
|
|
|
import androidx.transition.TransitionSet
|
|
|
|
import androidx.transition.TransitionSet
|
|
|
|
import androidx.window.layout.FoldingFeature
|
|
|
|
import androidx.window.layout.FoldingFeature
|
|
|
|
import androidx.window.layout.WindowInfoTracker
|
|
|
|
import androidx.window.layout.WindowInfoTracker
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
|
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
|
|
import kotlinx.coroutines.flow.flowOn
|
|
|
|
import kotlinx.coroutines.flow.flowOn
|
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
@ -114,6 +114,7 @@ class ReaderActivity :
|
|
|
|
private var gestureInsets: Insets = Insets.NONE
|
|
|
|
private var gestureInsets: Insets = Insets.NONE
|
|
|
|
private lateinit var readerManager: ReaderManager
|
|
|
|
private lateinit var readerManager: ReaderManager
|
|
|
|
private val hideUiRunnable = Runnable { setUiIsVisible(false) }
|
|
|
|
private val hideUiRunnable = Runnable { setUiIsVisible(false) }
|
|
|
|
|
|
|
|
|
|
|
|
// Tracks whether the foldable device is in an unfolded state (half-opened or flat)
|
|
|
|
// Tracks whether the foldable device is in an unfolded state (half-opened or flat)
|
|
|
|
private var isFoldUnfolded: Boolean = false
|
|
|
|
private var isFoldUnfolded: Boolean = false
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,21 +196,7 @@ class ReaderActivity :
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addMenuProvider(ReaderMenuProvider(viewModel))
|
|
|
|
addMenuProvider(ReaderMenuProvider(viewModel))
|
|
|
|
|
|
|
|
|
|
|
|
// Observe foldable window layout to auto-enable double-page if configured
|
|
|
|
observeWindowLayout()
|
|
|
|
WindowInfoTracker.getOrCreate(this)
|
|
|
|
|
|
|
|
.windowLayoutInfo(this)
|
|
|
|
|
|
|
|
.onEach { info ->
|
|
|
|
|
|
|
|
val fold = info.displayFeatures.filterIsInstance<FoldingFeature>().firstOrNull()
|
|
|
|
|
|
|
|
val unfolded = when (fold?.state) {
|
|
|
|
|
|
|
|
FoldingFeature.State.HALF_OPENED, FoldingFeature.State.FLAT -> true
|
|
|
|
|
|
|
|
else -> false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unfolded != isFoldUnfolded) {
|
|
|
|
|
|
|
|
isFoldUnfolded = unfolded
|
|
|
|
|
|
|
|
applyDoubleModeAuto()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.launchIn(lifecycleScope)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply initial double-mode considering foldable setting
|
|
|
|
// Apply initial double-mode considering foldable setting
|
|
|
|
applyDoubleModeAuto()
|
|
|
|
applyDoubleModeAuto()
|
|
|
|
@ -557,6 +544,24 @@ class ReaderActivity :
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Observe foldable window layout to auto-enable double-page if configured
|
|
|
|
|
|
|
|
private fun observeWindowLayout() {
|
|
|
|
|
|
|
|
WindowInfoTracker.getOrCreate(this)
|
|
|
|
|
|
|
|
.windowLayoutInfo(this)
|
|
|
|
|
|
|
|
.onEach { info ->
|
|
|
|
|
|
|
|
val fold = info.displayFeatures.filterIsInstance<FoldingFeature>().firstOrNull()
|
|
|
|
|
|
|
|
val unfolded = when (fold?.state) {
|
|
|
|
|
|
|
|
FoldingFeature.State.HALF_OPENED, FoldingFeature.State.FLAT -> true
|
|
|
|
|
|
|
|
else -> false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unfolded != isFoldUnfolded) {
|
|
|
|
|
|
|
|
isFoldUnfolded = unfolded
|
|
|
|
|
|
|
|
applyDoubleModeAuto()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.launchIn(lifecycleScope)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun askForIncognitoMode() {
|
|
|
|
private fun askForIncognitoMode() {
|
|
|
|
buildAlertDialog(this, isCentered = true) {
|
|
|
|
buildAlertDialog(this, isCentered = true) {
|
|
|
|
var dontAskAgain = false
|
|
|
|
var dontAskAgain = false
|
|
|
|
|