|
|
|
|
@ -24,10 +24,15 @@ import androidx.transition.Fade
|
|
|
|
|
import androidx.transition.Slide
|
|
|
|
|
import androidx.transition.TransitionManager
|
|
|
|
|
import androidx.transition.TransitionSet
|
|
|
|
|
import androidx.window.layout.FoldingFeature
|
|
|
|
|
import androidx.window.layout.WindowInfoTracker
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
|
|
import kotlinx.coroutines.flow.combine
|
|
|
|
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
|
|
|
import kotlinx.coroutines.flow.flowOn
|
|
|
|
|
@ -109,6 +114,8 @@ class ReaderActivity :
|
|
|
|
|
private var gestureInsets: Insets = Insets.NONE
|
|
|
|
|
private lateinit var readerManager: ReaderManager
|
|
|
|
|
private val hideUiRunnable = Runnable { setUiIsVisible(false) }
|
|
|
|
|
// Tracks whether the foldable device is in an unfolded state (half-opened or flat)
|
|
|
|
|
private var isFoldUnfolded: Boolean = false
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
@ -187,6 +194,25 @@ class ReaderActivity :
|
|
|
|
|
viewBinding.zoomControl.isVisible = it
|
|
|
|
|
}
|
|
|
|
|
addMenuProvider(ReaderMenuProvider(viewModel))
|
|
|
|
|
|
|
|
|
|
// Observe foldable window layout to auto-enable double-page if configured
|
|
|
|
|
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
|
|
|
|
|
applyDoubleModeAuto()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun getParentActivityIntent(): Intent? {
|
|
|
|
|
@ -341,7 +367,17 @@ class ReaderActivity :
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDoubleModeChanged(isEnabled: Boolean) {
|
|
|
|
|
readerManager.setDoubleReaderMode(isEnabled)
|
|
|
|
|
// Combine manual toggle with foldable auto setting
|
|
|
|
|
applyDoubleModeAuto(isEnabled)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun applyDoubleModeAuto(manualEnabled: Boolean? = null) {
|
|
|
|
|
val isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
|
|
|
|
// Auto double-page on foldable when device is unfolded (half-opened or flat)
|
|
|
|
|
val autoFoldable = settings.isReaderDoubleOnFoldable && isFoldUnfolded
|
|
|
|
|
val manualLandscape = (manualEnabled ?: settings.isReaderDoubleOnLandscape) && isLandscape
|
|
|
|
|
val autoEnabled = autoFoldable || manualLandscape
|
|
|
|
|
readerManager.setDoubleReaderMode(autoEnabled)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun setKeepScreenOn(isKeep: Boolean) {
|
|
|
|
|
|