From f6a3760dfa560fcabb0747deebce21e6719c244d 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 --- .../tachiyomi/data/preference/PreferenceKeys.kt | 3 +++ .../data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 1 + .../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 ++++++ .../widget/preference/SourceLoginDialog.kt | 2 +- .../main/res/layout/reader_settings_sheet.xml | 14 +++++++++++--- app/src/main/res/values/strings.xml | 6 +++++- 13 files changed, 70 insertions(+), 13 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 48b56acb09..02c1011bbd 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 @@ -145,6 +145,8 @@ object PreferenceKeys { const val keepCatSort = "keep_cat_sort" + const val alwaysShowChapterTransition = "always_show_chapter_transition" + @Deprecated("Use the preferences of the source") fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId" @@ -153,6 +155,7 @@ object PreferenceKeys { fun sourceSharedPref(sourceId: Long) = "source_$sourceId" + 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 395378278b..486851cdda 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 @@ -248,4 +248,6 @@ class PreferencesHelper(val context: Context) { fun keepCatSort() = rxPrefs.getInteger(Keys.keepCatSort, 0) fun hideFiltersAtStart() = rxPrefs.getBoolean("hide_filters_at_start", false) + + 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 a1ff69ea07..bbc8e6a470 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 @@ -116,6 +116,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia fullscreen.bindToPreference(preferences.fullscreen()) 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 9bb95453a6..495290ccb7 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 @@ -46,6 +46,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe var readerTheme = 0 private set + var alwaysShowChapterTransition = true + private set + init { preferences.readWithTapping() .register({ tappingEnabled = it }) @@ -76,6 +79,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe preferences.readerTheme() .register({ readerTheme = 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 a8ab6bc00e..5f8b1f764b 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 1e09183dd6..bb8677bfcc 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 @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import android.view.View import android.view.ViewGroup 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 @@ -27,7 +28,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. @@ -39,7 +40,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 @@ -49,7 +54,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 ddbf3c2ec2..dbd7854499 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.view.ViewGroup import android.widget.FrameLayout import android.widget.LinearLayout 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) : androidx.recyclerview.widget.R * Updates this adapter with the given [chapters]. It handles setting a few pages of the * next/previous chapter to allow seamless transitions. */ - fun setChapters(chapters: ViewerChapters) { + fun setChapters(chapters: ViewerChapters, forceTransition: Boolean) { val newItems = mutableListOf() // Add previous chapter pages and transition. @@ -36,7 +37,11 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : androidx.recyclerview.widget.R 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 @@ -45,7 +50,10 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : androidx.recyclerview.widget.R } // Add next chapter transition and pages. - newItems.add(ChapterTransition.Next(chapters.currChapter, chapters.nextChapter)) + if (forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded) { + newItems.add(ChapterTransition.Next(chapters.currChapter, chapters.nextChapter)) + } + 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/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index b610e3b330..224cba589b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -34,6 +34,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { var doubleTapAnimDuration = 500 private set + var alwaysShowChapterTransition = true + private set + init { preferences.readWithTapping() .register({ tappingEnabled = it }) @@ -52,6 +55,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { 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/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 2b05259b31..b3672f7ffd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -172,7 +172,8 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer { */ override fun setChapters(chapters: ViewerChapters) { Timber.d("setChapters") - adapter.setChapters(chapters) + var forceTransition = config.alwaysShowChapterTransition || currentPage is ChapterTransition + adapter.setChapters(chapters, forceTransition) if (recycler.visibility == View.GONE) { Timber.d("Recycler first layout") diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index 40b96f111b..8f4f3f2cb1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -87,6 +87,12 @@ class SettingsReaderController : SettingsController() { defaultValue = false } } + switchPreference { + key = Keys.alwaysShowChapterTransition + titleRes = R.string.pref_always_show_chapter_transition + defaultValue = true + } + preferenceCategory { titleRes = R.string.pager_viewer diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt index 0aa7c3828a..e546204a60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/SourceLoginDialog.kt @@ -16,7 +16,7 @@ import rx.schedulers.Schedulers import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SourceLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) { +class SourceLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle = bundle) { private val source = Injekt.get().get(args.getLong("key")) as LoginSource diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 6948177ee2..e58541c7c7 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -44,7 +44,7 @@ + + + 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 663270d442..a7f4f7e1c3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -328,6 +328,7 @@ A Smart (based on page) Smart (based on page and theme) + Always show chapter transition Download location @@ -415,7 +416,7 @@ - Login for %1$s + Log in to %1$s Username Email address Password @@ -678,6 +679,7 @@ + Backdrop image of manga Cover of manga @@ -688,6 +690,8 @@ No matches found for your current filters You have no categories. Hit the plus button to create one for organizing your library. + Failed to bypass Cloudflare + Please update the WebView app for better compatibility Downloader