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

View File

@ -1,16 +0,0 @@
package eu.kanade.tachiyomi.ui.base.holder
import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder
import kotlinx.android.extensions.LayoutContainer
abstract class BaseFlexibleViewHolder(
view: View,
adapter: FlexibleAdapter<*>,
stickyHeader: Boolean = false
) : FlexibleViewHolder(view, adapter, stickyHeader), LayoutContainer {
override val containerView: View?
get() = itemView
}

View File

@ -3,11 +3,13 @@ package eu.kanade.tachiyomi.ui.browse.extension
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.view.View import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import kotlinx.android.synthetic.main.source_main_controller_card_header.title import eu.kanade.tachiyomi.databinding.SourceMainControllerCardHeaderBinding
class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) : class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = SourceMainControllerCardHeaderBinding.bind(view)
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
fun bind(item: ExtensionGroupItem) { fun bind(item: ExtensionGroupItem) {
@ -16,6 +18,6 @@ class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) :
text += " (${item.size})" text += " (${item.size})"
} }
title.text = text binding.title.text = text
} }
} }

View File

@ -1,24 +1,21 @@
package eu.kanade.tachiyomi.ui.browse.extension package eu.kanade.tachiyomi.ui.browse.extension
import android.view.View import android.view.View
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.databinding.ExtensionCardItemBinding
import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.Extension
import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.InstallStep
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.android.synthetic.main.extension_card_item.ext_button
import kotlinx.android.synthetic.main.extension_card_item.ext_title
import kotlinx.android.synthetic.main.extension_card_item.image
import kotlinx.android.synthetic.main.extension_card_item.lang
import kotlinx.android.synthetic.main.extension_card_item.version
import kotlinx.android.synthetic.main.extension_card_item.warning
class ExtensionHolder(view: View, val adapter: ExtensionAdapter) : class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = ExtensionCardItemBinding.bind(view)
init { init {
ext_button.setOnClickListener { binding.extButton.setOnClickListener {
adapter.buttonClickListener.onButtonClick(bindingAdapterPosition) adapter.buttonClickListener.onButtonClick(bindingAdapterPosition)
} }
} }
@ -26,10 +23,10 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
fun bind(item: ExtensionItem) { fun bind(item: ExtensionItem) {
val extension = item.extension val extension = item.extension
ext_title.text = extension.name binding.extTitle.text = extension.name
version.text = extension.versionName binding.version.text = extension.versionName
lang.text = LocaleHelper.getSourceDisplayName(extension.lang, itemView.context) binding.lang.text = LocaleHelper.getSourceDisplayName(extension.lang, itemView.context)
warning.text = when { binding.warning.text = when {
extension is Extension.Untrusted -> itemView.context.getString(R.string.ext_untrusted) extension is Extension.Untrusted -> itemView.context.getString(R.string.ext_untrusted)
extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.ext_obsolete) extension is Extension.Installed && extension.isObsolete -> itemView.context.getString(R.string.ext_obsolete)
extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.ext_unofficial) extension is Extension.Installed && extension.isUnofficial -> itemView.context.getString(R.string.ext_unofficial)
@ -37,19 +34,19 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
else -> "" else -> ""
}.toUpperCase() }.toUpperCase()
GlideApp.with(itemView.context).clear(image) GlideApp.with(itemView.context).clear(binding.image)
if (extension is Extension.Available) { if (extension is Extension.Available) {
GlideApp.with(itemView.context) GlideApp.with(itemView.context)
.load(extension.iconUrl) .load(extension.iconUrl)
.into(image) .into(binding.image)
} else { } else {
extension.getApplicationIcon(itemView.context)?.let { image.setImageDrawable(it) } extension.getApplicationIcon(itemView.context)?.let { binding.image.setImageDrawable(it) }
} }
bindButton(item) bindButton(item)
} }
@Suppress("ResourceType") @Suppress("ResourceType")
fun bindButton(item: ExtensionItem) = with(ext_button) { fun bindButton(item: ExtensionItem) = with(binding.extButton) {
isEnabled = true isEnabled = true
isClickable = true isClickable = true

View File

@ -6,30 +6,31 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.SourceListItemBinding
import kotlinx.android.synthetic.main.source_list_item.thumbnail
import kotlinx.android.synthetic.main.source_list_item.title
class MangaHolder( class MangaHolder(
view: View, view: View,
adapter: FlexibleAdapter<*> adapter: FlexibleAdapter<*>
) : BaseFlexibleViewHolder(view, adapter) { ) : FlexibleViewHolder(view, adapter) {
private val binding = SourceListItemBinding.bind(view)
fun bind(item: MangaItem) { fun bind(item: MangaItem) {
// Update the title of the manga. // Update the title of the manga.
title.text = item.manga.title binding.title.text = item.manga.title
// Create thumbnail onclick to simulate long click // Create thumbnail onclick to simulate long click
thumbnail.setOnClickListener { binding.thumbnail.setOnClickListener {
// Simulate long click on this view to enter selection mode // Simulate long click on this view to enter selection mode
onLongClick(itemView) onLongClick(itemView)
} }
// Update the cover. // Update the cover.
GlideApp.with(itemView.context).clear(thumbnail) GlideApp.with(itemView.context).clear(binding.thumbnail)
val radius = itemView.context.resources.getDimensionPixelSize(R.dimen.card_radius) val radius = itemView.context.resources.getDimensionPixelSize(R.dimen.card_radius)
val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius)) val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
@ -38,6 +39,6 @@ class MangaHolder(
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.apply(requestOptions) .apply(requestOptions)
.dontAnimate() .dontAnimate()
.into(thumbnail) .into(binding.thumbnail)
} }
} }

View File

@ -5,9 +5,9 @@ import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem import eu.davidea.flexibleadapter.items.AbstractHeaderItem
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.SourceMainControllerCardHeaderBinding
import kotlinx.android.synthetic.main.source_main_controller_card_header.title
/** /**
* Item that contains the selection header. * Item that contains the selection header.
@ -43,9 +43,12 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
// Intentionally empty // Intentionally empty
} }
class Holder(view: View, adapter: FlexibleAdapter<*>) : BaseFlexibleViewHolder(view, adapter) { class Holder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) {
private val binding = SourceMainControllerCardHeaderBinding.bind(view)
init { init {
title.text = view.context.getString(R.string.migration_selection_prompt) binding.title.text = view.context.getString(R.string.migration_selection_prompt)
} }
} }

View File

@ -1,23 +1,24 @@
package eu.kanade.tachiyomi.ui.browse.migration.sources package eu.kanade.tachiyomi.ui.browse.migration.sources
import android.view.View import android.view.View
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardItemBinding
import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import kotlinx.android.synthetic.main.source_main_controller_card_item.image
import kotlinx.android.synthetic.main.source_main_controller_card_item.title
class SourceHolder(view: View, val adapter: SourceAdapter) : class SourceHolder(view: View, val adapter: SourceAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = SourceMainControllerCardItemBinding.bind(view)
fun bind(item: SourceItem) { fun bind(item: SourceItem) {
val source = item.source val source = item.source
// Set source name // Set source name
title.text = source.name binding.title.text = source.name
// Set source icon // Set source icon
itemView.post { itemView.post {
image.setImageDrawable(source.icon()) binding.image.setImageDrawable(source.icon())
} }
} }
} }

View File

@ -2,14 +2,16 @@ package eu.kanade.tachiyomi.ui.browse.source
import android.view.View import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardHeaderBinding
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.android.synthetic.main.source_main_controller_card_header.title
class LangHolder(view: View, adapter: FlexibleAdapter<*>) : class LangHolder(view: View, adapter: FlexibleAdapter<*>) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = SourceMainControllerCardHeaderBinding.bind(view)
fun bind(item: LangItem) { fun bind(item: LangItem) {
title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context) binding.title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
} }
} }

View File

@ -2,28 +2,26 @@ package eu.kanade.tachiyomi.ui.browse.source
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardItemBinding
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.icon
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat
import kotlinx.android.synthetic.main.source_main_controller_card_item.image
import kotlinx.android.synthetic.main.source_main_controller_card_item.pin
import kotlinx.android.synthetic.main.source_main_controller_card_item.source_latest
import kotlinx.android.synthetic.main.source_main_controller_card_item.subtitle
import kotlinx.android.synthetic.main.source_main_controller_card_item.title
class SourceHolder(private val view: View, val adapter: SourceAdapter) : class SourceHolder(private val view: View, val adapter: SourceAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = SourceMainControllerCardItemBinding.bind(view)
init { init {
source_latest.setOnClickListener { binding.sourceLatest.setOnClickListener {
adapter.clickListener.onLatestClick(bindingAdapterPosition) adapter.clickListener.onLatestClick(bindingAdapterPosition)
} }
pin.setOnClickListener { binding.pin.setOnClickListener {
adapter.clickListener.onPinClick(bindingAdapterPosition) adapter.clickListener.onPinClick(bindingAdapterPosition)
} }
} }
@ -31,26 +29,26 @@ class SourceHolder(private val view: View, val adapter: SourceAdapter) :
fun bind(item: SourceItem) { fun bind(item: SourceItem) {
val source = item.source val source = item.source
title.text = source.name binding.title.text = source.name
subtitle.isVisible = source !is LocalSource binding.subtitle.isVisible = source !is LocalSource
subtitle.text = LocaleHelper.getDisplayName(source.lang) binding.subtitle.text = LocaleHelper.getDisplayName(source.lang)
// Set source icon // Set source icon
itemView.post { itemView.post {
val icon = source.icon() val icon = source.icon()
when { when {
icon != null -> image.setImageDrawable(icon) icon != null -> binding.image.setImageDrawable(icon)
item.source.id == LocalSource.ID -> image.setImageResource(R.mipmap.ic_local_source) item.source.id == LocalSource.ID -> binding.image.setImageResource(R.mipmap.ic_local_source)
} }
} }
source_latest.isVisible = source.supportsLatest binding.sourceLatest.isVisible = source.supportsLatest
pin.isVisible = true binding.pin.isVisible = true
if (item.isPinned) { if (item.isPinned) {
pin.setVectorCompat(R.drawable.ic_push_pin_filled_24dp, view.context.getResourceColor(R.attr.colorAccent)) binding.pin.setVectorCompat(R.drawable.ic_push_pin_filled_24dp, view.context.getResourceColor(R.attr.colorAccent))
} else { } else {
pin.setVectorCompat(R.drawable.ic_push_pin_24dp, view.context.getResourceColor(android.R.attr.textColorHint)) binding.pin.setVectorCompat(R.drawable.ic_push_pin_24dp, view.context.getResourceColor(android.R.attr.textColorHint))
} }
} }
} }

View File

@ -6,11 +6,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.widget.StateImageViewTarget import eu.kanade.tachiyomi.widget.StateImageViewTarget
import kotlinx.android.synthetic.main.source_comfortable_grid_item.card
import kotlinx.android.synthetic.main.source_comfortable_grid_item.progress
import kotlinx.android.synthetic.main.source_comfortable_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
/** /**
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
@ -23,6 +20,8 @@ import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) : class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
SourceGridHolder(view, adapter) { SourceGridHolder(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.
@ -31,26 +30,26 @@ class SourceComfortableGridHolder(private val view: View, private val adapter: F
*/ */
override fun onSetValues(manga: Manga) { override fun onSetValues(manga: Manga) {
// Set manga title // Set manga title
title.text = manga.title binding.title.text = manga.title
// Set alpha of thumbnail. // Set alpha of thumbnail.
thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
setImage(manga) setImage(manga)
} }
override fun setImage(manga: Manga) { override fun setImage(manga: Manga) {
// For rounded corners // For rounded corners
card.clipToOutline = true binding.card.clipToOutline = true
GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context).clear(binding.thumbnail)
if (!manga.thumbnail_url.isNullOrEmpty()) { if (!manga.thumbnail_url.isNullOrEmpty()) {
GlideApp.with(view.context) GlideApp.with(view.context)
.load(manga.toMangaThumbnail()) .load(manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.DATA) .diskCacheStrategy(DiskCacheStrategy.DATA)
.centerCrop() .centerCrop()
.placeholder(android.R.color.transparent) .placeholder(android.R.color.transparent)
.into(StateImageViewTarget(thumbnail, progress)) .into(StateImageViewTarget(binding.thumbnail, binding.progress))
} }
} }
} }

