Replace Kotlin synthetic views in viewholders

This commit is contained in:
arkon
2020-11-28 15:24:40 -05:00
parent 322d66d282
commit 749c2071af
25 changed files with 227 additions and 263 deletions
@@ -8,14 +8,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.util.isLocal
import kotlinx.android.synthetic.main.source_comfortable_grid_item.badges
import kotlinx.android.synthetic.main.source_comfortable_grid_item.card
import kotlinx.android.synthetic.main.source_comfortable_grid_item.download_text
import kotlinx.android.synthetic.main.source_comfortable_grid_item.local_text
import kotlinx.android.synthetic.main.source_comfortable_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
import kotlinx.android.synthetic.main.source_comfortable_grid_item.unread_text
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -31,6 +25,8 @@ class LibraryComfortableGridHolder(
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
) : LibraryCompactGridHolder(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view)
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@@ -39,34 +35,34 @@ class LibraryComfortableGridHolder(
*/
override fun onSetValues(item: LibraryItem) {
// Update the title of the manga.
title.text = item.manga.title
binding.title.text = item.manga.title
// For rounded corners
badges.clipToOutline = true
binding.badges.clipToOutline = true
// Update the unread count and its visibility.
with(unread_text) {
with(binding.unreadText) {
isVisible = item.unreadCount > 0
text = item.unreadCount.toString()
}
// Update the download count and its visibility.
with(download_text) {
with(binding.downloadText) {
isVisible = item.downloadCount > 0
text = item.downloadCount.toString()
}
// set local visibility if its local manga
local_text.isVisible = item.manga.isLocal()
binding.localText.isVisible = item.manga.isLocal()
// For rounded corners
card.clipToOutline = true
binding.card.clipToOutline = true
// Update the cover.
GlideApp.with(view.context).clear(thumbnail)
GlideApp.with(view.context).clear(binding.thumbnail)
GlideApp.with(view.context)
.load(item.manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.dontAnimate()
.into(thumbnail)
.into(binding.thumbnail)
}
}
@@ -6,14 +6,8 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
import eu.kanade.tachiyomi.util.isLocal
import kotlinx.android.synthetic.main.source_compact_grid_item.badges
import kotlinx.android.synthetic.main.source_compact_grid_item.card
import kotlinx.android.synthetic.main.source_compact_grid_item.download_text
import kotlinx.android.synthetic.main.source_compact_grid_item.local_text
import kotlinx.android.synthetic.main.source_compact_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_compact_grid_item.title
import kotlinx.android.synthetic.main.source_compact_grid_item.unread_text
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -29,6 +23,8 @@ open class LibraryCompactGridHolder(
private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) {
private val binding = SourceCompactGridItemBinding.bind(view)
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@@ -37,34 +33,34 @@ open class LibraryCompactGridHolder(
*/
override fun onSetValues(item: LibraryItem) {
// Update the title of the manga.
title.text = item.manga.title
binding.title.text = item.manga.title
// For rounded corners
badges.clipToOutline = true
binding.badges.clipToOutline = true
// Update the unread count and its visibility.
with(unread_text) {
with(binding.unreadText) {
isVisible = item.unreadCount > 0
text = item.unreadCount.toString()
}
// Update the download count and its visibility.
with(download_text) {
with(binding.downloadText) {
isVisible = item.downloadCount > 0
text = item.downloadCount.toString()
}
// set local visibility if its local manga
local_text.isVisible = item.manga.isLocal()
binding.localText.isVisible = item.manga.isLocal()
// For rounded corners
card.clipToOutline = true
binding.card.clipToOutline = true
// Update the cover.
GlideApp.with(view.context).clear(thumbnail)
GlideApp.with(view.context).clear(binding.thumbnail)
GlideApp.with(view.context)
.load(item.manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.dontAnimate()
.into(thumbnail)
.into(binding.thumbnail)
}
}
@@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library
import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.davidea.viewholders.FlexibleViewHolder
/**
* Generic class used to hold the displayed data of a manga in the library.
@@ -14,7 +14,7 @@ import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
abstract class LibraryHolder(
view: View,
adapter: FlexibleAdapter<*>
) : BaseFlexibleViewHolder(view, adapter) {
) : FlexibleViewHolder(view, adapter) {
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
@@ -10,13 +10,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
import eu.kanade.tachiyomi.util.isLocal
import kotlinx.android.synthetic.main.source_list_item.badges
import kotlinx.android.synthetic.main.source_list_item.download_text
import kotlinx.android.synthetic.main.source_list_item.local_text
import kotlinx.android.synthetic.main.source_list_item.thumbnail
import kotlinx.android.synthetic.main.source_list_item.title
import kotlinx.android.synthetic.main.source_list_item.unread_text
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -33,6 +28,8 @@ class LibraryListHolder(
private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) {
private val binding = SourceListItemBinding.bind(view)
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@@ -41,32 +38,32 @@ class LibraryListHolder(
*/
override fun onSetValues(item: LibraryItem) {
// Update the title of the manga.
title.text = item.manga.title
binding.title.text = item.manga.title
// For rounded corners
badges.clipToOutline = true
binding.badges.clipToOutline = true
// Update the unread count and its visibility.
with(unread_text) {
with(binding.unreadText) {
isVisible = item.unreadCount > 0
text = item.unreadCount.toString()
}
// Update the download count and its visibility.
with(download_text) {
with(binding.downloadText) {
isVisible = item.downloadCount > 0
text = "${item.downloadCount}"
}
// show local text badge if local manga
local_text.isVisible = item.manga.isLocal()
binding.localText.isVisible = item.manga.isLocal()
// Create thumbnail onclick to simulate long click
thumbnail.setOnClickListener {
binding.thumbnail.setOnClickListener {
// Simulate long click on this view to enter selection mode
onLongClick(itemView)
}
// Update the cover.
GlideApp.with(itemView.context).clear(thumbnail)
GlideApp.with(itemView.context).clear(binding.thumbnail)
val radius = view.context.resources.getDimensionPixelSize(R.dimen.card_radius)
val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
@@ -75,6 +72,6 @@ class LibraryListHolder(
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.apply(requestOptions)
.dontAnimate()
.into(thumbnail)
.into(binding.thumbnail)
}
}