Move ReaderBottomButton to its own file

This commit is contained in:
Jays2Kings 2021-04-26 01:05:16 -04:00
parent 47f6c54412
commit b7b2c9ab64
5 changed files with 44 additions and 37 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 =

View File

@ -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<String>) = value in buttons
companion object {
val BUTTONS_DEFAULTS = setOf(
ViewChapters,
WebView,
PageLayout,
CropBordersWebtoon
).map { it.value }.toSet()
}
}

View File

@ -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
}