View File

@ -6,11 +6,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.widget.StateImageViewTarget import eu.kanade.tachiyomi.widget.StateImageViewTarget
import kotlinx.android.synthetic.main.source_compact_grid_item.card
import kotlinx.android.synthetic.main.source_compact_grid_item.progress
import kotlinx.android.synthetic.main.source_compact_grid_item.thumbnail
import kotlinx.android.synthetic.main.source_compact_grid_item.title
/** /**
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
@ -23,6 +20,8 @@ import kotlinx.android.synthetic.main.source_compact_grid_item.title
open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) : open class SourceGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
SourceHolder(view, adapter) { SourceHolder(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.
@ -31,26 +30,26 @@ open class SourceGridHolder(private val view: View, private val adapter: Flexibl
*/ */
override fun onSetValues(manga: Manga) { override fun onSetValues(manga: Manga) {
// Set manga title // Set manga title
title.text = manga.title binding.title.text = manga.title
// Set alpha of thumbnail. // Set alpha of thumbnail.
thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
setImage(manga) setImage(manga)
} }
override fun setImage(manga: Manga) { override fun setImage(manga: Manga) {
// For rounded corners // For rounded corners
card.clipToOutline = true binding.card.clipToOutline = true
GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context).clear(binding.thumbnail)
if (!manga.thumbnail_url.isNullOrEmpty()) { if (!manga.thumbnail_url.isNullOrEmpty()) {
GlideApp.with(view.context) GlideApp.with(view.context)
.load(manga.toMangaThumbnail()) .load(manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.DATA) .diskCacheStrategy(DiskCacheStrategy.DATA)
.centerCrop() .centerCrop()
.placeholder(android.R.color.transparent) .placeholder(android.R.color.transparent)
.into(StateImageViewTarget(thumbnail, progress)) .into(StateImageViewTarget(binding.thumbnail, binding.progress))
} }
} }
} }

