Add view caching to view holders

This commit is contained in:
inorichi
2017-12-03 17:00:32 +01:00
parent d94dc68830
commit 8bcb14c65d
21 changed files with 183 additions and 171 deletions
@@ -5,7 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.source.LocalSource
import kotlinx.android.synthetic.main.catalogue_grid_item.view.*
import kotlinx.android.synthetic.main.catalogue_grid_item.*
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -30,30 +30,28 @@ class LibraryGridHolder(
*/
override fun onSetValues(item: LibraryItem) {
// Update the title of the manga.
view.title.text = item.manga.title
title.text = item.manga.title
// Update the unread count and its visibility.
with(view.unread_text) {
with(unread_text) {
visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE
text = item.manga.unread.toString()
}
// Update the download count and its visibility.
with(view.download_text) {
with(download_text) {
visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE
text = item.downloadCount.toString()
}
//set local visibility if its local manga
with(view.local_text) {
visibility = if(item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE
}
local_text.visibility = if(item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE
// Update the cover.
GlideApp.with(view.context).clear(view.thumbnail)
GlideApp.with(view.context).clear(thumbnail)
GlideApp.with(view.context)
.load(item.manga)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.into(view.thumbnail)
.into(thumbnail)
}
}
@@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library
import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
/**
* Generic class used to hold the displayed data of a manga in the library.
@@ -14,7 +14,7 @@ import eu.davidea.viewholders.FlexibleViewHolder
abstract class LibraryHolder(
view: View,
adapter: FlexibleAdapter<*>
) : FlexibleViewHolder(view, adapter) {
) : BaseFlexibleViewHolder(view, adapter) {
/**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
@@ -5,7 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.source.LocalSource
import kotlinx.android.synthetic.main.catalogue_list_item.view.*
import kotlinx.android.synthetic.main.catalogue_list_item.*
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@@ -30,38 +30,36 @@ class LibraryListHolder(
*/
override fun onSetValues(item: LibraryItem) {
// Update the title of the manga.
itemView.title.text = item.manga.title
title.text = item.manga.title
// Update the unread count and its visibility.
with(itemView.unread_text) {
with(unread_text) {
visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE
text = item.manga.unread.toString()
}
// Update the download count and its visibility.
with(itemView.download_text) {
with(download_text) {
visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE
text = "${item.downloadCount}"
}
//show local text badge if local manga
with(itemView.local_text) {
visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE
}
local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE
// Create thumbnail onclick to simulate long click
itemView.thumbnail.setOnClickListener {
thumbnail.setOnClickListener {
// Simulate long click on this view to enter selection mode
onLongClick(itemView)
}
// Update the cover.
GlideApp.with(itemView.context).clear(itemView.thumbnail)
GlideApp.with(itemView.context).clear(thumbnail)
GlideApp.with(itemView.context)
.load(item.manga)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.circleCrop()
.dontAnimate()
.into(itemView.thumbnail)
.into(thumbnail)
}
}