From 3d10dad780d7d9c1a1b9c5fa634efe710183845b Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 20 Apr 2020 18:09:03 -0400 Subject: [PATCH] Complete RxBindings to FlowBinding migration --- app/build.gradle | 7 ++----- .../tachiyomi/data/preference/PreferencesHelper.kt | 8 -------- .../kanade/tachiyomi/ui/library/LibraryController.kt | 12 +++++++----- .../tachiyomi/ui/reader/viewer/ViewerConfig.kt | 2 -- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7cbbcad73..d0ab72278 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -232,16 +232,13 @@ dependencies { } implementation 'com.github.inorichi:conductor-support-preference:a32c357' - // RxBindings - final rxbindings_version = '1.0.1' - implementation "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxbindings_version" - // FlowBinding - final flowbinding_version = '0.10.2' + final flowbinding_version = '0.11.1' implementation "io.github.reactivecircus.flowbinding:flowbinding-android:$flowbinding_version" implementation "io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowbinding_version" implementation "io.github.reactivecircus.flowbinding:flowbinding-recyclerview:$flowbinding_version" implementation "io.github.reactivecircus.flowbinding:flowbinding-swiperefreshlayout:$flowbinding_version" + implementation "io.github.reactivecircus.flowbinding:flowbinding-viewpager:$flowbinding_version" // Tests testImplementation 'junit:junit:4.13' diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 44f4490f1..aff4f37cc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -8,7 +8,6 @@ import androidx.preference.PreferenceManager import com.f2prateek.rx.preferences.Preference as RxPreference import com.f2prateek.rx.preferences.RxSharedPreferences import com.tfcporciuncula.flow.FlowSharedPreferences -import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values @@ -19,16 +18,9 @@ import java.text.DateFormat import java.text.SimpleDateFormat import java.util.Locale import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.Flow -import reactivecircus.flowbinding.common.startWithCurrentValue fun RxPreference.getOrDefault(): T = get() ?: defaultValue()!! -fun Preference.asImmediateFlow(): Flow { - return asFlow() - .startWithCurrentValue(true) { get() } -} - private class DateFormatConverter : RxPreference.Adapter { override fun get(key: String, preferences: SharedPreferences): DateFormat { val dateFormat = preferences.getString(Keys.dateFormat, "")!! diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 398889291..070b8a9aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -19,7 +19,6 @@ import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.f2prateek.rx.preferences.Preference import com.google.android.material.tabs.TabLayout -import com.jakewharton.rxbinding.support.v4.view.pageSelections import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay import eu.kanade.tachiyomi.R @@ -43,6 +42,7 @@ import kotlinx.android.synthetic.main.main_activity.tabs import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.appcompat.queryTextChanges +import reactivecircus.flowbinding.viewpager.pageSelections import rx.Subscription import timber.log.Timber import uy.kohesive.injekt.Injekt @@ -149,10 +149,12 @@ class LibraryController( adapter = LibraryAdapter(this) binding.libraryPager.adapter = adapter - binding.libraryPager.pageSelections().skip(1).subscribeUntilDestroy { - preferences.lastUsedCategory().set(it) - activeCategory = it - } + binding.libraryPager.pageSelections() + .onEach { + preferences.lastUsedCategory().set(it) + activeCategory = it + } + .launchInUI() getColumnsPreferenceForCurrentOrientation().asObservable() .doOnNext { mangaPerRow = it } 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 index 0a92c0b9a..926efeb05 100644 --- 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 @@ -3,7 +3,6 @@ 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 { @@ -16,7 +15,6 @@ abstract class ViewerConfig { ) { asFlow() .onEach { valueAssignment(it) } - .drop(1) .distinctUntilChanged() .onEach { onChanged(it) } .launchInUI()