View File

@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.browse.source.browse
import android.view.View import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
/** /**
* Generic class used to hold the displayed data of a manga in the catalogue. * Generic class used to hold the displayed data of a manga in the catalogue.
@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
* @param adapter the adapter handling this holder. * @param adapter the adapter handling this holder.
*/ */
abstract class SourceHolder(view: View, adapter: FlexibleAdapter<*>) : abstract class SourceHolder(view: View, adapter: FlexibleAdapter<*>) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
/** /**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this * Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this

View File

@ -10,9 +10,8 @@ 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.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlinx.android.synthetic.main.source_list_item.thumbnail
import kotlinx.android.synthetic.main.source_list_item.title
/** /**
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title. * Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
@ -25,6 +24,8 @@ import kotlinx.android.synthetic.main.source_list_item.title
class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) : class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
SourceHolder(view, adapter) { SourceHolder(view, adapter) {
private val binding = SourceListItemBinding.bind(view)
private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f) private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface) private val unfavoriteColor = view.context.getResourceColor(R.attr.colorOnSurface)
@ -35,17 +36,17 @@ class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
* @param manga the manga to bind. * @param manga the manga to bind.
*/ */
override fun onSetValues(manga: Manga) { override fun onSetValues(manga: Manga) {
title.text = manga.title binding.title.text = manga.title
title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor) binding.title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor)
// Set alpha of thumbnail. // Set alpha of thumbnail.
thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f binding.thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
setImage(manga) setImage(manga)
} }
override fun setImage(manga: Manga) { override fun setImage(manga: Manga) {
GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context).clear(binding.thumbnail)
if (!manga.thumbnail_url.isNullOrEmpty()) { if (!manga.thumbnail_url.isNullOrEmpty()) {
val radius = view.context.resources.getDimensionPixelSize(R.dimen.card_radius) val radius = view.context.resources.getDimensionPixelSize(R.dimen.card_radius)
@ -56,7 +57,7 @@ class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
.apply(requestOptions) .apply(requestOptions)
.dontAnimate() .dontAnimate()
.placeholder(android.R.color.transparent) .placeholder(android.R.color.transparent)
.into(thumbnail) .into(binding.thumbnail)
} }
} }
} }

