Add behavior for modifying reader buttons depending on prev/next chapters (#5305)
(cherry picked from commit fdf178d4df5ca4819c972ca2730e86ef173beeca) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
This commit is contained in:
parent
74636f4b1a
commit
13235f3a37
@ -119,6 +119,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||
const val SHIFT_DOUBLE_PAGES = "shiftingDoublePages"
|
||||
const val SHIFTED_PAGE_INDEX = "shiftedPageIndex"
|
||||
const val SHIFTED_CHAP_INDEX = "shiftedChapterIndex"
|
||||
|
||||
private const val ENABLED_BUTTON_IMAGE_ALPHA = 255
|
||||
private const val DISABLED_BUTTON_IMAGE_ALPHA = 64
|
||||
}
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
@ -1078,7 +1081,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||
|
||||
/**
|
||||
* Called from the presenter whenever a new [viewerChapters] have been set. It delegates the
|
||||
* method to the current viewer, but also set the subtitle on the toolbar.
|
||||
* method to the current viewer, but also set the subtitle on the toolbar, and
|
||||
* hides or disables the reader prev/next buttons if there's a prev or next chapter
|
||||
*/
|
||||
fun setChapters(viewerChapters: ViewerChapters) {
|
||||
binding.pleaseWait.isVisible = false
|
||||
@ -1104,6 +1108,20 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||
viewer?.setChapters(viewerChapters)
|
||||
binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name
|
||||
|
||||
val leftChapterObject = if (viewer is R2LPagerViewer) viewerChapters.nextChapter else viewerChapters.prevChapter
|
||||
val rightChapterObject = if (viewer is R2LPagerViewer) viewerChapters.prevChapter else viewerChapters.nextChapter
|
||||
|
||||
if (leftChapterObject == null && rightChapterObject == null) {
|
||||
binding.leftChapter.isVisible = false
|
||||
binding.rightChapter.isVisible = false
|
||||
} else {
|
||||
binding.leftChapter.isEnabled = leftChapterObject != null
|
||||
binding.leftChapter.imageAlpha = if (leftChapterObject != null) ENABLED_BUTTON_IMAGE_ALPHA else DISABLED_BUTTON_IMAGE_ALPHA
|
||||
|
||||
binding.rightChapter.isEnabled = rightChapterObject != null
|
||||
binding.rightChapter.imageAlpha = if (rightChapterObject != null) ENABLED_BUTTON_IMAGE_ALPHA else DISABLED_BUTTON_IMAGE_ALPHA
|
||||
}
|
||||
|
||||
// Invalidate menu to show proper chapter bookmark state
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user