From c7f839ea4ae164cedb632946767fb0909b841c01 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 15 Apr 2021 10:09:16 -0400 Subject: [PATCH] Minor cleanup --- .../tachiyomi/ui/manga/MangaController.kt | 5 --- .../tachiyomi/ui/more/MoreController.kt | 27 +++++++++++++++ .../ui/setting/SettingsController.kt | 33 ++++--------------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 9810e64641..2ad2fd170c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -855,7 +855,6 @@ class MangaController : binding.actionToolbar.findItem(R.id.action_mark_as_unread)?.isVisible = chapters.all { it.chapter.read } // Hide FAB to avoid interfering with the bottom action toolbar - // actionFab?.hide() actionFab?.isVisible = false } return false @@ -887,10 +886,6 @@ class MangaController : chaptersAdapter?.clearSelection() selectedChapters.clear() actionMode = null - - // TODO: there seems to be a bug in MaterialComponents where the [ExtendedFloatingActionButton] - // fails to show up properly - // actionFab?.show() actionFab?.isVisible = true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 843dff2ba3..c44d844554 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -1,7 +1,11 @@ package eu.kanade.tachiyomi.ui.more import android.content.Context +import android.os.Bundle import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import androidx.preference.Preference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R @@ -26,7 +30,10 @@ import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser +import rx.Observable +import rx.Subscription import rx.android.schedulers.AndroidSchedulers +import rx.subscriptions.CompositeSubscription import uy.kohesive.injekt.injectLazy import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys @@ -39,6 +46,9 @@ class MoreController : private var isDownloading: Boolean = false private var downloadQueueSize: Int = 0 + private var untilDestroySubscriptions = CompositeSubscription() + private set + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.label_more @@ -115,6 +125,19 @@ class MoreController : } } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View { + if (untilDestroySubscriptions.isUnsubscribed) { + untilDestroySubscriptions = CompositeSubscription() + } + + return super.onCreateView(inflater, container, savedInstanceState) + } + + override fun onDestroyView(view: View) { + super.onDestroyView(view) + untilDestroySubscriptions.unsubscribe() + } + private fun initDownloadQueueSummary(preference: Preference) { // Handle running/paused status change DownloadService.runningRelay @@ -141,6 +164,10 @@ class MoreController : } } + private fun Observable.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription { + return subscribe(onNext).also { untilDestroySubscriptions.add(it) } + } + private class MoreHeaderPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : Preference(context, attrs) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index cf655f1787..9670f49a4b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -24,9 +24,6 @@ import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.coroutines.MainScope -import rx.Observable -import rx.Subscription -import rx.subscriptions.CompositeSubscription import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -36,14 +33,7 @@ abstract class SettingsController : PreferenceController() { val preferences: PreferencesHelper = Injekt.get() val viewScope = MainScope() - var untilDestroySubscriptions = CompositeSubscription() - private set - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View { - if (untilDestroySubscriptions.isUnsubscribed) { - untilDestroySubscriptions = CompositeSubscription() - } - val view = super.onCreateView(inflater, container, savedInstanceState) if (this is RootController) { @@ -77,9 +67,12 @@ abstract class SettingsController : PreferenceController() { } } - override fun onDestroyView(view: View) { - super.onDestroyView(view) - untilDestroySubscriptions.unsubscribe() + override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { + if (type.isEnter) { + setTitle() + } + setHasOptionsMenu(type.isEnter) + super.onChangeStarted(handler, type) } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { @@ -111,7 +104,7 @@ abstract class SettingsController : PreferenceController() { return preferenceScreen?.title?.toString() } - fun setTitle() { + private fun setTitle() { var parentController = parentController while (parentController != null) { if (parentController is BaseController<*> && parentController.getTitle() != null) { @@ -122,16 +115,4 @@ abstract class SettingsController : PreferenceController() { (activity as? AppCompatActivity)?.supportActionBar?.title = getTitle() } - - override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { - if (type.isEnter) { - setTitle() - } - setHasOptionsMenu(type.isEnter) - super.onChangeStarted(handler, type) - } - - fun Observable.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription { - return subscribe(onNext).also { untilDestroySubscriptions.add(it) } - } }