View File

@ -2,18 +2,17 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch
import android.view.View import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.GlobalSearchControllerCardItemBinding
import eu.kanade.tachiyomi.widget.StateImageViewTarget import eu.kanade.tachiyomi.widget.StateImageViewTarget
import kotlinx.android.synthetic.main.global_search_controller_card_item.card
import kotlinx.android.synthetic.main.global_search_controller_card_item.cover
import kotlinx.android.synthetic.main.global_search_controller_card_item.progress
import kotlinx.android.synthetic.main.global_search_controller_card_item.title
class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) : class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = GlobalSearchControllerCardItemBinding.bind(view)
init { init {
// Call onMangaClickListener when item is pressed. // Call onMangaClickListener when item is pressed.
@ -33,17 +32,17 @@ class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) :
} }
fun bind(manga: Manga) { fun bind(manga: Manga) {
card.clipToOutline = true binding.card.clipToOutline = true
title.text = manga.title binding.title.text = manga.title
// Set alpha of thumbnail. // Set alpha of thumbnail.
cover.alpha = if (manga.favorite) 0.3f else 1.0f binding.cover.alpha = if (manga.favorite) 0.3f else 1.0f
setImage(manga) setImage(manga)
} }
fun setImage(manga: Manga) { fun setImage(manga: Manga) {
GlideApp.with(itemView.context).clear(cover) GlideApp.with(itemView.context).clear(binding.cover)
if (!manga.thumbnail_url.isNullOrEmpty()) { if (!manga.thumbnail_url.isNullOrEmpty()) {
GlideApp.with(itemView.context) GlideApp.with(itemView.context)
.load(manga.toMangaThumbnail()) .load(manga.toMangaThumbnail())
@ -51,7 +50,7 @@ class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) :
.centerCrop() .centerCrop()
.skipMemoryCache(true) .skipMemoryCache(true)
.placeholder(android.R.color.transparent) .placeholder(android.R.color.transparent)
.into(StateImageViewTarget(cover, progress)) .into(StateImageViewTarget(binding.cover, binding.progress))
} }
} }
} }

View File

