mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Convert rotation to FlowPreference, remove some unused subscriptions code
This commit is contained in:
parent
a94fd24fa9
commit
d46a742a43
@ -92,7 +92,7 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.THEME_DARK_DEFAULT)
|
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)
|
fun pageTransitions() = flowPrefs.getBoolean(Keys.enableTransitions, true)
|
||||||
|
|
||||||
|
@ -10,25 +10,7 @@ import rx.subscriptions.CompositeSubscription
|
|||||||
|
|
||||||
abstract class RxController<VB : ViewBinding>(bundle: Bundle? = null) : BaseController<VB>(bundle) {
|
abstract class RxController<VB : ViewBinding>(bundle: Bundle? = null) : BaseController<VB>(bundle) {
|
||||||
|
|
||||||
var untilDetachSubscriptions = CompositeSubscription()
|
private var untilDestroySubscriptions = 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()
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onViewCreated(view: View) {
|
override fun onViewCreated(view: View) {
|
||||||
@ -43,49 +25,7 @@ abstract class RxController<VB : ViewBinding>(bundle: Bundle? = null) : BaseCont
|
|||||||
untilDestroySubscriptions.unsubscribe()
|
untilDestroySubscriptions.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDetach(): Subscription {
|
|
||||||
return subscribe().also { untilDetachSubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDetach(onNext: (T) -> Unit): Subscription {
|
|
||||||
return subscribe(onNext).also { untilDetachSubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDetach(
|
|
||||||
onNext: (T) -> Unit,
|
|
||||||
onError: (Throwable) -> Unit
|
|
||||||
): Subscription {
|
|
||||||
return subscribe(onNext, onError).also { untilDetachSubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDetach(
|
|
||||||
onNext: (T) -> Unit,
|
|
||||||
onError: (Throwable) -> Unit,
|
|
||||||
onCompleted: () -> Unit
|
|
||||||
): Subscription {
|
|
||||||
return subscribe(onNext, onError, onCompleted).also { untilDetachSubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDestroy(): Subscription {
|
|
||||||
return subscribe().also { untilDestroySubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription {
|
fun <T> Observable<T>.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription {
|
||||||
return subscribe(onNext).also { untilDestroySubscriptions.add(it) }
|
return subscribe(onNext).also { untilDestroySubscriptions.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDestroy(
|
|
||||||
onNext: (T) -> Unit,
|
|
||||||
onError: (Throwable) -> Unit
|
|
||||||
): Subscription {
|
|
||||||
return subscribe(onNext, onError).also { untilDestroySubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Observable<T>.subscribeUntilDestroy(
|
|
||||||
onNext: (T) -> Unit,
|
|
||||||
onError: (Throwable) -> Unit,
|
|
||||||
onCompleted: () -> Unit
|
|
||||||
): Subscription {
|
|
||||||
return subscribe(onNext, onError, onCompleted).also { untilDestroySubscriptions.add(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||||
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
|
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst
|
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.SimpleAnimationListener
|
||||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.drop
|
import kotlinx.coroutines.flow.drop
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
import nucleus.factory.RequiresPresenter
|
import nucleus.factory.RequiresPresenter
|
||||||
import rx.Observable
|
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
|
||||||
import rx.subscriptions.CompositeSubscription
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
@ -163,7 +161,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
viewer?.destroy()
|
viewer?.destroy()
|
||||||
viewer = null
|
viewer = null
|
||||||
config?.destroy()
|
|
||||||
config = null
|
config = null
|
||||||
progressDialog?.dismiss()
|
progressDialog?.dismiss()
|
||||||
progressDialog = null
|
progressDialog = null
|
||||||
@ -606,22 +603,17 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|||||||
*/
|
*/
|
||||||
private inner class ReaderConfig {
|
private inner class ReaderConfig {
|
||||||
|
|
||||||
/**
|
|
||||||
* List of subscriptions to keep while the reader is alive.
|
|
||||||
*/
|
|
||||||
private val subscriptions = CompositeSubscription()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the reader subscriptions.
|
* Initializes the reader subscriptions.
|
||||||
*/
|
*/
|
||||||
init {
|
init {
|
||||||
val sharedRotation = preferences.rotation().asObservable().share()
|
preferences.rotation().asImmediateFlow { setOrientation(it) }
|
||||||
val initialRotation = sharedRotation.take(1)
|
.drop(1)
|
||||||
val rotationUpdates = sharedRotation.skip(1)
|
.onEach {
|
||||||
.delay(250, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
|
delay(250)
|
||||||
|
setOrientation(it)
|
||||||
subscriptions += Observable.merge(initialRotation, rotationUpdates)
|
}
|
||||||
.subscribe { setOrientation(it) }
|
.launchIn(scope)
|
||||||
|
|
||||||
preferences.readerTheme().asFlow()
|
preferences.readerTheme().asFlow()
|
||||||
.drop(1) // We only care about updates
|
.drop(1) // We only care about updates
|
||||||
@ -659,13 +651,6 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
|||||||
.launchIn(scope)
|
.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.
|
* Forces the user preferred [orientation] on the activity.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user