mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-29 23:23:43 -05:00
Move common view configs to parent class
This commit is contained in:
parent
6d5b6b2ff7
commit
04a178e7da
3 changed files with 55 additions and 99 deletions
|
@ -1,14 +1,59 @@
|
||||||
package eu.kanade.tachiyomi.ui.reader.viewer
|
package eu.kanade.tachiyomi.ui.reader.viewer
|
||||||
|
|
||||||
import com.tfcporciuncula.flow.Preference
|
import com.tfcporciuncula.flow.Preference
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.util.lang.addTo
|
||||||
import eu.kanade.tachiyomi.util.lang.launchInUI
|
import eu.kanade.tachiyomi.util.lang.launchInUI
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import rx.subscriptions.CompositeSubscription
|
||||||
|
|
||||||
abstract class ViewerConfig {
|
abstract class ViewerConfig(preferences: PreferencesHelper) {
|
||||||
|
|
||||||
|
private val subscriptions = CompositeSubscription()
|
||||||
|
|
||||||
var imagePropertyChangedListener: (() -> Unit)? = null
|
var imagePropertyChangedListener: (() -> Unit)? = null
|
||||||
|
|
||||||
|
var tappingEnabled = true
|
||||||
|
var longTapEnabled = true
|
||||||
|
var volumeKeysEnabled = false
|
||||||
|
var volumeKeysInverted = false
|
||||||
|
var alwaysShowChapterTransition = true
|
||||||
|
|
||||||
|
init {
|
||||||
|
preferences.readWithTapping()
|
||||||
|
.register({ tappingEnabled = it })
|
||||||
|
|
||||||
|
preferences.readWithLongTap()
|
||||||
|
.register({ longTapEnabled = it })
|
||||||
|
|
||||||
|
preferences.readWithVolumeKeys()
|
||||||
|
.register({ volumeKeysEnabled = it })
|
||||||
|
|
||||||
|
preferences.readWithVolumeKeysInverted()
|
||||||
|
.register({ volumeKeysInverted = it })
|
||||||
|
|
||||||
|
preferences.alwaysShowChapterTransition()
|
||||||
|
.register({ alwaysShowChapterTransition = it })
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unsubscribe() {
|
||||||
|
subscriptions.unsubscribe()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> com.f2prateek.rx.preferences.Preference<T>.register(
|
||||||
|
valueAssignment: (T) -> Unit,
|
||||||
|
onChanged: (T) -> Unit = {}
|
||||||
|
) {
|
||||||
|
asObservable()
|
||||||
|
.doOnNext(valueAssignment)
|
||||||
|
.skip(1)
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.doOnNext(onChanged)
|
||||||
|
.subscribe()
|
||||||
|
.addTo(subscriptions)
|
||||||
|
}
|
||||||
|
|
||||||
fun <T> Preference<T>.register(
|
fun <T> Preference<T>.register(
|
||||||
valueAssignment: (T) -> Unit,
|
valueAssignment: (T) -> Unit,
|
||||||
onChanged: (T) -> Unit = {}
|
onChanged: (T) -> Unit = {}
|
||||||
|
|
|
@ -1,32 +1,15 @@
|
||||||
package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
||||||
|
|
||||||
import com.f2prateek.rx.preferences.Preference
|
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
||||||
import eu.kanade.tachiyomi.util.lang.addTo
|
|
||||||
import rx.subscriptions.CompositeSubscription
|
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration used by pager viewers.
|
* Configuration used by pager viewers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private val subscriptions = CompositeSubscription()
|
|
||||||
class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelper = Injekt.get()) :
|
class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelper = Injekt.get()) :
|
||||||
ViewerConfig() {
|
ViewerConfig(preferences) {
|
||||||
|
|
||||||
var tappingEnabled = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
var longTapEnabled = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
var volumeKeysEnabled = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
var volumeKeysInverted = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
var usePageTransitions = false
|
var usePageTransitions = false
|
||||||
private set
|
private set
|
||||||
|
@ -43,16 +26,7 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||||
var doubleTapAnimDuration = 500
|
var doubleTapAnimDuration = 500
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var alwaysShowChapterTransition = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
preferences.readWithTapping()
|
|
||||||
.register({ tappingEnabled = it })
|
|
||||||
|
|
||||||
preferences.readWithLongTap()
|
|
||||||
.register({ longTapEnabled = it })
|
|
||||||
|
|
||||||
preferences.pageTransitions()
|
preferences.pageTransitions()
|
||||||
.register({ usePageTransitions = it })
|
.register({ usePageTransitions = it })
|
||||||
|
|
||||||
|
@ -67,32 +41,6 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||||
|
|
||||||
preferences.doubleTapAnimSpeed()
|
preferences.doubleTapAnimSpeed()
|
||||||
.register({ doubleTapAnimDuration = it })
|
.register({ doubleTapAnimDuration = it })
|
||||||
|
|
||||||
preferences.readWithVolumeKeys()
|
|
||||||
.register({ volumeKeysEnabled = it })
|
|
||||||
|
|
||||||
preferences.readWithVolumeKeysInverted()
|
|
||||||
.register({ volumeKeysInverted = it })
|
|
||||||
|
|
||||||
preferences.alwaysShowChapterTransition()
|
|
||||||
.register({ alwaysShowChapterTransition = it })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unsubscribe() {
|
|
||||||
subscriptions.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> Preference<T>.register(
|
|
||||||
valueAssignment: (T) -> Unit,
|
|
||||||
onChanged: (T) -> Unit = {}
|
|
||||||
) {
|
|
||||||
asObservable()
|
|
||||||
.doOnNext(valueAssignment)
|
|
||||||
.skip(1)
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.doOnNext(onChanged)
|
|
||||||
.subscribe()
|
|
||||||
.addTo(subscriptions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun zoomTypeFromPreference(value: Int) {
|
private fun zoomTypeFromPreference(value: Int) {
|
||||||
|
|
|
@ -1,31 +1,14 @@
|
||||||
package eu.kanade.tachiyomi.ui.reader.viewer.webtoon
|
package eu.kanade.tachiyomi.ui.reader.viewer.webtoon
|
||||||
|
|
||||||
import com.f2prateek.rx.preferences.Preference
|
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
||||||
import eu.kanade.tachiyomi.util.lang.addTo
|
|
||||||
import rx.subscriptions.CompositeSubscription
|
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration used by webtoon viewers.
|
* Configuration used by webtoon viewers.
|
||||||
*/
|
*/
|
||||||
|
class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfig(preferences) {
|
||||||
private val subscriptions = CompositeSubscription()
|
|
||||||
class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfig() {
|
|
||||||
|
|
||||||
var tappingEnabled = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
var longTapEnabled = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
var volumeKeysEnabled = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
var volumeKeysInverted = false
|
|
||||||
private set
|
|
||||||
|
|
||||||
var imageCropBorders = false
|
var imageCropBorders = false
|
||||||
private set
|
private set
|
||||||
|
@ -33,52 +16,32 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfi
|
||||||
var doubleTapAnimDuration = 500
|
var doubleTapAnimDuration = 500
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var alwaysShowChapterTransition = true
|
|
||||||
private set
|
|
||||||
|
|
||||||
var sidePadding = 0
|
var sidePadding = 0
|
||||||
private set
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
preferences.readWithTapping()
|
preferences.readWithTapping()
|
||||||
.register({ tappingEnabled = it })
|
.register({ tappingEnabled = it })
|
||||||
|
|
||||||
preferences.readWithLongTap()
|
preferences.readWithLongTap()
|
||||||
.register({ longTapEnabled = it })
|
.register({ longTapEnabled = it })
|
||||||
|
|
||||||
preferences.cropBordersWebtoon()
|
preferences.cropBordersWebtoon()
|
||||||
.register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
|
.register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
|
||||||
|
|
||||||
preferences.doubleTapAnimSpeed()
|
preferences.doubleTapAnimSpeed()
|
||||||
.register({ doubleTapAnimDuration = it })
|
.register({ doubleTapAnimDuration = it })
|
||||||
|
|
||||||
preferences.readWithVolumeKeys()
|
preferences.readWithVolumeKeys()
|
||||||
.register({ volumeKeysEnabled = it })
|
.register({ volumeKeysEnabled = it })
|
||||||
|
|
||||||
preferences.readWithVolumeKeysInverted()
|
preferences.readWithVolumeKeysInverted()
|
||||||
.register({ volumeKeysInverted = it })
|
.register({ volumeKeysInverted = it })
|
||||||
|
|
||||||
preferences.alwaysShowChapterTransition()
|
preferences.alwaysShowChapterTransition()
|
||||||
.register({ alwaysShowChapterTransition = it })
|
.register({ alwaysShowChapterTransition = it })
|
||||||
|
|
||||||
preferences.webtoonSidePadding()
|
preferences.webtoonSidePadding()
|
||||||
.register({ sidePadding = it }, { imagePropertyChangedListener?.invoke() })
|
.register({ sidePadding = it }, { imagePropertyChangedListener?.invoke() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unsubscribe() {
|
|
||||||
subscriptions.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> Preference<T>.register(
|
|
||||||
valueAssignment: (T) -> Unit,
|
|
||||||
onChanged: (T) -> Unit = {}
|
|
||||||
) {
|
|
||||||
asObservable()
|
|
||||||
.doOnNext(valueAssignment)
|
|
||||||
.skip(1)
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.doOnNext(onChanged)
|
|
||||||
.subscribe()
|
|
||||||
.addTo(subscriptions)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue