From 678c004a641873970dc3be6ae229c8c608c00621 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Apr 2020 20:10:29 -0400 Subject: [PATCH] Add parent class for view configs --- .../ui/reader/viewer/ViewerConfig.kt | 24 +++++++++++++++++++ .../ui/reader/viewer/pager/PagerConfig.kt | 6 ++--- .../ui/reader/viewer/webtoon/WebtoonConfig.kt | 5 ++-- 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt new file mode 100644 index 000000000..0a92c0b9a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.ui.reader.viewer + +import com.tfcporciuncula.flow.Preference +import eu.kanade.tachiyomi.util.lang.launchInUI +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.onEach + +abstract class ViewerConfig { + + var imagePropertyChangedListener: (() -> Unit)? = null + + fun Preference.register( + valueAssignment: (T) -> Unit, + onChanged: (T) -> Unit = {} + ) { + asFlow() + .onEach { valueAssignment(it) } + .drop(1) + .distinctUntilChanged() + .onEach { onChanged(it) } + .launchInUI() + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index 2ac6eab10..a95d29c64 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -4,17 +4,17 @@ import com.f2prateek.rx.preferences.Preference import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.lang.addTo import rx.subscriptions.CompositeSubscription +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get /** * Configuration used by pager viewers. */ -class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelper = Injekt.get()) { private val subscriptions = CompositeSubscription() - - var imagePropertyChangedListener: (() -> Unit)? = null +class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelper = Injekt.get()) : + ViewerConfig() { var tappingEnabled = true private set 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 2f348382d..98fa704cf 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 @@ -4,17 +4,16 @@ import com.f2prateek.rx.preferences.Preference import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.lang.addTo import rx.subscriptions.CompositeSubscription +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get /** * Configuration used by webtoon viewers. */ -class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) { private val subscriptions = CompositeSubscription() - - var imagePropertyChangedListener: (() -> Unit)? = null +class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfig() { var tappingEnabled = true private set