From 9936b402a6e0e5974140e6ed1162455bb489204e Mon Sep 17 00:00:00 2001 From: morcefaster <51055657+morcefaster@users.noreply.github.com> Date: Mon, 9 Mar 2020 20:36:29 +0200 Subject: [PATCH] Added config to hide transition page when not needed (#2682) * Added config to hide transition page when not needed * Moved always_show_chapter_transition setting to General group --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 2 ++ .../ui/reader/viewer/pager/PagerConfig.kt | 6 ++++++ .../ui/reader/viewer/pager/PagerViewer.kt | 3 ++- .../reader/viewer/pager/PagerViewerAdapter.kt | 17 ++++++++++++++--- .../ui/reader/viewer/webtoon/WebtoonAdapter.kt | 14 +++++++++++--- .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 6 ++++++ .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 3 ++- .../ui/setting/SettingsReaderController.kt | 6 ++++++ .../main/res/layout/reader_settings_sheet.xml | 11 ++++++++++- app/src/main/res/values/strings.xml | 1 + 12 files changed, 64 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 219bb847e..b1a7a1679 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -133,6 +133,8 @@ object PreferenceKeys { const val downloadBadge = "display_download_badge" + const val alwaysShowChapterTransition = "always_show_chapter_transition" + fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId" fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 467052129..17f66d08d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -203,4 +203,6 @@ class PreferencesHelper(val context: Context) { fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE) fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet()) + + fun alwaysShowChapterTransition() = rxPrefs.getBoolean(Keys.alwaysShowChapterTransition, true) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index 43d53c2de..669dd5607 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener +import kotlinx.android.synthetic.main.reader_settings_sheet.always_show_chapter_transition import kotlinx.android.synthetic.main.reader_settings_sheet.background_color import kotlinx.android.synthetic.main.reader_settings_sheet.crop_borders import kotlinx.android.synthetic.main.reader_settings_sheet.crop_borders_webtoon @@ -84,6 +85,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia } keepscreen.bindToPreference(preferences.keepScreenOn()) long_tap.bindToPreference(preferences.readWithLongTap()) + always_show_chapter_transition.bindToPreference(preferences.alwaysShowChapterTransition()) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index 89d69b29e..2ac6eab10 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -43,6 +43,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe var doubleTapAnimDuration = 500 private set + var alwaysShowChapterTransition = true + private set + init { preferences.readWithTapping() .register({ tappingEnabled = it }) @@ -70,6 +73,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe preferences.readWithVolumeKeysInverted() .register({ volumeKeysInverted = it }) + + preferences.alwaysShowChapterTransition() + .register({ alwaysShowChapterTransition = it }) } fun unsubscribe() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 67b1368f9..43af3a54e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -185,7 +185,8 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { */ private fun setChaptersInternal(chapters: ViewerChapters) { Timber.d("setChaptersInternal") - adapter.setChapters(chapters) + var forceTransition = config.alwaysShowChapterTransition || adapter.items.getOrNull(pager.currentItem) is ChapterTransition + adapter.setChapters(chapters, forceTransition) // Layout the pager once a chapter is being set if (pager.visibility == View.GONE) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 4162eaf85..980674333 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -4,6 +4,7 @@ import android.view.View import android.view.ViewGroup import androidx.viewpager.widget.PagerAdapter import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition +import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.widget.ViewPagerAdapter @@ -28,7 +29,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { * next/previous chapter to allow seamless transitions and inverting the pages if the viewer * has R2L direction. */ - fun setChapters(chapters: ViewerChapters) { + fun setChapters(chapters: ViewerChapters, forceTransition: Boolean) { val newItems = mutableListOf() // Add previous chapter pages and transition. @@ -40,7 +41,11 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { newItems.addAll(prevPages.takeLast(2)) } } - newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) + + // Skip transition page if the chapter is loaded & current page is not a transition page + if (forceTransition || chapters.prevChapter?.state !is ReaderChapter.State.Loaded) { + newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) + } // Add current chapter. val currPages = chapters.currChapter.pages @@ -50,7 +55,13 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { // Add next chapter transition and pages. nextTransition = ChapterTransition.Next(chapters.currChapter, chapters.nextChapter) - .also { newItems.add(it) } + .also { + if (forceTransition || + chapters.nextChapter?.state !is ReaderChapter.State.Loaded) { + newItems.add(it) + } + } + if (chapters.nextChapter != null) { // Add at most two pages, because this chapter will be selected before the user can // swap more pages. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index 3a27815de..e65a73b8f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -6,6 +6,7 @@ import android.widget.LinearLayout import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition +import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters @@ -24,7 +25,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter() // Add previous chapter pages and transition. @@ -36,7 +37,11 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter + + + app:layout_constraintBottom_toBottomOf="@id/always_show_chapter_transition" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 36d57a977..d2ed26f3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -264,6 +264,7 @@ G B A + Always show chapter transition Download location