Grid items optimizations (#6641)
Use ConstraintLayout for ez size ratio calculation and merge cover-only view holder with compact's
This commit is contained in:
+7
-11
@@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import coil.clear
|
||||
import coil.imageLoader
|
||||
@@ -16,14 +15,14 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
|
||||
* All the elements from the layout file "item_source_grid" are available in this class.
|
||||
*
|
||||
* @param view the inflated view for this holder.
|
||||
* @param binding the inflated view for this holder.
|
||||
* @param adapter the adapter handling this holder.
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
SourceHolder<SourceComfortableGridItemBinding>(view, adapter) {
|
||||
|
||||
override val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
class SourceComfortableGridHolder(
|
||||
override val binding: SourceComfortableGridItemBinding,
|
||||
adapter: FlexibleAdapter<*>
|
||||
) : SourceHolder<SourceComfortableGridItemBinding>(binding.root, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
@@ -49,15 +48,12 @@ class SourceComfortableGridHolder(private val view: View, private val adapter: F
|
||||
}
|
||||
|
||||
override fun setImage(manga: Manga) {
|
||||
// For rounded corners
|
||||
binding.card.clipToOutline = true
|
||||
|
||||
binding.thumbnail.clear()
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
val crossfadeDuration = view.context.imageLoader.defaults.transition.let {
|
||||
val crossfadeDuration = binding.root.context.imageLoader.defaults.transition.let {
|
||||
if (it is CrossfadeTransition) it.durationMillis else 0
|
||||
}
|
||||
val request = ImageRequest.Builder(view.context)
|
||||
val request = ImageRequest.Builder(binding.root.context)
|
||||
.data(manga)
|
||||
.setParameter(MangaCoverFetcher.USE_CUSTOM_COVER, false)
|
||||
.target(StateImageViewTarget(binding.thumbnail, binding.progress, crossfadeDuration))
|
||||
|
||||
+7
-11
@@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import coil.clear
|
||||
import coil.imageLoader
|
||||
@@ -16,14 +15,14 @@ import eu.kanade.tachiyomi.widget.StateImageViewTarget
|
||||
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
|
||||
* All the elements from the layout file "item_source_grid" are available in this class.
|
||||
*
|
||||
* @param view the inflated view for this holder.
|
||||
* @param binding the inflated view for this holder.
|
||||
* @param adapter the adapter handling this holder.
|
||||
* @constructor creates a new catalogue holder.
|
||||
*/
|
||||
open class SourceCompactGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
SourceHolder<SourceCompactGridItemBinding>(view, adapter) {
|
||||
|
||||
override val binding = SourceCompactGridItemBinding.bind(view)
|
||||
class SourceCompactGridHolder(
|
||||
override val binding: SourceCompactGridItemBinding,
|
||||
adapter: FlexibleAdapter<*>
|
||||
) : SourceHolder<SourceCompactGridItemBinding>(binding.root, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
@@ -49,15 +48,12 @@ open class SourceCompactGridHolder(private val view: View, private val adapter:
|
||||
}
|
||||
|
||||
override fun setImage(manga: Manga) {
|
||||
// For rounded corners
|
||||
binding.card.clipToOutline = true
|
||||
|
||||
binding.thumbnail.clear()
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
val crossfadeDuration = view.context.imageLoader.defaults.transition.let {
|
||||
val crossfadeDuration = binding.root.context.imageLoader.defaults.transition.let {
|
||||
if (it is CrossfadeTransition) it.durationMillis else 0
|
||||
}
|
||||
val request = ImageRequest.Builder(view.context)
|
||||
val request = ImageRequest.Builder(binding.root.context)
|
||||
.data(manga)
|
||||
.setParameter(MangaCoverFetcher.USE_CUSTOM_COVER, false)
|
||||
.target(StateImageViewTarget(binding.thumbnail, binding.progress, crossfadeDuration))
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.widget.FrameLayout
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
@@ -15,16 +11,15 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
|
||||
import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
|
||||
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting
|
||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||
|
||||
class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayModeSetting>) :
|
||||
AbstractFlexibleItem<SourceHolder<*>>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return when (displayMode.get()) {
|
||||
DisplayModeSetting.LIST -> R.layout.source_list_item
|
||||
DisplayModeSetting.COMPACT_GRID, DisplayModeSetting.COVER_ONLY_GRID -> R.layout.source_compact_grid_item
|
||||
DisplayModeSetting.COMFORTABLE_GRID -> R.layout.source_comfortable_grid_item
|
||||
else -> R.layout.source_compact_grid_item
|
||||
DisplayModeSetting.LIST -> R.layout.source_list_item
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,37 +28,14 @@ class SourceItem(val manga: Manga, private val displayMode: Preference<DisplayMo
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
|
||||
): SourceHolder<*> {
|
||||
return when (displayMode.get()) {
|
||||
DisplayModeSetting.LIST -> {
|
||||
SourceListHolder(view, adapter)
|
||||
DisplayModeSetting.COMPACT_GRID, DisplayModeSetting.COVER_ONLY_GRID -> {
|
||||
SourceCompactGridHolder(SourceCompactGridItemBinding.bind(view), adapter)
|
||||
}
|
||||
DisplayModeSetting.COMFORTABLE_GRID -> {
|
||||
val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
binding.card.layoutParams = ConstraintLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
}
|
||||
SourceComfortableGridHolder(view, adapter)
|
||||
SourceComfortableGridHolder(SourceComfortableGridItemBinding.bind(view), adapter)
|
||||
}
|
||||
else -> {
|
||||
val binding = SourceCompactGridItemBinding.bind(view)
|
||||
val parent = adapter.recyclerView as AutofitRecyclerView
|
||||
val coverHeight = parent.itemWidth / 3 * 4
|
||||
view.apply {
|
||||
binding.card.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight
|
||||
)
|
||||
binding.gradient.layoutParams = FrameLayout.LayoutParams(
|
||||
MATCH_PARENT,
|
||||
coverHeight / 2,
|
||||
Gravity.BOTTOM
|
||||
)
|
||||
}
|
||||
SourceCompactGridHolder(view, adapter)
|
||||
DisplayModeSetting.LIST -> {
|
||||
SourceListHolder(view, adapter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user