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 9a56e98395..6029b40022 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
@@ -57,6 +57,8 @@ object PreferenceKeys {
const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"
+ const val marginRatioWebtoon = "margin_ratio_webtoon"
+
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 5306ae302c..9784d5b393 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
@@ -107,6 +107,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)
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 bf7318791d..b12ee7cf7a 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
@@ -4,6 +4,7 @@ import android.os.Build
import android.os.Bundle
import android.widget.CompoundButton
import android.widget.Spinner
+import androidx.annotation.ArrayRes
import androidx.core.widget.NestedScrollView
import com.f2prateek.rx.preferences.Preference
import com.google.android.material.bottomsheet.BottomSheetDialog
@@ -23,6 +24,7 @@ import kotlinx.android.synthetic.main.reader_settings_sheet.cutout_short
import kotlinx.android.synthetic.main.reader_settings_sheet.fullscreen
import kotlinx.android.synthetic.main.reader_settings_sheet.keepscreen
import kotlinx.android.synthetic.main.reader_settings_sheet.long_tap
+import kotlinx.android.synthetic.main.reader_settings_sheet.margin_ratio_webtoon
import kotlinx.android.synthetic.main.reader_settings_sheet.page_transitions
import kotlinx.android.synthetic.main.reader_settings_sheet.pager_prefs_group
import kotlinx.android.synthetic.main.reader_settings_sheet.rotation_mode
@@ -112,6 +114,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
webtoon_prefs_group.visible()
crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon())
+ margin_ratio_webtoon.bindToFloatPreference(preferences.marginRatioWebtoon(), R.array.webtoon_margin_ratio_values)
}
/**
@@ -131,4 +134,18 @@ 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 39a25d5b2b..57905f1d09 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
@@ -37,6 +37,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) {
var alwaysShowChapterTransition = true
private set
+ var marginRatio = 0f
+ private set
+
init {
preferences.readWithTapping()
.register({ tappingEnabled = it })
@@ -58,6 +61,9 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) {
preferences.alwaysShowChapterTransition()
.register({ alwaysShowChapterTransition = it })
+
+ preferences.marginRatioWebtoon()
+ .register({ marginRatio = it }, { imagePropertyChangedListener?.invoke() })
}
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 766ebb2cf0..a407fa39d3 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,9 +2,11 @@ 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.view.Gravity
+import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
@@ -128,6 +130,10 @@ class WebtoonPageHolder(
if (!viewer.isContinuous) {
bottomMargin = 15.dpToPx
}
+
+ 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 b7c90ccc0c..53fadb0190 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
@@ -121,6 +121,8 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
frame.addView(recycler)
+
+ config.imagePropertyChangedListener = { adapter.notifyDataSetChanged() }
}
private fun checkAllowPreload(page: ReaderPage?): Boolean {
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 4fc00def3f..823d0cdf4a 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
@@ -146,6 +146,17 @@ class SettingsReaderController : SettingsController() {
titleRes = R.string.pref_crop_borders
defaultValue = false
}
+
+ floatListPreference {
+ 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_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"
+ }
}
preferenceCategory {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt
index 4cb24e0648..c1223cdce1 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt
@@ -14,6 +14,7 @@ import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import eu.kanade.tachiyomi.widget.preference.BadgePreference
+import eu.kanade.tachiyomi.widget.preference.FloatListPreference
import eu.kanade.tachiyomi.widget.preference.IntListPreference
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
@@ -53,6 +54,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/widget/preference/FloatListPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/FloatListPreference.kt
new file mode 100644
index 0000000000..b27e42d009
--- /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.util.AttributeSet
+import androidx.preference.ListPreference
+
+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
+ }
+ }
+}
diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml
index e3cdde96ae..685eb8afae 100644
--- a/app/src/main/res/layout/reader_settings_sheet.xml
+++ b/app/src/main/res/layout/reader_settings_sheet.xml
@@ -256,6 +256,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_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 b463524f0b..93b4de9d3e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -241,6 +241,7 @@
Tapping
Long tap dialog
Background color
+ Margin ratio
White
Black
Default viewer
@@ -278,6 +279,11 @@
A
Always show chapter transition
Reading
+ No margin
+ 10%
+ 15%
+ 20%
+ 25%
Download location