Prechádzať zdrojové kódy

Move common view configs to parent class

arkon 5 rokov pred
rodič
commit
04a178e7da

+ 46 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ViewerConfig.kt

@@ -1,14 +1,59 @@
 package eu.kanade.tachiyomi.ui.reader.viewer
 
 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 kotlinx.coroutines.flow.distinctUntilChanged
 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 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(
         valueAssignment: (T) -> Unit,
         onChanged: (T) -> Unit = {}

+ 1 - 53
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt

@@ -1,32 +1,15 @@
 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.ui.reader.viewer.ViewerConfig
-import eu.kanade.tachiyomi.util.lang.addTo
-import rx.subscriptions.CompositeSubscription
 import uy.kohesive.injekt.Injekt
 import uy.kohesive.injekt.api.get
 
 /**
  * Configuration used by pager viewers.
  */
-
-    private val subscriptions = CompositeSubscription()
 class PagerConfig(private val viewer: PagerViewer, 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
+    ViewerConfig(preferences) {
 
     var usePageTransitions = false
         private set
@@ -43,16 +26,7 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
     var doubleTapAnimDuration = 500
         private set
 
-    var alwaysShowChapterTransition = true
-        private set
-
     init {
-        preferences.readWithTapping()
-                .register({ tappingEnabled = it })
-
-        preferences.readWithLongTap()
-                .register({ longTapEnabled = it })
-
         preferences.pageTransitions()
                 .register({ usePageTransitions = it })
 
@@ -67,32 +41,6 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
 
         preferences.doubleTapAnimSpeed()
                 .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) {

+ 8 - 45
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt

@@ -1,31 +1,14 @@
 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.ui.reader.viewer.ViewerConfig
-import eu.kanade.tachiyomi.util.lang.addTo
-import rx.subscriptions.CompositeSubscription
 import uy.kohesive.injekt.Injekt
 import uy.kohesive.injekt.api.get
 
 /**
  * Configuration used by webtoon viewers.
  */
-
-    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
+class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfig(preferences) {
 
     var imageCropBorders = false
         private set
@@ -33,52 +16,32 @@ class WebtoonConfig(preferences: PreferencesHelper = Injekt.get()) : ViewerConfi
     var doubleTapAnimDuration = 500
         private set
 
-    var alwaysShowChapterTransition = true
-        private set
-
     var sidePadding = 0
         private set
 
     init {
         preferences.readWithTapping()
-                .register({ tappingEnabled = it })
+            .register({ tappingEnabled = it })
 
         preferences.readWithLongTap()
-                .register({ longTapEnabled = it })
+            .register({ longTapEnabled = it })
 
         preferences.cropBordersWebtoon()
-                .register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
+            .register({ imageCropBorders = it }, { imagePropertyChangedListener?.invoke() })
 
         preferences.doubleTapAnimSpeed()
-                .register({ doubleTapAnimDuration = it })
+            .register({ doubleTapAnimDuration = it })
 
         preferences.readWithVolumeKeys()
-                .register({ volumeKeysEnabled = it })
+            .register({ volumeKeysEnabled = it })
 
         preferences.readWithVolumeKeysInverted()
-                .register({ volumeKeysInverted = it })
+            .register({ volumeKeysInverted = it })
 
         preferences.alwaysShowChapterTransition()
-                .register({ alwaysShowChapterTransition = it })
+            .register({ alwaysShowChapterTransition = it })
 
         preferences.webtoonSidePadding()
             .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)
-    }
 }