mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-10 05:53:17 +02:00
Also use manga per row setting in catalogue
This commit is contained in:
parent
17c59657c3
commit
638d3a32cf
@ -1,10 +1,14 @@
|
|||||||
package eu.kanade.tachiyomi.ui.catalogue
|
package eu.kanade.tachiyomi.ui.catalogue
|
||||||
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
import android.widget.RelativeLayout
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.util.inflate
|
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.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,6 +72,7 @@ class CatalogueAdapter(val fragment: CatalogueFragment) : FlexibleAdapter<Catalo
|
|||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CatalogueHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CatalogueHolder {
|
||||||
if (parent.id == R.id.catalogue_grid) {
|
if (parent.id == R.id.catalogue_grid) {
|
||||||
val v = parent.inflate(R.layout.item_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)
|
return CatalogueGridHolder(v, this, fragment)
|
||||||
} else {
|
} else {
|
||||||
val v = parent.inflate(R.layout.item_catalogue_list)
|
val v = parent.inflate(R.layout.item_catalogue_list)
|
||||||
@ -86,4 +91,10 @@ class CatalogueAdapter(val fragment: CatalogueFragment) : FlexibleAdapter<Catalo
|
|||||||
holder.onSetValues(manga)
|
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
|
package eu.kanade.tachiyomi.ui.catalogue
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.GridLayoutManager
|
||||||
import android.support.v7.widget.SearchView
|
import android.support.v7.widget.SearchView
|
||||||
@ -11,6 +12,7 @@ import android.widget.ArrayAdapter
|
|||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import android.widget.Spinner
|
import android.widget.Spinner
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
|
import com.f2prateek.rx.preferences.Preference
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
||||||
@ -85,6 +87,11 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||||||
*/
|
*/
|
||||||
private var queryDebouncerSubscription: Subscription? = null
|
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).
|
* Display mode of the catalogue (list or grid mode).
|
||||||
*/
|
*/
|
||||||
@ -162,6 +169,12 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||||||
switcher.showNext()
|
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.inAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_in)
|
||||||
switcher.outAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_out)
|
switcher.outAnimation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_out)
|
||||||
|
|
||||||
@ -266,6 +279,7 @@ class CatalogueFragment : BaseRxFragment<CataloguePresenter>(), FlexibleViewHold
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
numColumnsSubscription?.unsubscribe()
|
||||||
searchItem?.let {
|
searchItem?.let {
|
||||||
if (it.isActionViewExpanded) it.collapseActionView()
|
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.
|
* Returns the view holder for the given manga.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user