@ -3,16 +3,11 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.databinding.GlobalSearchControllerCardBinding
import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.android.synthetic.main.global_search_controller_card.no_results_found
import kotlinx.android.synthetic.main.global_search_controller_card.progress
import kotlinx.android.synthetic.main.global_search_controller_card.recycler
import kotlinx.android.synthetic.main.global_search_controller_card.subtitle
import kotlinx.android.synthetic.main.global_search_controller_card.title
import kotlinx.android.synthetic.main.global_search_controller_card.title_wrapper
/** /**
* Holder that binds the [GlobalSearchItem] containing catalogue cards. * Holder that binds the [GlobalSearchItem] containing catalogue cards.
@ -21,7 +16,9 @@ import kotlinx.android.synthetic.main.global_search_controller_card.title_wrappe
* @param adapter instance of [GlobalSearchAdapter] * @param adapter instance of [GlobalSearchAdapter]
*/ */
class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) : class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = GlobalSearchControllerCardBinding.bind(view)
/** /**
* Adapter containing manga from search results. * Adapter containing manga from search results.
@ -32,10 +29,10 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
init { init {
// Set layout horizontal. // Set layout horizontal.
recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false) binding.recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false)
recycler.adapter = mangaAdapter binding.recycler.adapter = mangaAdapter
title_wrapper.setOnClickListener { binding.titleWrapper.setOnClickListener {
adapter.getItem(bindingAdapterPosition)?.let { adapter.getItem(bindingAdapterPosition)?.let {
adapter.titleClickListener.onTitleClick(it.source) adapter.titleClickListener.onTitleClick(it.source)
} }
@ -53,21 +50,21 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
val titlePrefix = if (item.highlighted) "" else "" val titlePrefix = if (item.highlighted) "" else ""
title.text = titlePrefix + source.name binding.title.text = titlePrefix + source.name
subtitle.isVisible = source !is LocalSource binding.subtitle.isVisible = source !is LocalSource
subtitle.text = LocaleHelper.getDisplayName(source.lang) binding.subtitle.text = LocaleHelper.getDisplayName(source.lang)
when { when {
results == null -> { results == null -> {
progress.isVisible = true binding.progress.isVisible = true
showResultsHolder() showResultsHolder()
} }
results.isEmpty() -> { results.isEmpty() -> {
progress.isVisible = false binding.progress.isVisible = false
showNoResults() showNoResults()
} }
else -> { else -> {
progress.isVisible = false binding.progress.isVisible = false
showResultsHolder() showResultsHolder()
} }
} }
@ -104,10 +101,10 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
} }
private fun showResultsHolder() { private fun showResultsHolder() {
no_results_found.isVisible = false binding.noResultsFound.isVisible = false
} }
private fun showNoResults() { private fun showNoResults() {
no_results_found.isVisible = true binding.noResultsFound.isVisible = true
} }
} }

View File

@ -1,10 +1,9 @@
package eu.kanade.tachiyomi.ui.category package eu.kanade.tachiyomi.ui.category
import android.view.View import android.view.View
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.CategoriesItemBinding
import kotlinx.android.synthetic.main.categories_item.reorder
import kotlinx.android.synthetic.main.categories_item.title
/** /**
* Holder used to display category items. * Holder used to display category items.
@ -12,10 +11,12 @@ import kotlinx.android.synthetic.main.categories_item.title
* @param view The view used by category items. * @param view The view used by category items.
* @param adapter The adapter containing this holder. * @param adapter The adapter containing this holder.
*/ */
class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleViewHolder(view, adapter) { class CategoryHolder(view: View, val adapter: CategoryAdapter) : FlexibleViewHolder(view, adapter) {
private val binding = CategoriesItemBinding.bind(view)
init { init {
setDragHandleView(reorder) setDragHandleView(binding.reorder)
} }
/** /**
@ -24,7 +25,7 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleVie
* @param category The category to bind. * @param category The category to bind.
*/ */
fun bind(category: Category) { fun bind(category: Category) {
title.text = category.name binding.title.text = category.name
} }
/** /**

View File

@ -1,16 +1,11 @@
package eu.kanade.tachiyomi.ui.download package eu.kanade.tachiyomi.ui.download
import android.view.View import android.view.View
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.DownloadItemBinding
import eu.kanade.tachiyomi.util.view.popupMenu import eu.kanade.tachiyomi.util.view.popupMenu
import kotlinx.android.synthetic.main.download_item.chapter_title
import kotlinx.android.synthetic.main.download_item.download_progress
import kotlinx.android.synthetic.main.download_item.download_progress_text
import kotlinx.android.synthetic.main.download_item.manga_full_title
import kotlinx.android.synthetic.main.download_item.menu
import kotlinx.android.synthetic.main.download_item.reorder
/** /**
* Class used to hold the data of a download. * Class used to hold the data of a download.
@ -20,11 +15,13 @@ import kotlinx.android.synthetic.main.download_item.reorder
* @constructor creates a new download holder. * @constructor creates a new download holder.
*/ */
class DownloadHolder(private val view: View, val adapter: DownloadAdapter) : class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = DownloadItemBinding.bind(view)
init { init {
setDragHandleView(reorder) setDragHandleView(binding.reorder)
menu.setOnClickListener { it.post { showPopupMenu(it) } } binding.menu.setOnClickListener { it.post { showPopupMenu(it) } }
} }
private lateinit var download: Download private lateinit var download: Download
@ -37,19 +34,19 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
fun bind(download: Download) { fun bind(download: Download) {
this.download = download this.download = download
// Update the chapter name. // Update the chapter name.
chapter_title.text = download.chapter.name binding.chapterTitle.text = download.chapter.name
// Update the manga title // Update the manga title
manga_full_title.text = download.manga.title binding.mangaFullTitle.text = download.manga.title
// Update the progress bar and the number of downloaded pages // Update the progress bar and the number of downloaded pages
val pages = download.pages val pages = download.pages
if (pages == null) { if (pages == null) {
download_progress.progress = 0 binding.downloadProgress.progress = 0
download_progress.max = 1 binding.downloadProgress.max = 1
download_progress_text.text = "" binding.downloadProgressText.text = ""
} else { } else {
download_progress.max = pages.size * 100 binding.downloadProgress.max = pages.size * 100
notifyProgress() notifyProgress()
notifyDownloadedPages() notifyDownloadedPages()
} }
@ -60,10 +57,10 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
*/ */
fun notifyProgress() { fun notifyProgress() {
val pages = download.pages ?: return val pages = download.pages ?: return
if (download_progress.max == 1) { if (binding.downloadProgress.max == 1) {
download_progress.max = pages.size * 100 binding.downloadProgress.max = pages.size * 100
} }
download_progress.progress = download.totalProgress binding.downloadProgress.progress = download.totalProgress
} }
/** /**
@ -71,7 +68,7 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
*/ */
fun notifyDownloadedPages() { fun notifyDownloadedPages() {
val pages = download.pages ?: return val pages = download.pages ?: return
download_progress_text.text = "${download.downloadedImages}/${pages.size}" binding.downloadProgressText.text = "${download.downloadedImages}/${pages.size}"
} }
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {

View File

@ -8,14 +8,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
import eu.kanade.tachiyomi.util.isLocal 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. * 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>> adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>
) : LibraryCompactGridHolder(view, adapter) { ) : LibraryCompactGridHolder(view, adapter) {
private val binding = SourceComfortableGridItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.
@ -39,34 +35,34 @@ class LibraryComfortableGridHolder(
*/ */
override fun onSetValues(item: LibraryItem) { override fun onSetValues(item: LibraryItem) {
// Update the title of the manga. // Update the title of the manga.
title.text = item.manga.title binding.title.text = item.manga.title
// For rounded corners // For rounded corners
badges.clipToOutline = true binding.badges.clipToOutline = true
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(unread_text) { with(binding.unreadText) {
isVisible = item.unreadCount > 0 isVisible = item.unreadCount > 0
text = item.unreadCount.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(download_text) { with(binding.downloadText) {
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = item.downloadCount.toString() text = item.downloadCount.toString()
} }
// set local visibility if its local manga // set local visibility if its local manga
local_text.isVisible = item.manga.isLocal() binding.localText.isVisible = item.manga.isLocal()
// For rounded corners // For rounded corners
card.clipToOutline = true binding.card.clipToOutline = true
// Update the cover. // Update the cover.
GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context).clear(binding.thumbnail)
GlideApp.with(view.context) GlideApp.with(view.context)
.load(item.manga.toMangaThumbnail()) .load(item.manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
.dontAnimate() .dontAnimate()
.into(thumbnail) .into(binding.thumbnail)
} }
} }

View File

@ -6,14 +6,8 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceCompactGridItemBinding
import eu.kanade.tachiyomi.util.isLocal 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. * 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<*> private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) { ) : LibraryHolder(view, adapter) {
private val binding = SourceCompactGridItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.
@ -37,34 +33,34 @@ open class LibraryCompactGridHolder(
*/ */
override fun onSetValues(item: LibraryItem) { override fun onSetValues(item: LibraryItem) {
// Update the title of the manga. // Update the title of the manga.
title.text = item.manga.title binding.title.text = item.manga.title
// For rounded corners // For rounded corners
badges.clipToOutline = true binding.badges.clipToOutline = true
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(unread_text) { with(binding.unreadText) {
isVisible = item.unreadCount > 0 isVisible = item.unreadCount > 0
text = item.unreadCount.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(download_text) { with(binding.downloadText) {
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = item.downloadCount.toString() text = item.downloadCount.toString()
} }
// set local visibility if its local manga // set local visibility if its local manga
local_text.isVisible = item.manga.isLocal() binding.localText.isVisible = item.manga.isLocal()
// For rounded corners // For rounded corners
card.clipToOutline = true binding.card.clipToOutline = true
// Update the cover. // Update the cover.
GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context).clear(binding.thumbnail)
GlideApp.with(view.context) GlideApp.with(view.context)
.load(item.manga.toMangaThumbnail()) .load(item.manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
.dontAnimate() .dontAnimate()
.into(thumbnail) .into(binding.thumbnail)
} }
} }

View File

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.ui.library
import android.view.View import android.view.View
import eu.davidea.flexibleadapter.FlexibleAdapter 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. * 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( abstract class LibraryHolder(
view: View, view: View,
adapter: FlexibleAdapter<*> adapter: FlexibleAdapter<*>
) : BaseFlexibleViewHolder(view, adapter) { ) : FlexibleViewHolder(view, adapter) {
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this

View File

@ -10,13 +10,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
import eu.kanade.tachiyomi.util.isLocal 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. * 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<*> private val adapter: FlexibleAdapter<*>
) : LibraryHolder(view, adapter) { ) : LibraryHolder(view, adapter) {
private val binding = SourceListItemBinding.bind(view)
/** /**
* Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga. * holder with the given manga.
@ -41,32 +38,32 @@ class LibraryListHolder(
*/ */
override fun onSetValues(item: LibraryItem) { override fun onSetValues(item: LibraryItem) {
// Update the title of the manga. // Update the title of the manga.
title.text = item.manga.title binding.title.text = item.manga.title
// For rounded corners // For rounded corners
badges.clipToOutline = true binding.badges.clipToOutline = true
// Update the unread count and its visibility. // Update the unread count and its visibility.
with(unread_text) { with(binding.unreadText) {
isVisible = item.unreadCount > 0 isVisible = item.unreadCount > 0
text = item.unreadCount.toString() text = item.unreadCount.toString()
} }
// Update the download count and its visibility. // Update the download count and its visibility.
with(download_text) { with(binding.downloadText) {
isVisible = item.downloadCount > 0 isVisible = item.downloadCount > 0
text = "${item.downloadCount}" text = "${item.downloadCount}"
} }
// show local text badge if local manga // 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 // Create thumbnail onclick to simulate long click
thumbnail.setOnClickListener { binding.thumbnail.setOnClickListener {
// Simulate long click on this view to enter selection mode // Simulate long click on this view to enter selection mode
onLongClick(itemView) onLongClick(itemView)
} }
// Update the cover. // 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 radius = view.context.resources.getDimensionPixelSize(R.dimen.card_radius)
val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius)) val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
@ -75,6 +72,6 @@ class LibraryListHolder(
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.apply(requestOptions) .apply(requestOptions)
.dontAnimate() .dontAnimate()
.into(thumbnail) .into(binding.thumbnail)
} }
} }

View File

@ -415,8 +415,8 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
} }
/** /**
* Used to manually offset a view within the activity's child views that might be cut off due to the * Used to manually offset a view within the activity's child views that might be cut off due to
* collapsing AppBarLayout. * the collapsing AppBarLayout.
*/ */
fun fixViewToBottom(view: View) { fun fixViewToBottom(view: View) {
binding.appbar.addOnOffsetChangedListener( binding.appbar.addOnOffsetChangedListener(

View File

@ -5,25 +5,24 @@ import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import eu.davidea.viewholders.FlexibleViewHolder
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.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.ChaptersItemBinding
import kotlinx.android.synthetic.main.chapters_item.bookmark_icon
import kotlinx.android.synthetic.main.chapters_item.chapter_description
import kotlinx.android.synthetic.main.chapters_item.chapter_title
import kotlinx.android.synthetic.main.chapters_item.download_text
import java.util.Date import java.util.Date
class ChapterHolder( class ChapterHolder(
view: View, view: View,
private val adapter: ChaptersAdapter private val adapter: ChaptersAdapter
) : BaseFlexibleViewHolder(view, adapter) { ) : FlexibleViewHolder(view, adapter) {
private val binding = ChaptersItemBinding.bind(view)
fun bind(item: ChapterItem, manga: Manga) { fun bind(item: ChapterItem, manga: Manga) {
val chapter = item.chapter val chapter = item.chapter
chapter_title.text = when (manga.displayMode) { binding.chapterTitle.text = when (manga.displayMode) {
Manga.DISPLAY_NUMBER -> { Manga.DISPLAY_NUMBER -> {
val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
itemView.context.getString(R.string.display_mode_chapter, number) itemView.context.getString(R.string.display_mode_chapter, number)
@ -37,16 +36,16 @@ class ChapterHolder(
chapter.bookmark -> adapter.bookmarkedColor chapter.bookmark -> adapter.bookmarkedColor
else -> adapter.unreadColor else -> adapter.unreadColor
} }
chapter_title.setTextColor(chapterTitleColor) binding.chapterTitle.setTextColor(chapterTitleColor)
val chapterDescriptionColor = when { val chapterDescriptionColor = when {
chapter.read -> adapter.readColor chapter.read -> adapter.readColor
chapter.bookmark -> adapter.bookmarkedColor chapter.bookmark -> adapter.bookmarkedColor
else -> adapter.unreadColorSecondary else -> adapter.unreadColorSecondary
} }
chapter_description.setTextColor(chapterDescriptionColor) binding.chapterDescription.setTextColor(chapterDescriptionColor)
bookmark_icon.isVisible = chapter.bookmark binding.bookmarkIcon.isVisible = chapter.bookmark
val descriptions = mutableListOf<CharSequence>() val descriptions = mutableListOf<CharSequence>()
@ -64,15 +63,15 @@ class ChapterHolder(
} }
if (descriptions.isNotEmpty()) { if (descriptions.isNotEmpty()) {
chapter_description.text = descriptions.joinTo(SpannableStringBuilder(), "") binding.chapterDescription.text = descriptions.joinTo(SpannableStringBuilder(), "")
} else { } else {
chapter_description.text = "" binding.chapterDescription.text = ""
} }
notifyStatus(item.status) notifyStatus(item.status)
} }
fun notifyStatus(status: Int) = with(download_text) { fun notifyStatus(status: Int) = with(binding.downloadText) {
when (status) { when (status) {
Download.QUEUE -> setText(R.string.chapter_queued) Download.QUEUE -> setText(R.string.chapter_queued)
Download.DOWNLOADING -> setText(R.string.chapter_downloading) Download.DOWNLOADING -> setText(R.string.chapter_downloading)

View File

@ -2,18 +2,13 @@ package eu.kanade.tachiyomi.ui.recent.history
import android.view.View import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.HistoryItemBinding
import eu.kanade.tachiyomi.util.lang.toTimestampString import eu.kanade.tachiyomi.util.lang.toTimestampString
import kotlinx.android.synthetic.main.history_item.cover
import kotlinx.android.synthetic.main.history_item.holder
import kotlinx.android.synthetic.main.history_item.manga_subtitle
import kotlinx.android.synthetic.main.history_item.manga_title
import kotlinx.android.synthetic.main.history_item.remove
import kotlinx.android.synthetic.main.history_item.resume
import java.util.Date import java.util.Date
/** /**
@ -28,18 +23,20 @@ import java.util.Date
class HistoryHolder( class HistoryHolder(
view: View, view: View,
val adapter: HistoryAdapter val adapter: HistoryAdapter
) : BaseFlexibleViewHolder(view, adapter) { ) : FlexibleViewHolder(view, adapter) {
private val binding = HistoryItemBinding.bind(view)
init { init {
holder.setOnClickListener { binding.holder.setOnClickListener {
adapter.itemClickListener.onItemClick(bindingAdapterPosition) adapter.itemClickListener.onItemClick(bindingAdapterPosition)
} }
remove.setOnClickListener { binding.remove.setOnClickListener {
adapter.removeClickListener.onRemoveClick(bindingAdapterPosition) adapter.removeClickListener.onRemoveClick(bindingAdapterPosition)
} }
resume.setOnClickListener { binding.resume.setOnClickListener {
adapter.resumeClickListener.onResumeClick(bindingAdapterPosition) adapter.resumeClickListener.onResumeClick(bindingAdapterPosition)
} }
} }
@ -54,26 +51,26 @@ class HistoryHolder(
val (manga, chapter, history) = item val (manga, chapter, history) = item
// Set manga title // Set manga title
manga_title.text = manga.title binding.mangaTitle.text = manga.title
// Set chapter number + timestamp // Set chapter number + timestamp
if (chapter.chapter_number > -1f) { if (chapter.chapter_number > -1f) {
val formattedNumber = adapter.decimalFormat.format(chapter.chapter_number.toDouble()) val formattedNumber = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
manga_subtitle.text = itemView.context.getString( binding.mangaSubtitle.text = itemView.context.getString(
R.string.recent_manga_time, R.string.recent_manga_time,
formattedNumber, formattedNumber,
Date(history.last_read).toTimestampString() Date(history.last_read).toTimestampString()
) )
} else { } else {
manga_subtitle.text = Date(history.last_read).toTimestampString() binding.mangaSubtitle.text = Date(history.last_read).toTimestampString()
} }
// Set cover // Set cover
GlideApp.with(itemView.context).clear(cover) GlideApp.with(itemView.context).clear(binding.cover)
GlideApp.with(itemView.context) GlideApp.with(itemView.context)
.load(manga.toMangaThumbnail()) .load(manga.toMangaThumbnail())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .centerCrop()
.into(cover) .into(binding.cover)
} }
} }

View File

@ -5,16 +5,13 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.databinding.UpdatesItemBinding
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlinx.android.synthetic.main.updates_item.chapter_title
import kotlinx.android.synthetic.main.updates_item.download_text
import kotlinx.android.synthetic.main.updates_item.manga_cover
import kotlinx.android.synthetic.main.updates_item.manga_title
/** /**
* Holder that contains chapter item * Holder that contains chapter item
@ -27,7 +24,9 @@ import kotlinx.android.synthetic.main.updates_item.manga_title
* @constructor creates a new recent chapter holder. * @constructor creates a new recent chapter holder.
*/ */
class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) : class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = UpdatesItemBinding.bind(view)
private var readColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f) private var readColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
private var unreadColor = view.context.getResourceColor(R.attr.colorOnSurface) private var unreadColor = view.context.getResourceColor(R.attr.colorOnSurface)
@ -38,7 +37,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
private var item: UpdatesItem? = null private var item: UpdatesItem? = null
init { init {
manga_cover.setOnClickListener { binding.mangaCover.setOnClickListener {
adapter.coverClickListener.onCoverClick(bindingAdapterPosition) adapter.coverClickListener.onCoverClick(bindingAdapterPosition)
} }
} }
@ -52,25 +51,25 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
this.item = item this.item = item
// Set chapter title // Set chapter title
chapter_title.text = item.chapter.name binding.chapterTitle.text = item.chapter.name
// Set manga title // Set manga title
manga_title.text = item.manga.title binding.mangaTitle.text = item.manga.title
// Check if chapter is read and set correct color // Check if chapter is read and set correct color
if (item.chapter.read) { if (item.chapter.read) {
chapter_title.setTextColor(readColor) binding.chapterTitle.setTextColor(readColor)
manga_title.setTextColor(readColor) binding.mangaTitle.setTextColor(readColor)
} else { } else {
chapter_title.setTextColor(unreadColor) binding.chapterTitle.setTextColor(unreadColor)
manga_title.setTextColor(unreadColor) binding.mangaTitle.setTextColor(unreadColor)
} }
// Set chapter status // Set chapter status
notifyStatus(item.status) notifyStatus(item.status)
// Set cover // Set cover
GlideApp.with(itemView.context).clear(manga_cover) GlideApp.with(itemView.context).clear(binding.mangaCover)
val radius = itemView.context.resources.getDimensionPixelSize(R.dimen.card_radius) val radius = itemView.context.resources.getDimensionPixelSize(R.dimen.card_radius)
val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius)) val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
@ -79,7 +78,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.apply(requestOptions) .apply(requestOptions)
.dontAnimate() .dontAnimate()
.into(manga_cover) .into(binding.mangaCover)
} }
/** /**
@ -87,7 +86,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
* *
* @param status download status * @param status download status
*/ */
fun notifyStatus(status: Int) = with(download_text) { fun notifyStatus(status: Int) = with(binding.downloadText) {
when (status) { when (status) {
Download.QUEUE -> setText(R.string.chapter_queued) Download.QUEUE -> setText(R.string.chapter_queued)
Download.DOWNLOADING -> setText(R.string.chapter_downloading) Download.DOWNLOADING -> setText(R.string.chapter_downloading)

View File

@ -1,11 +1,8 @@
package eu.kanade.tachiyomi.ui.setting.search package eu.kanade.tachiyomi.ui.setting.search
import android.view.View import android.view.View
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.davidea.viewholders.FlexibleViewHolder
import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_breadcrumb import eu.kanade.tachiyomi.databinding.SettingsSearchControllerCardBinding
import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_summary
import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_title
import kotlinx.android.synthetic.main.settings_search_controller_card.title_wrapper
import kotlin.reflect.full.createInstance import kotlin.reflect.full.createInstance
/** /**
@ -15,10 +12,12 @@ import kotlin.reflect.full.createInstance
* @param adapter instance of [SettingsSearchAdapter] * @param adapter instance of [SettingsSearchAdapter]
*/ */
class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) : class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
BaseFlexibleViewHolder(view, adapter) { FlexibleViewHolder(view, adapter) {
private val binding = SettingsSearchControllerCardBinding.bind(view)
init { init {
title_wrapper.setOnClickListener { binding.titleWrapper.setOnClickListener {
adapter.getItem(bindingAdapterPosition)?.let { adapter.getItem(bindingAdapterPosition)?.let {
val ctrl = it.settingsSearchResult.searchController::class.createInstance() val ctrl = it.settingsSearchResult.searchController::class.createInstance()
ctrl.preferenceKey = it.settingsSearchResult.key ctrl.preferenceKey = it.settingsSearchResult.key
@ -35,8 +34,8 @@ class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
* @param item item of card. * @param item item of card.
*/ */
fun bind(item: SettingsSearchItem) { fun bind(item: SettingsSearchItem) {
search_result_pref_title.text = item.settingsSearchResult.title binding.searchResultPrefTitle.text = item.settingsSearchResult.title
search_result_pref_summary.text = item.settingsSearchResult.summary binding.searchResultPrefSummary.text = item.settingsSearchResult.summary
search_result_pref_breadcrumb.text = item.settingsSearchResult.breadcrumb binding.searchResultPrefBreadcrumb.text = item.settingsSearchResult.breadcrumb
} }
} }