Show toast when toggling crop borders

Consistent with reading mode and orientation shortcuts.
This commit is contained in:
arkon 2021-05-30 10:54:24 -04:00
parent fce81dd6d9
commit 1feac9c559
3 changed files with 34 additions and 22 deletions

View file

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

View file

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

View file

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