From 1feac9c5594e85a9e8ef82ac69cb048b7eda2598 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 30 May 2021 10:54:24 -0400 Subject: [PATCH] Show toast when toggling crop borders Consistent with reading mode and orientation shortcuts. --- .../data/preference/PreferencesHelper.kt | 3 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 51 +++++++++++-------- app/src/main/res/values/strings.xml | 2 + 3 files changed, 34 insertions(+), 22 deletions(-) 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 2f745202e..7591b9446 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 @@ -38,8 +38,9 @@ operator fun Preference>.minusAssign(item: T) { set(get() - item) } -fun Preference.toggle() { +fun Preference.toggle(): Boolean { set(!get()) + return get() } class PreferencesHelper(val context: Context) { 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 1de5b17df..95ca41bd6 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 @@ -378,6 +378,36 @@ class ReaderActivity : BaseRxActivity() } } + // Crop borders + with(binding.actionCropBorders) { + setTooltip(R.string.pref_crop_borders) + + setOnClickListener { + val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode()) + val enabled = if (isPagerType) { + preferences.cropBorders().toggle() + } else { + preferences.cropBordersWebtoon().toggle() + } + + menuToggleToast?.cancel() + menuToggleToast = toast( + if (enabled) { + R.string.on + } else { + R.string.off + } + ) + } + } + updateCropBordersShortcut() + listOf(preferences.cropBorders(), preferences.cropBordersWebtoon()) + .forEach { pref -> + pref.asFlow() + .onEach { updateCropBordersShortcut() } + .launchIn(lifecycleScope) + } + // Rotation with(binding.actionRotation) { setTooltip(R.string.rotation_type) @@ -400,27 +430,6 @@ class ReaderActivity : BaseRxActivity() } } - // Crop borders - with(binding.actionCropBorders) { - setTooltip(R.string.pref_crop_borders) - - setOnClickListener { - val isPagerType = ReadingModeType.isPagerType(presenter.getMangaReadingMode()) - if (isPagerType) { - preferences.cropBorders().toggle() - } else { - preferences.cropBordersWebtoon().toggle() - } - } - } - updateCropBordersShortcut() - listOf(preferences.cropBorders(), preferences.cropBordersWebtoon()) - .forEach { pref -> - pref.asFlow() - .onEach { updateCropBordersShortcut() } - .launchIn(lifecycleScope) - } - // Settings sheet with(binding.actionSettings) { setTooltip(R.string.action_settings) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 43fc1ae4d..56ffe0622 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -277,6 +277,8 @@ 32-bit color Reduces banding, but impacts performance Crop borders + On + Off Custom brightness Grayscale Custom color filter