From 638d3a32cf047f5e1bbbb7973e25ffaa6c6c064c Mon Sep 17 00:00:00 2001 From: len Date: Mon, 18 Apr 2016 20:33:09 +0200 Subject: [PATCH] Also use manga per row setting in catalogue --- .../ui/catalogue/CatalogueAdapter.kt | 11 ++++++++ .../ui/catalogue/CatalogueFragment.kt | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueAdapter.kt index 8999873339..c5b3a1c262 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueAdapter.kt @@ -1,10 +1,14 @@ package eu.kanade.tachiyomi.ui.catalogue import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.widget.RelativeLayout import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.util.inflate +import kotlinx.android.synthetic.main.fragment_catalogue.* +import kotlinx.android.synthetic.main.item_catalogue_grid.view.* import java.util.* /** @@ -68,6 +72,7 @@ class CatalogueAdapter(val fragment: CatalogueFragment) : FlexibleAdapter(), FlexibleViewHold */ private var queryDebouncerSubscription: Subscription? = null + /** + * Subscription of the number of manga per row. + */ + private var numColumnsSubscription: Subscription? = null + /** * Display mode of the catalogue (list or grid mode). */ @@ -162,6 +169,12 @@ class CatalogueFragment : BaseRxFragment(), FlexibleViewHold switcher.showNext() } + numColumnsSubscription = getColumnsPreferenceForCurrentOrientation().asObservable() + .doOnNext { catalogue_grid.spanCount = it } + .skip(1) + // Set again the adapter to recalculate the covers height + .subscribe { catalogue_grid.adapter = adapter } + switcher.inAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_in) switcher.outAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_out) @@ -266,6 +279,7 @@ class CatalogueFragment : BaseRxFragment(), FlexibleViewHold } override fun onDestroyView() { + numColumnsSubscription?.unsubscribe() searchItem?.let { if (it.isActionViewExpanded) it.collapseActionView() } @@ -391,6 +405,18 @@ class CatalogueFragment : BaseRxFragment(), FlexibleViewHold } } + /** + * Returns a preference for the number of manga per row based on the current orientation. + * + * @return the preference. + */ + fun getColumnsPreferenceForCurrentOrientation(): Preference { + return if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) + presenter.prefs.portraitColumns() + else + presenter.prefs.landscapeColumns() + } + /** * Returns the view holder for the given manga. *