mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-08-20 08:19:10 +02:00
Tweak webtoon margin setting
This commit is contained in:
parent
a63d165dd3
commit
fdc7981d18
@ -57,7 +57,7 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"
|
const val readWithVolumeKeysInverted = "reader_volume_keys_inverted"
|
||||||
|
|
||||||
const val marginRatioWebtoon = "margin_ratio_webtoon"
|
const val webtoonSidePadding = "webtoon_side_padding"
|
||||||
|
|
||||||
const val portraitColumns = "pref_library_columns_portrait_key"
|
const val portraitColumns = "pref_library_columns_portrait_key"
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun cropBordersWebtoon() = rxPrefs.getBoolean(Keys.cropBordersWebtoon, false)
|
fun cropBordersWebtoon() = rxPrefs.getBoolean(Keys.cropBordersWebtoon, false)
|
||||||
|
|
||||||
fun marginRatioWebtoon() = rxPrefs.getFloat(Keys.marginRatioWebtoon, 0f)
|
fun webtoonSidePadding() = rxPrefs.getInteger(Keys.webtoonSidePadding, 0)
|
||||||
|
|
||||||
fun readWithTapping() = rxPrefs.getBoolean(Keys.readWithTapping, true)
|
fun readWithTapping() = rxPrefs.getBoolean(Keys.readWithTapping, true)
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ 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.fullscreen
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.keepscreen
|
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.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.page_transitions
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.pager_prefs_group
|
import kotlinx.android.synthetic.main.reader_settings_sheet.pager_prefs_group
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.rotation_mode
|
import kotlinx.android.synthetic.main.reader_settings_sheet.rotation_mode
|
||||||
@ -32,6 +31,7 @@ import kotlinx.android.synthetic.main.reader_settings_sheet.scale_type
|
|||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.show_page_number
|
import kotlinx.android.synthetic.main.reader_settings_sheet.show_page_number
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.viewer
|
import kotlinx.android.synthetic.main.reader_settings_sheet.viewer
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.webtoon_prefs_group
|
import kotlinx.android.synthetic.main.reader_settings_sheet.webtoon_prefs_group
|
||||||
|
import kotlinx.android.synthetic.main.reader_settings_sheet.webtoon_side_padding
|
||||||
import kotlinx.android.synthetic.main.reader_settings_sheet.zoom_start
|
import kotlinx.android.synthetic.main.reader_settings_sheet.zoom_start
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
|
|||||||
webtoon_prefs_group.visible()
|
webtoon_prefs_group.visible()
|
||||||
|
|
||||||
crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon())
|
crop_borders_webtoon.bindToPreference(preferences.cropBordersWebtoon())
|
||||||
margin_ratio_webtoon.bindToFloatPreference(preferences.marginRatioWebtoon(), R.array.webtoon_margin_ratio_values)
|
webtoon_side_padding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,16 +136,15 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a spinner to a float preference. The position of the spinner item must
|
* Binds a spinner to an int preference. The position of the spinner item must
|
||||||
* correlate with the [floatValues] resource item (in arrays.xml), which is a <string-array>
|
* correlate with the [intValues] resource item (in arrays.xml), which is a <string-array>
|
||||||
* of float values that will be parsed here and applied to the preference.
|
* of int values that will be parsed here and applied to the preference.
|
||||||
*/
|
*/
|
||||||
private fun Spinner.bindToFloatPreference(pref: Preference<Float>, @ArrayRes floatValuesResource: Int) {
|
private fun Spinner.bindToIntPreference(pref: Preference<Int>, @ArrayRes intValuesResource: Int) {
|
||||||
val floatValues = resources.getStringArray(floatValuesResource).map { it.toFloatOrNull() }
|
val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() }
|
||||||
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||||
pref.set(floatValues[position])
|
pref.set(intValues[position])
|
||||||
}
|
}
|
||||||
setSelection(floatValues.indexOf(pref.getOrDefault()), false)
|
setSelection(intValues.indexOf(pref.getOrDefault()), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) {
|
|||||||
var alwaysShowChapterTransition = true
|
var alwaysShowChapterTransition = true
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var marginRatio = 0f
|
var sidePadding = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -62,8 +62,8 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) {
|
|||||||
preferences.alwaysShowChapterTransition()
|
preferences.alwaysShowChapterTransition()
|
||||||
.register({ alwaysShowChapterTransition = it })
|
.register({ alwaysShowChapterTransition = it })
|
||||||
|
|
||||||
preferences.marginRatioWebtoon()
|
preferences.webtoonSidePadding()
|
||||||
.register({ marginRatio = it }, { imagePropertyChangedListener?.invoke() })
|
.register({ sidePadding = it }, { imagePropertyChangedListener?.invoke() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unsubscribe() {
|
fun unsubscribe() {
|
||||||
|
@ -6,7 +6,6 @@ import android.content.res.Resources
|
|||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
@ -131,7 +130,7 @@ class WebtoonPageHolder(
|
|||||||
bottomMargin = 15.dpToPx
|
bottomMargin = 15.dpToPx
|
||||||
}
|
}
|
||||||
|
|
||||||
val margin = Resources.getSystem().displayMetrics.widthPixels * viewer.config.marginRatio
|
val margin = Resources.getSystem().displayMetrics.widthPixels * (viewer.config.sidePadding / 100f)
|
||||||
marginEnd = margin.toInt()
|
marginEnd = margin.toInt()
|
||||||
marginStart = margin.toInt()
|
marginStart = margin.toInt()
|
||||||
}
|
}
|
||||||
|
@ -121,8 +121,6 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||||||
|
|
||||||
frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
frame.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||||
frame.addView(recycler)
|
frame.addView(recycler)
|
||||||
|
|
||||||
config.imagePropertyChangedListener = { adapter.notifyDataSetChanged() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAllowPreload(page: ReaderPage?): Boolean {
|
private fun checkAllowPreload(page: ReaderPage?): Boolean {
|
||||||
@ -288,10 +286,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies adapter of changes around the current page to trigger a relayout in the recycler.
|
* Notifies adapter of changes around the current page to trigger a relayout in the recycler.
|
||||||
* Used when a image configuration is changed.
|
* Used when an image configuration is changed.
|
||||||
*/
|
*/
|
||||||
private fun refreshAdapter() {
|
private fun refreshAdapter() {
|
||||||
val position = layoutManager.findLastEndVisibleItemPosition()
|
val position = layoutManager.findLastEndVisibleItemPosition()
|
||||||
adapter.notifyItemRangeChanged(max(0, position - 1), min(2, adapter.itemCount - position))
|
adapter.notifyItemRangeChanged(
|
||||||
|
max(0, position - 2),
|
||||||
|
min(position + 2, adapter.itemCount - 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,13 +147,16 @@ class SettingsReaderController : SettingsController() {
|
|||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
|
|
||||||
floatListPreference {
|
intListPreference {
|
||||||
key = Keys.marginRatioWebtoon
|
key = Keys.webtoonSidePadding
|
||||||
titleRes = R.string.pref_reader_margin
|
titleRes = R.string.pref_webtoon_side_padding
|
||||||
entriesRes = arrayOf(R.string.webtoon_margin_ratio_0,
|
entriesRes = arrayOf(
|
||||||
R.string.webtoon_margin_ratio_10, R.string.webtoon_margin_ratio_15,
|
R.string.webtoon_side_padding_0,
|
||||||
R.string.webtoon_margin_ratio_20, R.string.webtoon_margin_ratio_25)
|
R.string.webtoon_side_padding_10,
|
||||||
entryValues = arrayOf("0", "0.1", "0.15", "0.2", "0.25")
|
R.string.webtoon_side_padding_15,
|
||||||
|
R.string.webtoon_side_padding_20,
|
||||||
|
R.string.webtoon_side_padding_25)
|
||||||
|
entryValues = arrayOf("0", "10", "15", "20", "25")
|
||||||
defaultValue = "0"
|
defaultValue = "0"
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import androidx.preference.PreferenceScreen
|
|||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||||
import eu.kanade.tachiyomi.widget.preference.BadgePreference
|
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.IntListPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
||||||
|
|
||||||
@ -54,10 +53,6 @@ inline fun PreferenceGroup.intListPreference(block: (@DSL IntListPreference).()
|
|||||||
return initThenAdd(IntListPreference(context), block).also(::initDialog)
|
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 {
|
inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectListPreference).() -> Unit): MultiSelectListPreference {
|
||||||
return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog)
|
return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog)
|
||||||
}
|
}
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -257,20 +257,20 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@id/webtoon_prefs" />
|
app:layout_constraintTop_toBottomOf="@id/webtoon_prefs" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/margin_ratio_text"
|
android:id="@+id/webtoon_side_padding_text"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/pref_reader_margin"
|
android:text="@string/pref_webtoon_side_padding"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toLeftOf="@id/verticalcenter"
|
app:layout_constraintRight_toLeftOf="@id/verticalcenter"
|
||||||
app:layout_constraintBaseline_toBaselineOf="@id/margin_ratio_webtoon"/>
|
app:layout_constraintBaseline_toBaselineOf="@id/webtoon_side_padding"/>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatSpinner
|
<androidx.appcompat.widget.AppCompatSpinner
|
||||||
android:id="@+id/margin_ratio_webtoon"
|
android:id="@+id/webtoon_side_padding"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:entries="@array/webtoon_margin_ratio"
|
android:entries="@array/webtoon_side_padding"
|
||||||
app:layout_constraintLeft_toRightOf="@id/verticalcenter"
|
app:layout_constraintLeft_toRightOf="@id/verticalcenter"
|
||||||
app:layout_constraintRight_toRightOf="@id/spinner_end"
|
app:layout_constraintRight_toRightOf="@id/spinner_end"
|
||||||
app:layout_constraintTop_toBottomOf="@id/crop_borders_webtoon"/>
|
app:layout_constraintTop_toBottomOf="@id/crop_borders_webtoon"/>
|
||||||
@ -290,7 +290,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:constraint_referenced_ids="webtoon_prefs,crop_borders_webtoon,margin_ratio_text,margin_ratio_webtoon" />
|
app:constraint_referenced_ids="webtoon_prefs,crop_borders_webtoon,webtoon_side_padding_text,webtoon_side_padding" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Guideline
|
<androidx.constraintlayout.widget.Guideline
|
||||||
android:id="@+id/verticalcenter"
|
android:id="@+id/verticalcenter"
|
||||||
|
@ -54,20 +54,20 @@
|
|||||||
<item>@string/scale_type_smart_fit</item>
|
<item>@string/scale_type_smart_fit</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="webtoon_margin_ratio">
|
<string-array name="webtoon_side_padding">
|
||||||
<item>@string/webtoon_margin_ratio_0</item>
|
<item>@string/webtoon_side_padding_0</item>
|
||||||
<item>@string/webtoon_margin_ratio_10</item>
|
<item>@string/webtoon_side_padding_10</item>
|
||||||
<item>@string/webtoon_margin_ratio_15</item>
|
<item>@string/webtoon_side_padding_15</item>
|
||||||
<item>@string/webtoon_margin_ratio_20</item>
|
<item>@string/webtoon_side_padding_20</item>
|
||||||
<item>@string/webtoon_margin_ratio_25</item>
|
<item>@string/webtoon_side_padding_25</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="webtoon_margin_ratio_values">
|
<string-array name="webtoon_side_padding_values">
|
||||||
<item>0.0</item>
|
<item>0</item>
|
||||||
<item>0.1</item>
|
<item>10</item>
|
||||||
<item>0.15</item>
|
<item>15</item>
|
||||||
<item>0.2</item>
|
<item>20</item>
|
||||||
<item>0.25</item>
|
<item>25</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="image_scale_type_values">
|
<string-array name="image_scale_type_values">
|
||||||
|
@ -241,7 +241,6 @@
|
|||||||
<string name="pref_read_with_tapping">Tapping</string>
|
<string name="pref_read_with_tapping">Tapping</string>
|
||||||
<string name="pref_read_with_long_tap">Long tap dialog</string>
|
<string name="pref_read_with_long_tap">Long tap dialog</string>
|
||||||
<string name="pref_reader_theme">Background color</string>
|
<string name="pref_reader_theme">Background color</string>
|
||||||
<string name="pref_reader_margin">Margin ratio</string>
|
|
||||||
<string name="white_background">White</string>
|
<string name="white_background">White</string>
|
||||||
<string name="black_background">Black</string>
|
<string name="black_background">Black</string>
|
||||||
<string name="pref_viewer_type">Default viewer</string>
|
<string name="pref_viewer_type">Default viewer</string>
|
||||||
@ -279,11 +278,12 @@
|
|||||||
<string name="color_filter_a_value">A</string>
|
<string name="color_filter_a_value">A</string>
|
||||||
<string name="pref_always_show_chapter_transition">Always show chapter transition</string>
|
<string name="pref_always_show_chapter_transition">Always show chapter transition</string>
|
||||||
<string name="pref_category_reading">Reading</string>
|
<string name="pref_category_reading">Reading</string>
|
||||||
<string name="webtoon_margin_ratio_0">No margin</string>
|
<string name="pref_webtoon_side_padding">Side padding</string>
|
||||||
<string name="webtoon_margin_ratio_10">10%</string>
|
<string name="webtoon_side_padding_0">No margin</string>
|
||||||
<string name="webtoon_margin_ratio_15">15%</string>
|
<string name="webtoon_side_padding_10">10%</string>
|
||||||
<string name="webtoon_margin_ratio_20">20%</string>
|
<string name="webtoon_side_padding_15">15%</string>
|
||||||
<string name="webtoon_margin_ratio_25">25%</string>
|
<string name="webtoon_side_padding_20">20%</string>
|
||||||
|
<string name="webtoon_side_padding_25">25%</string>
|
||||||
|
|
||||||
<!-- Downloads section -->
|
<!-- Downloads section -->
|
||||||
<string name="pref_download_directory">Download location</string>
|
<string name="pref_download_directory">Download location</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user