mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 08:17:49 +01:00
Remove usage of savedInstanceState for storing reader menu visibility state
This commit is contained in:
parent
20faaaa908
commit
bb8f3c63f1
4 changed files with 27 additions and 33 deletions
|
@ -99,7 +99,8 @@ import tachiyomi.core.util.lang.launchNonCancellable
|
|||
import tachiyomi.core.util.lang.withUIContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import kotlin.math.abs
|
||||
|
||||
class ReaderActivity : BaseActivity() {
|
||||
|
@ -114,8 +115,8 @@ class ReaderActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private val readerPreferences: ReaderPreferences by injectLazy()
|
||||
private val preferences: BasePreferences by injectLazy()
|
||||
private val readerPreferences = Injekt.get<ReaderPreferences>()
|
||||
private val preferences = Injekt.get<BasePreferences>()
|
||||
|
||||
lateinit var binding: ReaderActivityBinding
|
||||
|
||||
|
@ -124,19 +125,12 @@ class ReaderActivity : BaseActivity() {
|
|||
|
||||
val hasCutout by lazy { hasDisplayCutout() }
|
||||
|
||||
/**
|
||||
* Whether the menu is currently visible.
|
||||
*/
|
||||
var menuVisible = false
|
||||
private set
|
||||
|
||||
/**
|
||||
* Configuration at reader level, like background color or forced orientation.
|
||||
*/
|
||||
private var config: ReaderConfig? = null
|
||||
|
||||
private var menuToggleToast: Toast? = null
|
||||
|
||||
private var readingModeToast: Toast? = null
|
||||
|
||||
private val windowInsetsController by lazy { WindowInsetsControllerCompat(window, binding.root) }
|
||||
|
@ -159,8 +153,8 @@ class ReaderActivity : BaseActivity() {
|
|||
setContentView(binding.root)
|
||||
|
||||
if (viewModel.needsInit()) {
|
||||
val manga = intent.extras!!.getLong("manga", -1)
|
||||
val chapter = intent.extras!!.getLong("chapter", -1)
|
||||
val manga = intent.extras?.getLong("manga", -1) ?: -1L
|
||||
val chapter = intent.extras?.getLong("chapter", -1) ?: -1L
|
||||
if (manga == -1L || chapter == -1L) {
|
||||
finish()
|
||||
return
|
||||
|
@ -178,10 +172,6 @@ class ReaderActivity : BaseActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
menuVisible = savedInstanceState.getBoolean(::menuVisible.name)
|
||||
}
|
||||
|
||||
config = ReaderConfig()
|
||||
initializeMenu()
|
||||
|
||||
|
@ -250,7 +240,6 @@ class ReaderActivity : BaseActivity() {
|
|||
* activity isn't changing configurations.
|
||||
*/
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
outState.putBoolean(::menuVisible.name, menuVisible)
|
||||
viewModel.onSaveInstanceState()
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
@ -267,7 +256,7 @@ class ReaderActivity : BaseActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
viewModel.setReadStartTime()
|
||||
setMenuVisibility(menuVisible, animate = false)
|
||||
setMenuVisibility(viewModel.state.value.menuVisible, animate = false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -277,7 +266,7 @@ class ReaderActivity : BaseActivity() {
|
|||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
setMenuVisibility(menuVisible, animate = false)
|
||||
setMenuVisibility(viewModel.state.value.menuVisible, animate = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +402,7 @@ class ReaderActivity : BaseActivity() {
|
|||
when (state.dialog) {
|
||||
is ReaderViewModel.Dialog.Loading -> {
|
||||
AlertDialog(
|
||||
onDismissRequest = { /* Non dismissible */ },
|
||||
onDismissRequest = {},
|
||||
confirmButton = {},
|
||||
text = {
|
||||
Row(
|
||||
|
@ -488,7 +477,7 @@ class ReaderActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
// Set initial visibility
|
||||
setMenuVisibility(menuVisible)
|
||||
setMenuVisibility(viewModel.state.value.menuVisible)
|
||||
}
|
||||
|
||||
private fun initBottomShortcuts() {
|
||||
|
@ -614,7 +603,7 @@ class ReaderActivity : BaseActivity() {
|
|||
* [animate] the views.
|
||||
*/
|
||||
fun setMenuVisibility(visible: Boolean, animate: Boolean = true) {
|
||||
menuVisible = visible
|
||||
viewModel.showMenus(visible)
|
||||
if (visible) {
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||
binding.readerMenu.isVisible = true
|
||||
|
@ -844,14 +833,14 @@ class ReaderActivity : BaseActivity() {
|
|||
* viewer because each one implements its own touch and key events.
|
||||
*/
|
||||
fun toggleMenu() {
|
||||
setMenuVisibility(!menuVisible)
|
||||
setMenuVisibility(!viewModel.state.value.menuVisible)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the viewer to show the menu.
|
||||
*/
|
||||
fun showMenu() {
|
||||
if (!menuVisible) {
|
||||
if (!viewModel.state.value.menuVisible) {
|
||||
setMenuVisibility(true)
|
||||
}
|
||||
}
|
||||
|
@ -860,7 +849,7 @@ class ReaderActivity : BaseActivity() {
|
|||
* Called from the viewer to hide the menu.
|
||||
*/
|
||||
fun hideMenu() {
|
||||
if (menuVisible) {
|
||||
if (viewModel.state.value.menuVisible) {
|
||||
setMenuVisibility(false)
|
||||
}
|
||||
}
|
||||
|
@ -1058,7 +1047,7 @@ class ReaderActivity : BaseActivity() {
|
|||
}
|
||||
|
||||
// Trigger relayout
|
||||
setMenuVisibility(menuVisible)
|
||||
setMenuVisibility(viewModel.state.value.menuVisible)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -718,6 +718,10 @@ class ReaderViewModel(
|
|||
) + filenameSuffix
|
||||
}
|
||||
|
||||
fun showMenus(visible: Boolean) {
|
||||
mutableState.update { it.copy(menuVisible = visible) }
|
||||
}
|
||||
|
||||
fun showLoadingDialog() {
|
||||
mutableState.update { it.copy(dialog = Dialog.Loading) }
|
||||
}
|
||||
|
@ -926,6 +930,7 @@ class ReaderViewModel(
|
|||
*/
|
||||
val viewer: Viewer? = null,
|
||||
val dialog: Dialog? = null,
|
||||
val menuVisible: Boolean = false,
|
||||
) {
|
||||
val totalPages: Int
|
||||
get() = viewerChapters?.currChapter?.pages?.size ?: -1
|
||||
|
|
|
@ -112,7 +112,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : Viewer {
|
|||
}
|
||||
}
|
||||
pager.longTapListener = f@{
|
||||
if (activity.menuVisible || config.longTapEnabled) {
|
||||
if (activity.viewModel.state.value.menuVisible || config.longTapEnabled) {
|
||||
val item = adapter.items.getOrNull(pager.currentItem)
|
||||
if (item is ReaderPage) {
|
||||
activity.onPageLongTap(item)
|
||||
|
@ -374,14 +374,14 @@ abstract class PagerViewer(val activity: ReaderActivity) : Viewer {
|
|||
|
||||
when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (!config.volumeKeysEnabled || activity.menuVisible) {
|
||||
if (!config.volumeKeysEnabled || activity.viewModel.state.value.menuVisible) {
|
||||
return false
|
||||
} else if (isUp) {
|
||||
if (!config.volumeKeysInverted) moveDown() else moveUp()
|
||||
}
|
||||
}
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (!config.volumeKeysEnabled || activity.menuVisible) {
|
||||
if (!config.volumeKeysEnabled || activity.viewModel.state.value.menuVisible) {
|
||||
return false
|
||||
} else if (isUp) {
|
||||
if (!config.volumeKeysInverted) moveUp() else moveDown()
|
||||
|
|
|
@ -91,7 +91,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
onScrolled()
|
||||
|
||||
if ((dy > threshold || dy < -threshold) && activity.menuVisible) {
|
||||
if ((dy > threshold || dy < -threshold) && activity.viewModel.state.value.menuVisible) {
|
||||
activity.hideMenu()
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||
}
|
||||
}
|
||||
recycler.longTapListener = f@{ event ->
|
||||
if (activity.menuVisible || config.longTapEnabled) {
|
||||
if (activity.viewModel.state.value.menuVisible || config.longTapEnabled) {
|
||||
val child = recycler.findChildViewUnder(event.x, event.y)
|
||||
if (child != null) {
|
||||
val position = recycler.getChildAdapterPosition(child)
|
||||
|
@ -310,14 +310,14 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||
|
||||
when (event.keyCode) {
|
||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||
if (!config.volumeKeysEnabled || activity.menuVisible) {
|
||||
if (!config.volumeKeysEnabled || activity.viewModel.state.value.menuVisible) {
|
||||
return false
|
||||
} else if (isUp) {
|
||||
if (!config.volumeKeysInverted) scrollDown() else scrollUp()
|
||||
}
|
||||
}
|
||||
KeyEvent.KEYCODE_VOLUME_UP -> {
|
||||
if (!config.volumeKeysEnabled || activity.menuVisible) {
|
||||
if (!config.volumeKeysEnabled || activity.viewModel.state.value.menuVisible) {
|
||||
return false
|
||||
} else if (isUp) {
|
||||
if (!config.volumeKeysInverted) scrollUp() else scrollDown()
|
||||
|
|
Loading…
Reference in a new issue