Эх сурвалжийг харах

Show toast when toggling crop borders

Consistent with reading mode and orientation shortcuts.
arkon 3 жил өмнө
parent
commit
1feac9c559

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt

@@ -38,8 +38,9 @@ operator fun <T> Preference<Set<T>>.minusAssign(item: T) {
     set(get() - item)
 }
 
-fun Preference<Boolean>.toggle() {
+fun Preference<Boolean>.toggle(): Boolean {
     set(!get())
+    return get()
 }
 
 class PreferencesHelper(val context: Context) {

+ 30 - 21
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -378,6 +378,36 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
             }
         }
 
+        // 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<ReaderActivityBinding, ReaderPresenter>()
             }
         }
 
-        // 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)

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -277,6 +277,8 @@
     <string name="pref_true_color">32-bit color</string>
     <string name="pref_true_color_summary">Reduces banding, but impacts performance</string>
     <string name="pref_crop_borders">Crop borders</string>
+    <string name="on">On</string>
+    <string name="off">Off</string>
     <string name="pref_custom_brightness">Custom brightness</string>
     <string name="pref_grayscale">Grayscale</string>
     <string name="pref_custom_color_filter">Custom color filter</string>