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 128f03f39..99033f497 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 @@ -92,7 +92,7 @@ class PreferencesHelper(val context: Context) { fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.THEME_DARK_DEFAULT) - fun rotation() = rxPrefs.getInteger(Keys.rotation, 1) + fun rotation() = flowPrefs.getInt(Keys.rotation, 1) fun pageTransitions() = flowPrefs.getBoolean(Keys.enableTransitions, true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt index 2c3d7e9b3..493504aeb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/RxController.kt @@ -10,25 +10,7 @@ import rx.subscriptions.CompositeSubscription abstract class RxController(bundle: Bundle? = null) : BaseController(bundle) { - var untilDetachSubscriptions = CompositeSubscription() - private set - - var untilDestroySubscriptions = CompositeSubscription() - private set - - @CallSuper - override fun onAttach(view: View) { - super.onAttach(view) - if (untilDetachSubscriptions.isUnsubscribed) { - untilDetachSubscriptions = CompositeSubscription() - } - } - - @CallSuper - override fun onDetach(view: View) { - super.onDetach(view) - untilDetachSubscriptions.unsubscribe() - } + private var untilDestroySubscriptions = CompositeSubscription() @CallSuper override fun onViewCreated(view: View) { @@ -43,49 +25,7 @@ abstract class RxController(bundle: Bundle? = null) : BaseCont untilDestroySubscriptions.unsubscribe() } - fun Observable.subscribeUntilDetach(): Subscription { - return subscribe().also { untilDetachSubscriptions.add(it) } - } - - fun Observable.subscribeUntilDetach(onNext: (T) -> Unit): Subscription { - return subscribe(onNext).also { untilDetachSubscriptions.add(it) } - } - - fun Observable.subscribeUntilDetach( - onNext: (T) -> Unit, - onError: (Throwable) -> Unit - ): Subscription { - return subscribe(onNext, onError).also { untilDetachSubscriptions.add(it) } - } - - fun Observable.subscribeUntilDetach( - onNext: (T) -> Unit, - onError: (Throwable) -> Unit, - onCompleted: () -> Unit - ): Subscription { - return subscribe(onNext, onError, onCompleted).also { untilDetachSubscriptions.add(it) } - } - - fun Observable.subscribeUntilDestroy(): Subscription { - return subscribe().also { untilDestroySubscriptions.add(it) } - } - fun Observable.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription { return subscribe(onNext).also { untilDestroySubscriptions.add(it) } } - - fun Observable.subscribeUntilDestroy( - onNext: (T) -> Unit, - onError: (Throwable) -> Unit - ): Subscription { - return subscribe(onNext, onError).also { untilDestroySubscriptions.add(it) } - } - - fun Observable.subscribeUntilDestroy( - onNext: (T) -> Unit, - onError: (Throwable) -> Unit, - onCompleted: () -> Unit - ): Subscription { - return subscribe(onNext, onError, onCompleted).also { untilDestroySubscriptions.add(it) } - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index e1c71eea7..174eb5abc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst @@ -54,16 +55,13 @@ import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.SimpleAnimationListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import java.io.File -import java.util.concurrent.TimeUnit import kotlin.math.abs +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.sample import nucleus.factory.RequiresPresenter -import rx.Observable -import rx.android.schedulers.AndroidSchedulers -import rx.subscriptions.CompositeSubscription import timber.log.Timber import uy.kohesive.injekt.injectLazy @@ -163,7 +161,6 @@ class ReaderActivity : BaseRxActivity() super.onDestroy() viewer?.destroy() viewer = null - config?.destroy() config = null progressDialog?.dismiss() progressDialog = null @@ -606,22 +603,17 @@ class ReaderActivity : BaseRxActivity() */ private inner class ReaderConfig { - /** - * List of subscriptions to keep while the reader is alive. - */ - private val subscriptions = CompositeSubscription() - /** * Initializes the reader subscriptions. */ init { - val sharedRotation = preferences.rotation().asObservable().share() - val initialRotation = sharedRotation.take(1) - val rotationUpdates = sharedRotation.skip(1) - .delay(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread()) - - subscriptions += Observable.merge(initialRotation, rotationUpdates) - .subscribe { setOrientation(it) } + preferences.rotation().asImmediateFlow { setOrientation(it) } + .drop(1) + .onEach { + delay(250) + setOrientation(it) + } + .launchIn(scope) preferences.readerTheme().asFlow() .drop(1) // We only care about updates @@ -659,13 +651,6 @@ class ReaderActivity : BaseRxActivity() .launchIn(scope) } - /** - * Called when the reader is being destroyed. It cleans up all the subscriptions. - */ - fun destroy() { - subscriptions.unsubscribe() - } - /** * Forces the user preferred [orientation] on the activity. */