Replace Kotlin synthetic views in viewholders
This commit is contained in:
parent
322d66d282
commit
749c2071af
25 changed files with 227 additions and 263 deletions
|
@ -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
|
||||
}
|
|
@ -3,11 +3,13 @@ package eu.kanade.tachiyomi.ui.browse.extension
|
|||
import android.annotation.SuppressLint
|
||||
import android.view.View
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.source_main_controller_card_header.title
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardHeaderBinding
|
||||
|
||||
class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceMainControllerCardHeaderBinding.bind(view)
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
fun bind(item: ExtensionGroupItem) {
|
||||
|
@ -16,6 +18,6 @@ class ExtensionGroupHolder(view: View, adapter: FlexibleAdapter<*>) :
|
|||
text += " (${item.size})"
|
||||
}
|
||||
|
||||
title.text = text
|
||||
binding.title.text = text
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
package eu.kanade.tachiyomi.ui.browse.extension
|
||||
|
||||
import android.view.View
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
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.InstallStep
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
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) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = ExtensionCardItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
ext_button.setOnClickListener {
|
||||
binding.extButton.setOnClickListener {
|
||||
adapter.buttonClickListener.onButtonClick(bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +23,10 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
|||
fun bind(item: ExtensionItem) {
|
||||
val extension = item.extension
|
||||
|
||||
ext_title.text = extension.name
|
||||
version.text = extension.versionName
|
||||
lang.text = LocaleHelper.getSourceDisplayName(extension.lang, itemView.context)
|
||||
warning.text = when {
|
||||
binding.extTitle.text = extension.name
|
||||
binding.version.text = extension.versionName
|
||||
binding.lang.text = LocaleHelper.getSourceDisplayName(extension.lang, itemView.context)
|
||||
binding.warning.text = when {
|
||||
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.isUnofficial -> itemView.context.getString(R.string.ext_unofficial)
|
||||
|
@ -37,19 +34,19 @@ class ExtensionHolder(view: View, val adapter: ExtensionAdapter) :
|
|||
else -> ""
|
||||
}.toUpperCase()
|
||||
|
||||
GlideApp.with(itemView.context).clear(image)
|
||||
GlideApp.with(itemView.context).clear(binding.image)
|
||||
if (extension is Extension.Available) {
|
||||
GlideApp.with(itemView.context)
|
||||
.load(extension.iconUrl)
|
||||
.into(image)
|
||||
.into(binding.image)
|
||||
} else {
|
||||
extension.getApplicationIcon(itemView.context)?.let { image.setImageDrawable(it) }
|
||||
extension.getApplicationIcon(itemView.context)?.let { binding.image.setImageDrawable(it) }
|
||||
}
|
||||
bindButton(item)
|
||||
}
|
||||
|
||||
@Suppress("ResourceType")
|
||||
fun bindButton(item: ExtensionItem) = with(ext_button) {
|
||||
fun bindButton(item: ExtensionItem) = with(binding.extButton) {
|
||||
isEnabled = true
|
||||
isClickable = true
|
||||
|
||||
|
|
|
@ -6,30 +6,31 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
|||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.source_list_item.thumbnail
|
||||
import kotlinx.android.synthetic.main.source_list_item.title
|
||||
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
|
||||
|
||||
class MangaHolder(
|
||||
view: View,
|
||||
adapter: FlexibleAdapter<*>
|
||||
) : BaseFlexibleViewHolder(view, adapter) {
|
||||
) : FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceListItemBinding.bind(view)
|
||||
|
||||
fun bind(item: MangaItem) {
|
||||
// Update the title of the manga.
|
||||
title.text = item.manga.title
|
||||
binding.title.text = item.manga.title
|
||||
|
||||
// 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 = itemView.context.resources.getDimensionPixelSize(R.dimen.card_radius)
|
||||
val requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
|
||||
|
@ -38,6 +39,6 @@ class MangaHolder(
|
|||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.apply(requestOptions)
|
||||
.dontAnimate()
|
||||
.into(thumbnail)
|
||||
.into(binding.thumbnail)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.flexibleadapter.items.AbstractHeaderItem
|
||||
import eu.davidea.flexibleadapter.items.IFlexible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.source_main_controller_card_header.title
|
||||
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardHeaderBinding
|
||||
|
||||
/**
|
||||
* Item that contains the selection header.
|
||||
|
@ -43,9 +43,12 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
|
|||
// 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 {
|
||||
title.text = view.context.getString(R.string.migration_selection_prompt)
|
||||
binding.title.text = view.context.getString(R.string.migration_selection_prompt)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
package eu.kanade.tachiyomi.ui.browse.migration.sources
|
||||
|
||||
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.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) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceMainControllerCardItemBinding.bind(view)
|
||||
|
||||
fun bind(item: SourceItem) {
|
||||
val source = item.source
|
||||
|
||||
// Set source name
|
||||
title.text = source.name
|
||||
binding.title.text = source.name
|
||||
|
||||
// Set source icon
|
||||
itemView.post {
|
||||
image.setImageDrawable(source.icon())
|
||||
binding.image.setImageDrawable(source.icon())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,16 @@ package eu.kanade.tachiyomi.ui.browse.source
|
|||
|
||||
import android.view.View
|
||||
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 kotlinx.android.synthetic.main.source_main_controller_card_header.title
|
||||
|
||||
class LangHolder(view: View, adapter: FlexibleAdapter<*>) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceMainControllerCardHeaderBinding.bind(view)
|
||||
|
||||
fun bind(item: LangItem) {
|
||||
title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
|
||||
binding.title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,28 +2,26 @@ package eu.kanade.tachiyomi.ui.browse.source
|
|||
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.SourceMainControllerCardItemBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
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.getResourceColor
|
||||
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) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceMainControllerCardItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
source_latest.setOnClickListener {
|
||||
binding.sourceLatest.setOnClickListener {
|
||||
adapter.clickListener.onLatestClick(bindingAdapterPosition)
|
||||
}
|
||||
|
||||
pin.setOnClickListener {
|
||||
binding.pin.setOnClickListener {
|
||||
adapter.clickListener.onPinClick(bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
@ -31,26 +29,26 @@ class SourceHolder(private val view: View, val adapter: SourceAdapter) :
|
|||
fun bind(item: SourceItem) {
|
||||
val source = item.source
|
||||
|
||||
title.text = source.name
|
||||
subtitle.isVisible = source !is LocalSource
|
||||
subtitle.text = LocaleHelper.getDisplayName(source.lang)
|
||||
binding.title.text = source.name
|
||||
binding.subtitle.isVisible = source !is LocalSource
|
||||
binding.subtitle.text = LocaleHelper.getDisplayName(source.lang)
|
||||
|
||||
// Set source icon
|
||||
itemView.post {
|
||||
val icon = source.icon()
|
||||
when {
|
||||
icon != null -> image.setImageDrawable(icon)
|
||||
item.source.id == LocalSource.ID -> image.setImageResource(R.mipmap.ic_local_source)
|
||||
icon != null -> binding.image.setImageDrawable(icon)
|
||||
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) {
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
|
||||
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.
|
||||
|
@ -23,6 +20,8 @@ import kotlinx.android.synthetic.main.source_comfortable_grid_item.title
|
|||
class SourceComfortableGridHolder(private val view: View, private val adapter: FlexibleAdapter<*>) :
|
||||
SourceGridHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
* holder with the given manga.
|
||||
|
@ -31,26 +30,26 @@ class SourceComfortableGridHolder(private val view: View, private val adapter: F
|
|||
*/
|
||||
override fun onSetValues(manga: Manga) {
|
||||
// Set manga title
|
||||
title.text = manga.title
|
||||
binding.title.text = manga.title
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
override fun setImage(manga: Manga) {
|
||||
// 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()) {
|
||||
GlideApp.with(view.context)
|
||||
.load(manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
||||
.centerCrop()
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(StateImageViewTarget(thumbnail, progress))
|
||||
.into(StateImageViewTarget(binding.thumbnail, binding.progress))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||
import eu.kanade.tachiyomi.databinding.SourceComfortableGridItemBinding
|
||||
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.
|
||||
|
@ -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<*>) :
|
||||
SourceHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceComfortableGridItemBinding.bind(view)
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
* 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) {
|
||||
// Set manga title
|
||||
title.text = manga.title
|
||||
binding.title.text = manga.title
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
override fun setImage(manga: Manga) {
|
||||
// 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()) {
|
||||
GlideApp.with(view.context)
|
||||
.load(manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.DATA)
|
||||
.centerCrop()
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(StateImageViewTarget(thumbnail, progress))
|
||||
.into(StateImageViewTarget(binding.thumbnail, binding.progress))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.browse.source.browse
|
|||
|
||||
import android.view.View
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
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.
|
||||
|
@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
|||
* @param adapter the adapter handling this holder.
|
||||
*/
|
||||
abstract class SourceHolder(view: View, adapter: FlexibleAdapter<*>) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
/**
|
||||
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
|
||||
|
|
|
@ -10,9 +10,8 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
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.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.
|
||||
|
@ -25,6 +24,8 @@ import kotlinx.android.synthetic.main.source_list_item.title
|
|||
class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
|
||||
SourceHolder(view, adapter) {
|
||||
|
||||
private val binding = SourceListItemBinding.bind(view)
|
||||
|
||||
private val favoriteColor = view.context.getResourceColor(R.attr.colorOnSurface, 0.38f)
|
||||
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.
|
||||
*/
|
||||
override fun onSetValues(manga: Manga) {
|
||||
title.text = manga.title
|
||||
title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor)
|
||||
binding.title.text = manga.title
|
||||
binding.title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
override fun setImage(manga: Manga) {
|
||||
GlideApp.with(view.context).clear(thumbnail)
|
||||
GlideApp.with(view.context).clear(binding.thumbnail)
|
||||
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
val radius = view.context.resources.getDimensionPixelSize(R.dimen.card_radius)
|
||||
|
@ -56,7 +57,7 @@ class SourceListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
|
|||
.apply(requestOptions)
|
||||
.dontAnimate()
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(thumbnail)
|
||||
.into(binding.thumbnail)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,18 +2,17 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch
|
|||
|
||||
import android.view.View
|
||||
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.glide.GlideApp
|
||||
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 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) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = GlobalSearchControllerCardItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
// Call onMangaClickListener when item is pressed.
|
||||
|
@ -33,17 +32,17 @@ class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) :
|
|||
}
|
||||
|
||||
fun bind(manga: Manga) {
|
||||
card.clipToOutline = true
|
||||
binding.card.clipToOutline = true
|
||||
|
||||
title.text = manga.title
|
||||
binding.title.text = manga.title
|
||||
// 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)
|
||||
}
|
||||
|
||||
fun setImage(manga: Manga) {
|
||||
GlideApp.with(itemView.context).clear(cover)
|
||||
GlideApp.with(itemView.context).clear(binding.cover)
|
||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||
GlideApp.with(itemView.context)
|
||||
.load(manga.toMangaThumbnail())
|
||||
|
@ -51,7 +50,7 @@ class GlobalSearchCardHolder(view: View, adapter: GlobalSearchCardAdapter) :
|
|||
.centerCrop()
|
||||
.skipMemoryCache(true)
|
||||
.placeholder(android.R.color.transparent)
|
||||
.into(StateImageViewTarget(cover, progress))
|
||||
.into(StateImageViewTarget(binding.cover, binding.progress))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,11 @@ package eu.kanade.tachiyomi.ui.browse.source.globalsearch
|
|||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.databinding.GlobalSearchControllerCardBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
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.
|
||||
|
@ -21,7 +16,9 @@ import kotlinx.android.synthetic.main.global_search_controller_card.title_wrappe
|
|||
* @param adapter instance of [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.
|
||||
|
@ -32,10 +29,10 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
|
|||
|
||||
init {
|
||||
// Set layout horizontal.
|
||||
recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false)
|
||||
recycler.adapter = mangaAdapter
|
||||
binding.recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.HORIZONTAL, false)
|
||||
binding.recycler.adapter = mangaAdapter
|
||||
|
||||
title_wrapper.setOnClickListener {
|
||||
binding.titleWrapper.setOnClickListener {
|
||||
adapter.getItem(bindingAdapterPosition)?.let {
|
||||
adapter.titleClickListener.onTitleClick(it.source)
|
||||
}
|
||||
|
@ -53,21 +50,21 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
|
|||
|
||||
val titlePrefix = if (item.highlighted) "▶ " else ""
|
||||
|
||||
title.text = titlePrefix + source.name
|
||||
subtitle.isVisible = source !is LocalSource
|
||||
subtitle.text = LocaleHelper.getDisplayName(source.lang)
|
||||
binding.title.text = titlePrefix + source.name
|
||||
binding.subtitle.isVisible = source !is LocalSource
|
||||
binding.subtitle.text = LocaleHelper.getDisplayName(source.lang)
|
||||
|
||||
when {
|
||||
results == null -> {
|
||||
progress.isVisible = true
|
||||
binding.progress.isVisible = true
|
||||
showResultsHolder()
|
||||
}
|
||||
results.isEmpty() -> {
|
||||
progress.isVisible = false
|
||||
binding.progress.isVisible = false
|
||||
showNoResults()
|
||||
}
|
||||
else -> {
|
||||
progress.isVisible = false
|
||||
binding.progress.isVisible = false
|
||||
showResultsHolder()
|
||||
}
|
||||
}
|
||||
|
@ -104,10 +101,10 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
|
|||
}
|
||||
|
||||
private fun showResultsHolder() {
|
||||
no_results_found.isVisible = false
|
||||
binding.noResultsFound.isVisible = false
|
||||
}
|
||||
|
||||
private fun showNoResults() {
|
||||
no_results_found.isVisible = true
|
||||
binding.noResultsFound.isVisible = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package eu.kanade.tachiyomi.ui.category
|
||||
|
||||
import android.view.View
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.data.database.models.Category
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.categories_item.reorder
|
||||
import kotlinx.android.synthetic.main.categories_item.title
|
||||
import eu.kanade.tachiyomi.databinding.CategoriesItemBinding
|
||||
|
||||
/**
|
||||
* 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 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 {
|
||||
setDragHandleView(reorder)
|
||||
setDragHandleView(binding.reorder)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +25,7 @@ class CategoryHolder(view: View, val adapter: CategoryAdapter) : BaseFlexibleVie
|
|||
* @param category The category to bind.
|
||||
*/
|
||||
fun bind(category: Category) {
|
||||
title.text = category.name
|
||||
binding.title.text = category.name
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package eu.kanade.tachiyomi.ui.download
|
||||
|
||||
import android.view.View
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
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 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.
|
||||
|
@ -20,11 +15,13 @@ import kotlinx.android.synthetic.main.download_item.reorder
|
|||
* @constructor creates a new download holder.
|
||||
*/
|
||||
class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = DownloadItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
setDragHandleView(reorder)
|
||||
menu.setOnClickListener { it.post { showPopupMenu(it) } }
|
||||
setDragHandleView(binding.reorder)
|
||||
binding.menu.setOnClickListener { it.post { showPopupMenu(it) } }
|
||||
}
|
||||
|
||||
private lateinit var download: Download
|
||||
|
@ -37,19 +34,19 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
|
|||
fun bind(download: Download) {
|
||||
this.download = download
|
||||
// Update the chapter name.
|
||||
chapter_title.text = download.chapter.name
|
||||
binding.chapterTitle.text = download.chapter.name
|
||||
|
||||
// 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
|
||||
val pages = download.pages
|
||||
if (pages == null) {
|
||||
download_progress.progress = 0
|
||||
download_progress.max = 1
|
||||
download_progress_text.text = ""
|
||||
binding.downloadProgress.progress = 0
|
||||
binding.downloadProgress.max = 1
|
||||
binding.downloadProgressText.text = ""
|
||||
} else {
|
||||
download_progress.max = pages.size * 100
|
||||
binding.downloadProgress.max = pages.size * 100
|
||||
notifyProgress()
|
||||
notifyDownloadedPages()
|
||||
}
|
||||
|
@ -60,10 +57,10 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
|
|||
*/
|
||||
fun notifyProgress() {
|
||||
val pages = download.pages ?: return
|
||||
if (download_progress.max == 1) {
|
||||
download_progress.max = pages.size * 100
|
||||
if (binding.downloadProgress.max == 1) {
|
||||
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() {
|
||||
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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
* collapsing AppBarLayout.
|
||||
* Used to manually offset a view within the activity's child views that might be cut off due to
|
||||
* the collapsing AppBarLayout.
|
||||
*/
|
||||
fun fixViewToBottom(view: View) {
|
||||
binding.appbar.addOnOffsetChangedListener(
|
||||
|
|
|
@ -5,25 +5,24 @@ import android.text.SpannableStringBuilder
|
|||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
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 eu.kanade.tachiyomi.databinding.ChaptersItemBinding
|
||||
import java.util.Date
|
||||
|
||||
class ChapterHolder(
|
||||
view: View,
|
||||
private val adapter: ChaptersAdapter
|
||||
) : BaseFlexibleViewHolder(view, adapter) {
|
||||
) : FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = ChaptersItemBinding.bind(view)
|
||||
|
||||
fun bind(item: ChapterItem, manga: Manga) {
|
||||
val chapter = item.chapter
|
||||
|
||||
chapter_title.text = when (manga.displayMode) {
|
||||
binding.chapterTitle.text = when (manga.displayMode) {
|
||||
Manga.DISPLAY_NUMBER -> {
|
||||
val number = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
|
||||
itemView.context.getString(R.string.display_mode_chapter, number)
|
||||
|
@ -37,16 +36,16 @@ class ChapterHolder(
|
|||
chapter.bookmark -> adapter.bookmarkedColor
|
||||
else -> adapter.unreadColor
|
||||
}
|
||||
chapter_title.setTextColor(chapterTitleColor)
|
||||
binding.chapterTitle.setTextColor(chapterTitleColor)
|
||||
|
||||
val chapterDescriptionColor = when {
|
||||
chapter.read -> adapter.readColor
|
||||
chapter.bookmark -> adapter.bookmarkedColor
|
||||
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>()
|
||||
|
||||
|
@ -64,15 +63,15 @@ class ChapterHolder(
|
|||
}
|
||||
|
||||
if (descriptions.isNotEmpty()) {
|
||||
chapter_description.text = descriptions.joinTo(SpannableStringBuilder(), " • ")
|
||||
binding.chapterDescription.text = descriptions.joinTo(SpannableStringBuilder(), " • ")
|
||||
} else {
|
||||
chapter_description.text = ""
|
||||
binding.chapterDescription.text = ""
|
||||
}
|
||||
|
||||
notifyStatus(item.status)
|
||||
}
|
||||
|
||||
fun notifyStatus(status: Int) = with(download_text) {
|
||||
fun notifyStatus(status: Int) = with(binding.downloadText) {
|
||||
when (status) {
|
||||
Download.QUEUE -> setText(R.string.chapter_queued)
|
||||
Download.DOWNLOADING -> setText(R.string.chapter_downloading)
|
||||
|
|
|
@ -2,18 +2,13 @@ package eu.kanade.tachiyomi.ui.recent.history
|
|||
|
||||
import android.view.View
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
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 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
|
||||
|
||||
/**
|
||||
|
@ -28,18 +23,20 @@ import java.util.Date
|
|||
class HistoryHolder(
|
||||
view: View,
|
||||
val adapter: HistoryAdapter
|
||||
) : BaseFlexibleViewHolder(view, adapter) {
|
||||
) : FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = HistoryItemBinding.bind(view)
|
||||
|
||||
init {
|
||||
holder.setOnClickListener {
|
||||
binding.holder.setOnClickListener {
|
||||
adapter.itemClickListener.onItemClick(bindingAdapterPosition)
|
||||
}
|
||||
|
||||
remove.setOnClickListener {
|
||||
binding.remove.setOnClickListener {
|
||||
adapter.removeClickListener.onRemoveClick(bindingAdapterPosition)
|
||||
}
|
||||
|
||||
resume.setOnClickListener {
|
||||
binding.resume.setOnClickListener {
|
||||
adapter.resumeClickListener.onResumeClick(bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
@ -54,26 +51,26 @@ class HistoryHolder(
|
|||
val (manga, chapter, history) = item
|
||||
|
||||
// Set manga title
|
||||
manga_title.text = manga.title
|
||||
binding.mangaTitle.text = manga.title
|
||||
|
||||
// Set chapter number + timestamp
|
||||
if (chapter.chapter_number > -1f) {
|
||||
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,
|
||||
formattedNumber,
|
||||
Date(history.last_read).toTimestampString()
|
||||
)
|
||||
} else {
|
||||
manga_subtitle.text = Date(history.last_read).toTimestampString()
|
||||
binding.mangaSubtitle.text = Date(history.last_read).toTimestampString()
|
||||
}
|
||||
|
||||
// Set cover
|
||||
GlideApp.with(itemView.context).clear(cover)
|
||||
GlideApp.with(itemView.context).clear(binding.cover)
|
||||
GlideApp.with(itemView.context)
|
||||
.load(manga.toMangaThumbnail())
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
.into(cover)
|
||||
.into(binding.cover)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.RoundedCorners
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
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 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
|
||||
|
@ -27,7 +24,9 @@ import kotlinx.android.synthetic.main.updates_item.manga_title
|
|||
* @constructor creates a new recent chapter holder.
|
||||
*/
|
||||
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 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
|
||||
|
||||
init {
|
||||
manga_cover.setOnClickListener {
|
||||
binding.mangaCover.setOnClickListener {
|
||||
adapter.coverClickListener.onCoverClick(bindingAdapterPosition)
|
||||
}
|
||||
}
|
||||
|
@ -52,25 +51,25 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
|||
this.item = item
|
||||
|
||||
// Set chapter title
|
||||
chapter_title.text = item.chapter.name
|
||||
binding.chapterTitle.text = item.chapter.name
|
||||
|
||||
// Set manga title
|
||||
manga_title.text = item.manga.title
|
||||
binding.mangaTitle.text = item.manga.title
|
||||
|
||||
// Check if chapter is read and set correct color
|
||||
if (item.chapter.read) {
|
||||
chapter_title.setTextColor(readColor)
|
||||
manga_title.setTextColor(readColor)
|
||||
binding.chapterTitle.setTextColor(readColor)
|
||||
binding.mangaTitle.setTextColor(readColor)
|
||||
} else {
|
||||
chapter_title.setTextColor(unreadColor)
|
||||
manga_title.setTextColor(unreadColor)
|
||||
binding.chapterTitle.setTextColor(unreadColor)
|
||||
binding.mangaTitle.setTextColor(unreadColor)
|
||||
}
|
||||
|
||||
// Set chapter status
|
||||
notifyStatus(item.status)
|
||||
|
||||
// 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 requestOptions = RequestOptions().transform(CenterCrop(), RoundedCorners(radius))
|
||||
|
@ -79,7 +78,7 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter)
|
|||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.apply(requestOptions)
|
||||
.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
|
||||
*/
|
||||
fun notifyStatus(status: Int) = with(download_text) {
|
||||
fun notifyStatus(status: Int) = with(binding.downloadText) {
|
||||
when (status) {
|
||||
Download.QUEUE -> setText(R.string.chapter_queued)
|
||||
Download.DOWNLOADING -> setText(R.string.chapter_downloading)
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package eu.kanade.tachiyomi.ui.setting.search
|
||||
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||
import kotlinx.android.synthetic.main.settings_search_controller_card.search_result_pref_breadcrumb
|
||||
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 eu.davidea.viewholders.FlexibleViewHolder
|
||||
import eu.kanade.tachiyomi.databinding.SettingsSearchControllerCardBinding
|
||||
import kotlin.reflect.full.createInstance
|
||||
|
||||
/**
|
||||
|
@ -15,10 +12,12 @@ import kotlin.reflect.full.createInstance
|
|||
* @param adapter instance of [SettingsSearchAdapter]
|
||||
*/
|
||||
class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
|
||||
BaseFlexibleViewHolder(view, adapter) {
|
||||
FlexibleViewHolder(view, adapter) {
|
||||
|
||||
private val binding = SettingsSearchControllerCardBinding.bind(view)
|
||||
|
||||
init {
|
||||
title_wrapper.setOnClickListener {
|
||||
binding.titleWrapper.setOnClickListener {
|
||||
adapter.getItem(bindingAdapterPosition)?.let {
|
||||
val ctrl = it.settingsSearchResult.searchController::class.createInstance()
|
||||
ctrl.preferenceKey = it.settingsSearchResult.key
|
||||
|
@ -35,8 +34,8 @@ class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
|
|||
* @param item item of card.
|
||||
*/
|
||||
fun bind(item: SettingsSearchItem) {
|
||||
search_result_pref_title.text = item.settingsSearchResult.title
|
||||
search_result_pref_summary.text = item.settingsSearchResult.summary
|
||||
search_result_pref_breadcrumb.text = item.settingsSearchResult.breadcrumb
|
||||
binding.searchResultPrefTitle.text = item.settingsSearchResult.title
|
||||
binding.searchResultPrefSummary.text = item.settingsSearchResult.summary
|
||||
binding.searchResultPrefBreadcrumb.text = item.settingsSearchResult.breadcrumb
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue