From 3d6d934708549d90a276775ccc3e37cdc22a286d Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 19 Jul 2021 17:37:16 -0400 Subject: [PATCH] Added chapter/page-contextual disabling / hiding of nav buttons and nav bar Co-Authored-By: Hunter Nickel <25621728+datreesezcup@users.noreply.github.com> --- .../tachiyomi/ui/reader/ReaderActivity.kt | 11 +++++++++- .../ui/reader/chapter/ReaderChapterSheet.kt | 21 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 62b408a7d7..34af9e889f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -957,12 +957,21 @@ class ReaderActivity : ) ) % 2 != 0 } + val currentChapterPageCount = viewerChapters.currChapter.pages?.size ?: 1 + binding.readerNav.root.visibility = when { + currentChapterPageCount == 1 -> View.GONE + binding.chaptersSheet.root.sheetBehavior.isCollapsed() -> View.VISIBLE + else -> View.INVISIBLE + } lastShiftDoubleState = null viewer?.setChapters(viewerChapters) intentPageNumber?.let { moveToPageIndex(it) } intentPageNumber = null binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name - if (viewer is R2LPagerViewer) { + if (viewerChapters.nextChapter == null && viewerChapters.prevChapter == null) { + binding.readerNav.leftChapter.isVisible = false + binding.readerNav.rightChapter.isVisible = false + } else if (viewer is R2LPagerViewer) { binding.readerNav.leftChapter.alpha = if (viewerChapters.nextChapter != null) 1f else 0.5f binding.readerNav.rightChapter.alpha = if (viewerChapters.prevChapter != null) 1f else 0.5f } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt index bafd419248..b5f93c6ed4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt @@ -7,6 +7,7 @@ import android.util.AttributeSet import android.view.View import android.widget.LinearLayout import androidx.core.graphics.ColorUtils +import androidx.core.view.isGone import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager @@ -67,7 +68,9 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr binding.chapterRecycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f binding.chapterRecycler.isClickable = sheetBehavior.isExpanded() binding.chapterRecycler.isFocusable = sheetBehavior.isExpanded() - activity.binding.readerNav.root.isVisible = sheetBehavior.isCollapsed() + if (!activity.binding.readerNav.root.isGone) { + activity.binding.readerNav.root.isVisible = sheetBehavior.isCollapsed() + } } sheetBehavior?.addBottomSheetCallback( @@ -92,21 +95,29 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr adapter?.getPosition(presenter.getCurrentChapter()?.chapter?.id ?: 0L) ?: 0, binding.chapterRecycler.height / 2 - 30.dpToPx ) - activity.binding.readerNav.root.isVisible = true + if (!activity.binding.readerNav.root.isGone) { + activity.binding.readerNav.root.isVisible = true + } activity.binding.readerNav.root.alpha = 1f } if (state == BottomSheetBehavior.STATE_DRAGGING || state == BottomSheetBehavior.STATE_SETTLING) { - activity.binding.readerNav.root.isVisible = true + if (!activity.binding.readerNav.root.isGone) { + activity.binding.readerNav.root.isVisible = true + } } if (state == BottomSheetBehavior.STATE_EXPANDED) { - activity.binding.readerNav.root.isInvisible = true + if (!activity.binding.readerNav.root.isGone) { + activity.binding.readerNav.root.isInvisible = true + } activity.binding.readerNav.root.alpha = 0f binding.chapterRecycler.alpha = 1f if (activity.sheetManageNavColor) activity.window.navigationBarColor = primary } if (state == BottomSheetBehavior.STATE_HIDDEN) { activity.binding.readerNav.root.alpha = 0f - activity.binding.readerNav.root.isInvisible = true + if (!activity.binding.readerNav.root.isGone) { + activity.binding.readerNav.root.isInvisible = true + } } binding.chapterRecycler.isClickable = state == BottomSheetBehavior.STATE_EXPANDED binding.chapterRecycler.isFocusable = state == BottomSheetBehavior.STATE_EXPANDED