mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 09:00:46 +03:00
Also use manga per row setting in catalogue
This commit is contained in:
parent
17c59657c3
commit
638d3a32cf
2 changed files with 37 additions and 0 deletions
|
@ -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<Catalo
|
|||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CatalogueHolder {
|
||||
if (parent.id == R.id.catalogue_grid) {
|
||||
val v = parent.inflate(R.layout.item_catalogue_grid)
|
||||
v.image_container.layoutParams = RelativeLayout.LayoutParams(MATCH_PARENT, coverHeight)
|
||||
return CatalogueGridHolder(v, this, fragment)
|
||||
} else {
|
||||
val v = parent.inflate(R.layout.item_catalogue_list)
|
||||
|
@ -86,4 +91,10 @@ class CatalogueAdapter(val fragment: CatalogueFragment) : FlexibleAdapter<Catalo
|
|||
holder.onSetValues(manga)
|
||||
}
|
||||
|
||||
/**
|
||||
* Property to return the height for the covers based on the width to keep an aspect ratio.
|
||||
*/
|
||||
val coverHeight: Int
|
||||
get() = fragment.catalogue_grid.itemWidth / 3 * 4
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.ui.catalogue
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.support.v7.widget.SearchView
|
||||
|
@ -11,6 +12,7 @@ import android.widget.ArrayAdapter
|
|||
import android.widget.ProgressBar
|
||||
import android.widget.Spinner
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.f2prateek.rx.preferences.Preference
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||
|
@ -85,6 +87,11 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), 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<CataloguePresenter>(), 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<CataloguePresenter>(), FlexibleViewHold
|
|||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
numColumnsSubscription?.unsubscribe()
|
||||
searchItem?.let {
|
||||
if (it.isActionViewExpanded) it.collapseActionView()
|
||||
}
|
||||
|
@ -391,6 +405,18 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a preference for the number of manga per row based on the current orientation.
|
||||
*
|
||||
* @return the preference.
|
||||
*/
|
||||
fun getColumnsPreferenceForCurrentOrientation(): Preference<Int> {
|
||||
return if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
|
||||
presenter.prefs.portraitColumns()
|
||||
else
|
||||
presenter.prefs.landscapeColumns()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the view holder for the given manga.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue