From d501c02f8bdc666e5701518da2e0845d7b494e9e Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 28 Mar 2021 16:25:53 -0400 Subject: [PATCH] Add crop borders shortcut --- .../data/preference/PreferencesHelper.kt | 4 ++++ .../tachiyomi/ui/reader/ReaderActivity.kt | 14 ++++++++++++++ .../ui/reader/setting/ReadingModeType.kt | 5 +++++ app/src/main/res/drawable/ic_crop_free_24dp.xml | 9 +++++++++ app/src/main/res/layout/reader_activity.xml | 17 +++++++++++++++-- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_crop_free_24dp.xml 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 65b02c323d..be65ddfdf0 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 @@ -36,6 +36,10 @@ operator fun Preference>.minusAssign(item: T) { set(get() - item) } +fun Preference.toggle() { + set(!get()) +} + class PreferencesHelper(val context: Context) { private val prefs = PreferenceManager.getDefaultSharedPreferences(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 79d9c3a0e3..b1517f91e5 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 @@ -34,6 +34,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.asImmediateFlow +import eu.kanade.tachiyomi.data.preference.toggle import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.main.MainActivity @@ -375,6 +376,19 @@ class ReaderActivity : BaseRxActivity() } .launchIn(lifecycleScope) + with(binding.actionCropBorders) { + setTooltip(R.string.pref_crop_borders) + + setOnClickListener { + val isPagerType = ReadingModeType.isPagerType(presenter.getMangaViewer()) + if (isPagerType) { + preferences.cropBorders().toggle() + } else { + preferences.cropBordersWebtoon().toggle() + } + } + } + with(binding.actionSettings) { setTooltip(R.string.action_settings) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt index 7e54c74c7f..4f0c1a3f8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReadingModeType.kt @@ -21,5 +21,10 @@ enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @D val current = fromPreference(preference) return current.next() } + + fun isPagerType(preference: Int): Boolean { + val mode = fromPreference(preference) + return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL + } } } diff --git a/app/src/main/res/drawable/ic_crop_free_24dp.xml b/app/src/main/res/drawable/ic_crop_free_24dp.xml new file mode 100644 index 0000000000..0b681872e8 --- /dev/null +++ b/app/src/main/res/drawable/ic_crop_free_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/reader_activity.xml b/app/src/main/res/layout/reader_activity.xml index a134f2a717..d2d968a202 100644 --- a/app/src/main/res/layout/reader_activity.xml +++ b/app/src/main/res/layout/reader_activity.xml @@ -171,12 +171,25 @@ android:background="?selectableItemBackgroundBorderless" android:contentDescription="@string/pref_rotation_type" android:padding="@dimen/material_layout_keylines_screen_edge_margin" - app:layout_constraintEnd_toStartOf="@id/action_settings" + app:layout_constraintEnd_toStartOf="@id/action_crop_borders" app:layout_constraintStart_toEndOf="@+id/action_reader_mode" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/ic_screen_rotation_24dp" app:tint="?attr/colorOnPrimary" /> + +