From b7b2c9ab643ca7ff2d95a5173424c863b61b7657 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 26 Apr 2021 01:05:16 -0400 Subject: [PATCH] Move ReaderBottomButton to its own file --- .../data/preference/PreferencesHelper.kt | 4 +-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 2 -- .../tachiyomi/ui/reader/ReaderActivity.kt | 36 +++++-------------- .../ui/reader/settings/ReaderBottomButton.kt | 27 ++++++++++++++ .../ui/setting/SettingsReaderController.kt | 12 +++---- 5 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderBottomButton.kt 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 dfbdbba4c5..b89b866eff 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 @@ -12,7 +12,7 @@ import com.tfcporciuncula.flow.FlowSharedPreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.ui.library.filter.FilterBottomSheet -import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout import eu.kanade.tachiyomi.ui.recents.RecentMangaAdapter @@ -190,7 +190,7 @@ class PreferencesHelper(val context: Context) { fun readerBottomButtons() = flowPrefs.getStringSet( Keys.readerBottomButtons, - ReaderActivity.BUTTONS_DEFAULTS + ReaderBottomButton.BUTTONS_DEFAULTS ) fun showNavigationOverlayNewUser() = flowPrefs.getBoolean(Keys.showNavigationOverlayNewUser, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index bebeb8f95d..d54c9808a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -44,7 +44,6 @@ import eu.kanade.tachiyomi.data.download.DownloadServiceListener import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications -import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdateChecker @@ -82,7 +81,6 @@ import eu.kanade.tachiyomi.widget.EndAnimatorListener import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber 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 c2db8b2a23..64ea4f9bb4 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 @@ -22,7 +22,6 @@ import android.view.WindowManager import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.SeekBar -import androidx.annotation.StringRes import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu import androidx.core.content.ContextCompat @@ -56,6 +55,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success 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.ui.reader.settings.ReaderBottomButton import eu.kanade.tachiyomi.ui.reader.settings.OrientationType import eu.kanade.tachiyomi.ui.reader.settings.ReadingModeType import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet @@ -207,13 +207,6 @@ class ReaderActivity : const val SHIFTED_PAGE_INDEX = "shiftedPageIndex" const val SHIFTED_CHAP_INDEX = "shiftedChapterIndex" - val BUTTONS_DEFAULTS = setOf( - BottomButton.ViewChapters, - BottomButton.WebView, - BottomButton.PageLayout, - BottomButton.CropBordersWebtoon - ).map { it.value }.toSet() - fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent { val intent = Intent(context, ReaderActivity::class.java) intent.putExtra("manga", manga.id) @@ -223,17 +216,6 @@ class ReaderActivity : } } - enum class BottomButton(val value: String, @StringRes val stringRes: Int) { - ViewChapters("vc", R.string.view_chapters), - WebView("wb", R.string.open_in_webview), - ReadingMode("rm", R.string.reading_mode), - Rotation("rot", R.string.rotation), - CropBordersPaged("cbp", R.string.crop_borders_paged), - CropBordersWebtoon("cbw", R.string.crop_borders_webtoon), - PageLayout("pl", R.string.page_layout), - ShiftDoublePage("sdp", R.string.shift_double_pages) - } - /** * Called when the activity is created. Initializes the presenter and configuration. */ @@ -379,7 +361,7 @@ class ReaderActivity : return if (preferences.readerBottomButtons().isNotSet()) { isTablet() } else { - BottomButton.ShiftDoublePage.value in preferences.readerBottomButtons().get() + ReaderBottomButton.ShiftDoublePage.isIn(preferences.readerBottomButtons().get()) } } @@ -446,21 +428,21 @@ class ReaderActivity : with(binding.chaptersSheet) { readingMode.isVisible = presenter?.manga?.isLongStrip() != true && - BottomButton.ReadingMode.value in enabledButtons + ReaderBottomButton.ReadingMode.isIn(enabledButtons) rotationSheetButton.isVisible = - BottomButton.Rotation.value in enabledButtons + ReaderBottomButton.Rotation.isIn(enabledButtons) doublePage.isVisible = viewer is PagerViewer && - BottomButton.PageLayout.value in enabledButtons + ReaderBottomButton.PageLayout.isIn(enabledButtons) cropBordersSheetButton.isVisible = if (viewer is PagerViewer) { - BottomButton.CropBordersPaged.value in enabledButtons + ReaderBottomButton.CropBordersPaged.isIn(enabledButtons) } else { - BottomButton.CropBordersWebtoon.value in enabledButtons + ReaderBottomButton.CropBordersWebtoon.isIn(enabledButtons) } webviewButton.isVisible = - BottomButton.WebView.value in enabledButtons + ReaderBottomButton.WebView.isIn(enabledButtons) chaptersButton.isVisible = - BottomButton.ViewChapters.value in enabledButtons + ReaderBottomButton.ViewChapters.isIn(enabledButtons) shiftPageButton.isVisible = ((viewer as? PagerViewer)?.config?.doublePages ?: false) && canShowSplitAtBottom() binding.toolbar.menu.findItem(R.id.action_shift_double_page)?.isVisible = diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderBottomButton.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderBottomButton.kt new file mode 100644 index 0000000000..4b31266e13 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/settings/ReaderBottomButton.kt @@ -0,0 +1,27 @@ +package eu.kanade.tachiyomi.ui.reader.settings + +import androidx.annotation.StringRes +import eu.kanade.tachiyomi.R + +enum class ReaderBottomButton(val value: String, @StringRes val stringRes: Int) { + ViewChapters("vc", R.string.view_chapters), + WebView("wb", R.string.open_in_webview), + ReadingMode("rm", R.string.reading_mode), + Rotation("rot", R.string.rotation), + CropBordersPaged("cbp", R.string.crop_borders_paged), + CropBordersWebtoon("cbw", R.string.crop_borders_webtoon), + PageLayout("pl", R.string.page_layout), + ShiftDoublePage("sdp", R.string.shift_double_pages) + ; + + fun isIn(buttons: Collection) = value in buttons + + companion object { + val BUTTONS_DEFAULTS = setOf( + ViewChapters, + WebView, + PageLayout, + CropBordersWebtoon + ).map { it.value }.toSet() + } +} 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 79f8eee5a3..83af49d0e8 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 @@ -5,7 +5,7 @@ import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn -import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.ui.reader.settings.ReaderBottomButton import eu.kanade.tachiyomi.ui.reader.settings.OrientationType import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout @@ -73,15 +73,15 @@ class SettingsReaderController : SettingsController() { multiSelectListPreferenceMat(activity) { key = Keys.readerBottomButtons titleRes = R.string.display_buttons_bottom_reader - val enumConstants = ReaderActivity.BottomButton::class.java.enumConstants - entriesRes = enumConstants?.map { it.stringRes }.orEmpty().toTypedArray() - entryValues = enumConstants?.map { it.value }.orEmpty() + val enumConstants = ReaderBottomButton.values() + entriesRes = ReaderBottomButton.values().map { it.stringRes }.toTypedArray() + entryValues = enumConstants.map { it.value } allSelectionRes = R.string.display_options allIsAlwaysSelected = true showAllLast = true - val defaults = ReaderActivity.BUTTONS_DEFAULTS.toMutableList() + val defaults = ReaderBottomButton.BUTTONS_DEFAULTS.toMutableList() if (context.isTablet()) { - defaults.add(ReaderActivity.BottomButton.ShiftDoublePage.value) + defaults.add(ReaderBottomButton.ShiftDoublePage.value) } defaultValue = defaults }