From 5b9f36292525ab9567460b4ba156c24b3435aeb2 Mon Sep 17 00:00:00 2001 From: John Leehey Date: Sat, 30 Nov 2019 18:37:52 -0800 Subject: [PATCH 1/4] Add support for margins in Webtoon view On larger tablets, matching the page width to the screen width in webtoon mode causes eye strain due to the image looking so magnified. Adding a page margin to the image can resolve this by effectively scaling the image down. --- .../data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferencesHelper.kt | 2 ++ .../ui/reader/ReaderSettingsSheet.kt | 1 + .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 20 ++++++++++++++ .../viewer/webtoon/WebtoonPageHolder.kt | 13 +++++++++- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 2 ++ .../tachiyomi/ui/setting/PreferenceDSL.kt | 5 ++++ .../ui/setting/SettingsReaderController.kt | 10 +++++++ .../widget/preference/FloatListPreference.kt | 26 +++++++++++++++++++ .../main/res/layout/reader_settings_sheet.xml | 21 ++++++++++++++- app/src/main/res/values/arrays.xml | 6 +++++ app/src/main/res/values/strings.xml | 4 +++ 12 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 58388547c..26e25aa29 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -51,6 +51,8 @@ object PreferenceKeys { const val readWithVolumeKeysInverted = "reader_volume_keys_inverted" + const val webtoonMarginRatio = "margin_ratio" + const val portraitColumns = "pref_library_columns_portrait_key" const val landscapeColumns = "pref_library_columns_landscape_key" 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 68e6371ee..bb5be1c25 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 @@ -79,6 +79,8 @@ class PreferencesHelper(val context: Context) { fun readWithVolumeKeysInverted() = rxPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false) + fun marginRatio() = rxPrefs.getInteger(Keys.webtoonMarginRatio, 0) + fun portraitColumns() = rxPrefs.getInteger(Keys.portraitColumns, 0) fun landscapeColumns() = rxPrefs.getInteger(Keys.landscapeColumns, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index b798f3b49..5f88b26fa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -82,6 +82,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia private fun initWebtoonPreferences() { webtoon_prefs_group.visible() crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon()) + margin_ratio_webtoon.bindToPreference(preferences.marginRatio()) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index 7ac8a220a..31ca89323 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -34,6 +34,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { var doubleTapAnimDuration = 500 private set + var marginRatio = 0f + private set + init { preferences.readWithTapping() .register({ tappingEnabled = it }) @@ -52,6 +55,23 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { preferences.readWithVolumeKeysInverted() .register({ volumeKeysInverted = it }) + + preferences.marginRatio() + .register({ marginFromPreference(it) }, { imagePropertyChangedListener?.invoke() }) + } + + private fun marginFromPreference(position: Int) { + marginRatio = when (position) { + 1 -> PageMargin.TEN_PERCENT + 2 -> PageMargin.TWENTY_FIVE_PERCENT + else -> PageMargin.NO_MARGIN + } + } + + object PageMargin { + const val NO_MARGIN = 0f + const val TEN_PERCENT = 0.1f + const val TWENTY_FIVE_PERCENT = 0.25f } fun unsubscribe() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index 754dbb7e1..34fb025d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -2,11 +2,13 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon import android.annotation.SuppressLint import android.content.Intent +import android.content.res.Resources import android.graphics.drawable.Drawable import android.net.Uri import android.support.v7.widget.AppCompatButton import android.support.v7.widget.AppCompatImageView import android.view.Gravity +import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT @@ -111,7 +113,7 @@ class WebtoonPageHolder( private var readImageHeaderSubscription: Subscription? = null init { - frame.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + refreshLayoutParams() } /** @@ -120,6 +122,15 @@ class WebtoonPageHolder( fun bind(page: ReaderPage) { this.page = page observeStatus() + refreshLayoutParams() + } + + private fun refreshLayoutParams() { + frame.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT).apply { + val margin = Resources.getSystem().displayMetrics.widthPixels * viewer.config.marginRatio + marginEnd = margin.toInt() + marginStart = margin.toInt() + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 6adee83c2..a2cb85597 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -110,6 +110,8 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer { frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) frame.addView(recycler) + + config.imagePropertyChangedListener = { adapter.notifyDataSetChanged() } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index 6fc05d1af..138ebf76e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting import android.support.graphics.drawable.VectorDrawableCompat import android.support.v4.graphics.drawable.DrawableCompat import android.support.v7.preference.* +import eu.kanade.tachiyomi.widget.preference.FloatListPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference @DslMarker @@ -37,6 +38,10 @@ inline fun PreferenceGroup.intListPreference(block: (@DSL IntListPreference).() return initThenAdd(IntListPreference(context), block).also(::initDialog) } +inline fun PreferenceGroup.floatListPreference(block: (@DSL FloatListPreference).() -> Unit): FloatListPreference { + return initThenAdd(FloatListPreference(context), block).also(::initDialog) +} + inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectListPreference).() -> Unit): MultiSelectListPreference { return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index ae59d13f1..e5958fdac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -112,6 +112,16 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.pref_crop_borders defaultValue = false } + + floatListPreference { + key = Keys.webtoonMarginRatio + titleRes = R.string.pref_reader_theme + entriesRes = arrayOf(R.string.webtoon_margin_ratio_0, + R.string.webtoon_margin_ratio_10, R.string.webtoon_margin_ratio_25) + entryValues = arrayOf("0", "1", "2") + defaultValue = "0" + summary = "%s" + } } preferenceCategory { titleRes = R.string.pref_reader_navigation diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt new file mode 100644 index 000000000..fb7d66e63 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt @@ -0,0 +1,26 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import android.support.v7.preference.ListPreference +import android.util.AttributeSet + +class FloatListPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + ListPreference(context, attrs) { + + override fun persistString(value: String?): Boolean { + return value != null && persistFloat(value.toFloat()) + } + + override fun getPersistedString(defaultReturnValue: String?): String? { + // When the underlying preference is using a PreferenceDataStore, there's no way (for now) + // to check if a value is in the store, so we use a most likely unused value as workaround + val defaultIntValue = Float.NEGATIVE_INFINITY + + val value = getPersistedFloat(defaultIntValue) + return if (value != defaultIntValue) { + value.toString() + } else { + defaultReturnValue + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index d28155d70..12435ba18 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -240,6 +240,25 @@ android:textColor="?android:attr/textColorSecondary" app:layout_constraintTop_toBottomOf="@id/webtoon_prefs" /> + + + + + app:constraint_referenced_ids="webtoon_prefs,crop_borders_webtoon,margin_ratio_text,margin_ratio_webtoon" /> @string/scale_type_smart_fit + + @string/webtoon_margin_ratio_0 + @string/webtoon_margin_ratio_10 + @string/webtoon_margin_ratio_25 + + 1 2 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f72686b4f..a42e9d4ed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -196,6 +196,7 @@ Tapping Long tap dialog Background color + Margin ratio White Black Default viewer @@ -230,6 +231,9 @@ G B A + No margin + 10% + 25% From 19993199db400e0276966dacba5511115e907170 Mon Sep 17 00:00:00 2001 From: John Leehey Date: Sat, 30 Nov 2019 18:41:52 -0800 Subject: [PATCH 2/4] Remove no-longer-needed FloatListPreference --- .../tachiyomi/ui/setting/PreferenceDSL.kt | 5 ---- .../ui/setting/SettingsReaderController.kt | 2 +- .../widget/preference/FloatListPreference.kt | 26 ------------------- 3 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index 138ebf76e..6fc05d1af 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.setting import android.support.graphics.drawable.VectorDrawableCompat import android.support.v4.graphics.drawable.DrawableCompat import android.support.v7.preference.* -import eu.kanade.tachiyomi.widget.preference.FloatListPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference @DslMarker @@ -38,10 +37,6 @@ inline fun PreferenceGroup.intListPreference(block: (@DSL IntListPreference).() return initThenAdd(IntListPreference(context), block).also(::initDialog) } -inline fun PreferenceGroup.floatListPreference(block: (@DSL FloatListPreference).() -> Unit): FloatListPreference { - return initThenAdd(FloatListPreference(context), block).also(::initDialog) -} - inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectListPreference).() -> Unit): MultiSelectListPreference { return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index e5958fdac..901b6c358 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -113,7 +113,7 @@ class SettingsReaderController : SettingsController() { defaultValue = false } - floatListPreference { + intListPreference { key = Keys.webtoonMarginRatio titleRes = R.string.pref_reader_theme entriesRes = arrayOf(R.string.webtoon_margin_ratio_0, diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt deleted file mode 100644 index fb7d66e63..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt +++ /dev/null @@ -1,26 +0,0 @@ -package eu.kanade.tachiyomi.widget.preference - -import android.content.Context -import android.support.v7.preference.ListPreference -import android.util.AttributeSet - -class FloatListPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : - ListPreference(context, attrs) { - - override fun persistString(value: String?): Boolean { - return value != null && persistFloat(value.toFloat()) - } - - override fun getPersistedString(defaultReturnValue: String?): String? { - // When the underlying preference is using a PreferenceDataStore, there's no way (for now) - // to check if a value is in the store, so we use a most likely unused value as workaround - val defaultIntValue = Float.NEGATIVE_INFINITY - - val value = getPersistedFloat(defaultIntValue) - return if (value != defaultIntValue) { - value.toString() - } else { - defaultReturnValue - } - } -} \ No newline at end of file From 4014c48c626da812d9e40135941f067ecf08ef03 Mon Sep 17 00:00:00 2001 From: John Leehey Date: Mon, 2 Dec 2019 13:38:33 -0800 Subject: [PATCH 3/4] Revert "Remove no-longer-needed FloatListPreference" This reverts commit 19993199db400e0276966dacba5511115e907170. --- .../tachiyomi/ui/setting/PreferenceDSL.kt | 5 ++++ .../ui/setting/SettingsReaderController.kt | 2 +- .../widget/preference/FloatListPreference.kt | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index 6fc05d1af..138ebf76e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting import android.support.graphics.drawable.VectorDrawableCompat import android.support.v4.graphics.drawable.DrawableCompat import android.support.v7.preference.* +import eu.kanade.tachiyomi.widget.preference.FloatListPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference @DslMarker @@ -37,6 +38,10 @@ inline fun PreferenceGroup.intListPreference(block: (@DSL IntListPreference).() return initThenAdd(IntListPreference(context), block).also(::initDialog) } +inline fun PreferenceGroup.floatListPreference(block: (@DSL FloatListPreference).() -> Unit): FloatListPreference { + return initThenAdd(FloatListPreference(context), block).also(::initDialog) +} + inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectListPreference).() -> Unit): MultiSelectListPreference { return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index 901b6c358..e5958fdac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -113,7 +113,7 @@ class SettingsReaderController : SettingsController() { defaultValue = false } - intListPreference { + floatListPreference { key = Keys.webtoonMarginRatio titleRes = R.string.pref_reader_theme entriesRes = arrayOf(R.string.webtoon_margin_ratio_0, diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt new file mode 100644 index 000000000..fb7d66e63 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt @@ -0,0 +1,26 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import android.support.v7.preference.ListPreference +import android.util.AttributeSet + +class FloatListPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + ListPreference(context, attrs) { + + override fun persistString(value: String?): Boolean { + return value != null && persistFloat(value.toFloat()) + } + + override fun getPersistedString(defaultReturnValue: String?): String? { + // When the underlying preference is using a PreferenceDataStore, there's no way (for now) + // to check if a value is in the store, so we use a most likely unused value as workaround + val defaultIntValue = Float.NEGATIVE_INFINITY + + val value = getPersistedFloat(defaultIntValue) + return if (value != defaultIntValue) { + value.toString() + } else { + defaultReturnValue + } + } +} \ No newline at end of file From f14af7cf832a4ac7900897cd882ecb298e2d9546 Mon Sep 17 00:00:00 2001 From: John Leehey Date: Mon, 2 Dec 2019 14:19:22 -0800 Subject: [PATCH 4/4] Bind the margin ratio as a float preference and rename variables - Fixed the floatListPreference that was used in the SettingsReaderController - Created new extension for binding float preferences in the ReaderSettingsSheet - Renamed the ratio variables to include the `webtoon` naming --- .../data/preference/PreferenceKeys.kt | 2 +- .../data/preference/PreferencesHelper.kt | 4 ++-- .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 16 +++++++++++++++- .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 18 ++---------------- .../ui/setting/SettingsReaderController.kt | 9 +++++---- .../main/res/layout/reader_settings_sheet.xml | 2 +- app/src/main/res/values/arrays.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 2 ++ 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 26e25aa29..74f9c5a6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -51,7 +51,7 @@ object PreferenceKeys { const val readWithVolumeKeysInverted = "reader_volume_keys_inverted" - const val webtoonMarginRatio = "margin_ratio" + const val marginRatioWebtoon = "margin_ratio_webtoon" const val portraitColumns = "pref_library_columns_portrait_key" 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 bb5be1c25..75bef0c5f 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 @@ -71,6 +71,8 @@ class PreferencesHelper(val context: Context) { fun cropBordersWebtoon() = rxPrefs.getBoolean(Keys.cropBordersWebtoon, false) + fun marginRatioWebtoon() = rxPrefs.getFloat(Keys.marginRatioWebtoon, 0f) + fun readWithTapping() = rxPrefs.getBoolean(Keys.readWithTapping, true) fun readWithLongTap() = rxPrefs.getBoolean(Keys.readWithLongTap, true) @@ -79,8 +81,6 @@ class PreferencesHelper(val context: Context) { fun readWithVolumeKeysInverted() = rxPrefs.getBoolean(Keys.readWithVolumeKeysInverted, false) - fun marginRatio() = rxPrefs.getInteger(Keys.webtoonMarginRatio, 0) - fun portraitColumns() = rxPrefs.getInteger(Keys.portraitColumns, 0) fun landscapeColumns() = rxPrefs.getInteger(Keys.landscapeColumns, 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index 5f88b26fa..595668473 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader import android.os.Bundle +import android.support.annotation.ArrayRes import android.support.design.widget.BottomSheetDialog import android.support.v4.widget.NestedScrollView import android.widget.CompoundButton @@ -82,7 +83,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia private fun initWebtoonPreferences() { webtoon_prefs_group.visible() crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon()) - margin_ratio_webtoon.bindToPreference(preferences.marginRatio()) + margin_ratio_webtoon.bindToFloatPreference(preferences.marginRatioWebtoon(), R.array.webtoon_margin_ratio_values) } /** @@ -103,4 +104,17 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia setSelection(pref.getOrDefault() - offset, false) } + /** + * Binds a spinner to a float preference. The position of the spinner item must + * correlate with the [floatValues] resource item (in arrays.xml), which is a + * of float values that will be parsed here and applied to the preference. + */ + private fun Spinner.bindToFloatPreference(pref: Preference, @ArrayRes floatValuesResource: Int) { + val floatValues = resources.getStringArray(floatValuesResource).map { it.toFloatOrNull() } + onItemSelectedListener = IgnoreFirstSpinnerListener { position -> + pref.set(floatValues[position]) + } + setSelection(floatValues.indexOf(pref.getOrDefault()), false) + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index 31ca89323..b26ea5144 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -56,22 +56,8 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { preferences.readWithVolumeKeysInverted() .register({ volumeKeysInverted = it }) - preferences.marginRatio() - .register({ marginFromPreference(it) }, { imagePropertyChangedListener?.invoke() }) - } - - private fun marginFromPreference(position: Int) { - marginRatio = when (position) { - 1 -> PageMargin.TEN_PERCENT - 2 -> PageMargin.TWENTY_FIVE_PERCENT - else -> PageMargin.NO_MARGIN - } - } - - object PageMargin { - const val NO_MARGIN = 0f - const val TEN_PERCENT = 0.1f - const val TWENTY_FIVE_PERCENT = 0.25f + preferences.marginRatioWebtoon() + .register({ marginRatio = it }, { imagePropertyChangedListener?.invoke() }) } fun unsubscribe() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index e5958fdac..ceb9ee64c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -114,11 +114,12 @@ class SettingsReaderController : SettingsController() { } floatListPreference { - key = Keys.webtoonMarginRatio - titleRes = R.string.pref_reader_theme + key = Keys.marginRatioWebtoon + titleRes = R.string.pref_reader_margin entriesRes = arrayOf(R.string.webtoon_margin_ratio_0, - R.string.webtoon_margin_ratio_10, R.string.webtoon_margin_ratio_25) - entryValues = arrayOf("0", "1", "2") + R.string.webtoon_margin_ratio_10, R.string.webtoon_margin_ratio_15, + R.string.webtoon_margin_ratio_20, R.string.webtoon_margin_ratio_25) + entryValues = arrayOf("0", "0.1", "0.15", "0.2", "0.25") defaultValue = "0" summary = "%s" } diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 12435ba18..04ebe2909 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -254,7 +254,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="16dp" - android:entries="@array/margin_ratio" + android:entries="@array/webtoon_margin_ratio" app:layout_constraintLeft_toRightOf="@id/verticalcenter" app:layout_constraintRight_toRightOf="@id/spinner_end" app:layout_constraintTop_toBottomOf="@id/crop_borders_webtoon"/> diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 87e5710ff..feefd81b3 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -53,12 +53,22 @@ @string/scale_type_smart_fit - + @string/webtoon_margin_ratio_0 @string/webtoon_margin_ratio_10 + @string/webtoon_margin_ratio_15 + @string/webtoon_margin_ratio_20 @string/webtoon_margin_ratio_25 + + 0.0 + 0.1 + 0.15 + 0.2 + 0.25 + + 1 2 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a42e9d4ed..6a261e6fc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -233,6 +233,8 @@ A No margin 10% + 15% + 20% 25%