parent
e0b7698d40
commit
64c47bbaed
@ -0,0 +1,106 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.reader.setting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.core.widget.NestedScrollView
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||||
|
import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer
|
||||||
|
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
|
||||||
|
import eu.kanade.tachiyomi.util.preference.bindToIntPreference
|
||||||
|
import eu.kanade.tachiyomi.util.preference.bindToPreference
|
||||||
|
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet to show reader and viewer preferences.
|
||||||
|
*/
|
||||||
|
class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
|
NestedScrollView(context, attrs) {
|
||||||
|
|
||||||
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
|
private val binding = ReaderReadingModeSettingsBinding.inflate(LayoutInflater.from(context), this, false)
|
||||||
|
|
||||||
|
init {
|
||||||
|
addView(binding.root)
|
||||||
|
|
||||||
|
initGeneralPreferences()
|
||||||
|
|
||||||
|
when ((context as ReaderActivity).viewer) {
|
||||||
|
is PagerViewer -> initPagerPreferences()
|
||||||
|
is WebtoonViewer -> initWebtoonPreferences()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init general reader preferences.
|
||||||
|
*/
|
||||||
|
private fun initGeneralPreferences() {
|
||||||
|
binding.viewer.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||||
|
(context as ReaderActivity).presenter.setMangaViewer(position)
|
||||||
|
|
||||||
|
val mangaViewer = (context as ReaderActivity).presenter.getMangaViewer()
|
||||||
|
if (mangaViewer == ReadingModeType.WEBTOON.prefValue || mangaViewer == ReadingModeType.CONTINUOUS_VERTICAL.prefValue) {
|
||||||
|
initWebtoonPreferences()
|
||||||
|
} else {
|
||||||
|
initPagerPreferences()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binding.viewer.setSelection((context as ReaderActivity).presenter.manga?.viewer ?: 0, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init the preferences for the pager reader.
|
||||||
|
*/
|
||||||
|
private fun initPagerPreferences() {
|
||||||
|
binding.webtoonPrefsGroup.root.isVisible = false
|
||||||
|
binding.pagerPrefsGroup.root.isVisible = true
|
||||||
|
|
||||||
|
binding.pagerPrefsGroup.tappingPrefsGroup.isVisible = preferences.readWithTapping().get()
|
||||||
|
|
||||||
|
binding.pagerPrefsGroup.tappingInverted.bindToPreference(preferences.pagerNavInverted())
|
||||||
|
|
||||||
|
binding.pagerPrefsGroup.pagerNav.bindToPreference(preferences.navigationModePager())
|
||||||
|
binding.pagerPrefsGroup.scaleType.bindToPreference(preferences.imageScaleType(), 1)
|
||||||
|
binding.pagerPrefsGroup.zoomStart.bindToPreference(preferences.zoomStart(), 1)
|
||||||
|
binding.pagerPrefsGroup.cropBorders.bindToPreference(preferences.cropBorders())
|
||||||
|
|
||||||
|
// Makes so that dual page invert gets hidden away when turning of dual page split
|
||||||
|
binding.pagerPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitPaged())
|
||||||
|
preferences.dualPageSplitPaged()
|
||||||
|
.asImmediateFlow { binding.pagerPrefsGroup.dualPageInvert.isVisible = it }
|
||||||
|
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||||
|
binding.pagerPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertPaged())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init the preferences for the webtoon reader.
|
||||||
|
*/
|
||||||
|
private fun initWebtoonPreferences() {
|
||||||
|
binding.pagerPrefsGroup.root.isVisible = false
|
||||||
|
binding.webtoonPrefsGroup.root.isVisible = true
|
||||||
|
|
||||||
|
binding.webtoonPrefsGroup.tappingPrefsGroup.isVisible = preferences.readWithTapping().get()
|
||||||
|
|
||||||
|
binding.webtoonPrefsGroup.tappingInverted.bindToPreference(preferences.webtoonNavInverted())
|
||||||
|
|
||||||
|
binding.webtoonPrefsGroup.webtoonNav.bindToPreference(preferences.navigationModeWebtoon())
|
||||||
|
binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon())
|
||||||
|
binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values)
|
||||||
|
|
||||||
|
// Makes so that dual page invert gets hidden away when turning of dual page split
|
||||||
|
binding.webtoonPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitWebtoon())
|
||||||
|
preferences.dualPageSplitWebtoon()
|
||||||
|
.asImmediateFlow { binding.webtoonPrefsGroup.dualPageInvert.isVisible = it }
|
||||||
|
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||||
|
binding.webtoonPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertWebtoon())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package eu.kanade.tachiyomi.util.preference
|
||||||
|
|
||||||
|
import android.widget.CompoundButton
|
||||||
|
import android.widget.Spinner
|
||||||
|
import androidx.annotation.ArrayRes
|
||||||
|
import com.tfcporciuncula.flow.Preference
|
||||||
|
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a checkbox or switch view with a boolean preference.
|
||||||
|
*/
|
||||||
|
fun CompoundButton.bindToPreference(pref: Preference<Boolean>) {
|
||||||
|
isChecked = pref.get()
|
||||||
|
setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a spinner to an int preference with an optional offset for the value.
|
||||||
|
*/
|
||||||
|
fun Spinner.bindToPreference(pref: Preference<Int>, offset: Int = 0) {
|
||||||
|
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||||
|
pref.set(position + offset)
|
||||||
|
}
|
||||||
|
setSelection(pref.get() - offset, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a spinner to an enum preference.
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Enum<T>> Spinner.bindToPreference(pref: Preference<T>) {
|
||||||
|
val enumConstants = T::class.java.enumConstants
|
||||||
|
|
||||||
|
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||||
|
enumConstants?.get(position)?.let { pref.set(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
enumConstants?.indexOf(pref.get())?.let { setSelection(it, false) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a spinner to an int preference. The position of the spinner item must
|
||||||
|
* correlate with the [intValues] resource item (in arrays.xml), which is a <string-array>
|
||||||
|
* of int values that will be parsed here and applied to the preference.
|
||||||
|
*/
|
||||||
|
fun Spinner.bindToIntPreference(pref: Preference<Int>, @ArrayRes intValuesResource: Int) {
|
||||||
|
val intValues = resources.getStringArray(intValuesResource).map { it.toIntOrNull() }
|
||||||
|
onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
|
||||||
|
pref.set(intValues[position]!!)
|
||||||
|
}
|
||||||
|
setSelection(intValues.indexOf(pref.get()), false)
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<android.widget.Space
|
||||||
|
android:id="@+id/spinner_end"
|
||||||
|
android:layout_width="16dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintStart_toEndOf="parent"
|
||||||
|
tools:ignore="MissingConstraints" />
|
||||||
|
|
||||||
|
<!-- Series-specific preferences -->
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/series_prefs"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pref_category_for_this_series"
|
||||||
|
android:textColor="?attr/colorAccent"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/viewer_text"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/viewer"
|
||||||
|
app:layout_constraintBaseline_toBaselineOf="@id/viewer"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/verticalcenter"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatSpinner
|
||||||
|
android:id="@+id/viewer"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:entries="@array/viewers_selector"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/spinner_end"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/verticalcenter"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/series_prefs" />
|
||||||
|
|
||||||
|
<!-- Pager preferences -->
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/pager_prefs_group"
|
||||||
|
layout="@layout/reader_pager_settings"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/viewer"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<!-- Webtoon preferences -->
|
||||||
|
|
||||||
|
<include
|
||||||
|
android:id="@+id/webtoon_prefs_group"
|
||||||
|
layout="@layout/reader_webtoon_settings"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/viewer" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Guideline
|
||||||
|
android:id="@+id/verticalcenter"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintGuide_percent="0.5" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
Loading…
Reference in new issue