Binding Holders

I'm in absolute pain
This commit is contained in:
Jays2Kings 2021-03-29 23:07:05 -04:00
parent ea3ea165aa
commit 89f4ad393b
17 changed files with 176 additions and 162 deletions

View File

@ -4,11 +4,11 @@ import android.view.View
import androidx.appcompat.widget.PopupMenu
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.databinding.DownloadItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setVectorCompat
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.download_item.*
/**
* Class used to hold the data of a download.
@ -20,9 +20,10 @@ import kotlinx.android.synthetic.main.download_item.*
class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
BaseFlexibleViewHolder(view, adapter) {
private val binding = DownloadItemBinding.bind(view)
init {
setDragHandleView(reorder)
migration_menu.setOnClickListener { it.post { showPopupMenu(it) } }
setDragHandleView(binding.reorder)
binding.downloadMenu.setOnClickListener { it.post { showPopupMenu(it) } }
}
private lateinit var download: Download
@ -30,30 +31,30 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
/**
* Binds this holder with the given category.
*
* @param category The category to bind.
* @param download The download to bind.
*/
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
title.text = download.manga.title
binding.title.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()
}
migration_menu.visibleIf(flexibleAdapterPosition != 0 || flexibleAdapterPosition != adapter.itemCount - 1)
migration_menu.setVectorCompat(
binding.downloadMenu.visibleIf(flexibleAdapterPosition != 0 || flexibleAdapterPosition != adapter.itemCount - 1)
binding.downloadMenu.setVectorCompat(
R.drawable.ic_more_vert_24dp,
view.context
.getResourceColor(android.R.attr.textColorPrimary)
@ -65,10 +66,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.pageProgress
binding.downloadProgress.progress = download.pageProgress
}
/**
@ -76,7 +77,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) {
@ -93,8 +94,6 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
// Inflate our menu resource into the PopupMenu's Menu
popup.menuInflater.inflate(R.menu.download_single, popup.menu)
val download = item.download
popup.menu.findItem(R.id.move_to_top).isVisible = flexibleAdapterPosition != 0
popup.menu.findItem(R.id.move_to_bottom).isVisible = flexibleAdapterPosition != adapter
.itemCount - 1
@ -110,14 +109,14 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
}
override fun getFrontView(): View {
return front_view
return binding.frontView
}
override fun getRearRightView(): View {
return right_view
return binding.rightView
}
override fun getRearLeftView(): View {
return left_view
return binding.leftView
}
}

View File

@ -5,10 +5,10 @@ import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ExtensionDetailHeaderBinding
import eu.kanade.tachiyomi.ui.extension.getApplicationIcon
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.view.inflate
import kotlinx.android.synthetic.main.extension_detail_header.view.*
class ExtensionDetailsHeaderAdapter(private val presenter: ExtensionDetailsPresenter) :
RecyclerView.Adapter<ExtensionDetailsHeaderAdapter.HeaderViewHolder>() {
@ -34,28 +34,29 @@ class ExtensionDetailsHeaderAdapter(private val presenter: ExtensionDetailsPrese
inner class HeaderViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
fun bind() {
val binding = ExtensionDetailHeaderBinding.bind(view)
val extension = presenter.extension ?: return
val context = view.context
extension.getApplicationIcon(context)?.let { view.extension_icon.setImageDrawable(it) }
view.extension_title.text = extension.name
view.extension_version.text = context.getString(R.string.version_, extension.versionName)
view.extension_lang.text = context.getString(R.string.language_, LocaleHelper.getSourceDisplayName(extension.lang, context))
view.extension_nsfw.isVisible = extension.isNsfw
view.extension_pkg.text = extension.pkgName
extension.getApplicationIcon(context)?.let { binding.extensionIcon.setImageDrawable(it) }
binding.extensionTitle.text = extension.name
binding.extensionVersion.text = context.getString(R.string.version_, extension.versionName)
binding.extensionLang.text = context.getString(R.string.language_, LocaleHelper.getSourceDisplayName(extension.lang, context))
binding.extensionNsfw.isVisible = extension.isNsfw
binding.extensionPkg.text = extension.pkgName
view.extension_uninstall_button.setOnClickListener {
binding.extensionUninstallButton.setOnClickListener {
presenter.uninstallExtension()
}
if (extension.isObsolete) {
view.extension_warning_banner.isVisible = true
view.extension_warning_banner.setText(R.string.obsolete_extension_message)
binding.extensionWarningBanner.isVisible = true
binding.extensionWarningBanner.setText(R.string.obsolete_extension_message)
}
if (extension.isUnofficial) {
view.extension_warning_banner.isVisible = true
view.extension_warning_banner.setText(R.string.unofficial_extension_message)
binding.extensionWarningBanner.isVisible = true
binding.extensionWarningBanner.setText(R.string.unofficial_extension_message)
}
}
}

View File

@ -8,10 +8,11 @@ import coil.api.clear
import coil.api.load
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.track.model.TrackSearch
import eu.kanade.tachiyomi.databinding.TrackSearchItemBinding
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.inflate
import kotlinx.android.synthetic.main.track_search_item.view.*
import java.util.ArrayList
import java.util.Locale
class TrackSearchAdapter(context: Context) :
ArrayAdapter<TrackSearch>(context, R.layout.track_search_item, ArrayList<TrackSearch>()) {
@ -43,32 +44,33 @@ class TrackSearchAdapter(context: Context) :
class TrackSearchHolder(private val view: View) {
fun onSetValues(track: TrackSearch) {
view.track_search_title.text = track.title
view.track_search_summary.text = track.summary
view.track_search_cover.clear()
if (!track.cover_url.isNullOrEmpty()) {
view.track_search_cover.load(track.cover_url)
val binding = TrackSearchItemBinding.bind(view)
binding.trackSearchTitle.text = track.title
binding.trackSearchSummary.text = track.summary
binding.trackSearchCover.clear()
if (track.cover_url.isNotEmpty()) {
binding.trackSearchCover.load(track.cover_url)
}
if (track.publishing_status.isNullOrBlank()) {
view.track_search_status.gone()
view.track_search_status_result.gone()
if (track.publishing_status.isBlank()) {
binding.trackSearchStatus.gone()
binding.trackSearchStatusResult.gone()
} else {
view.track_search_status_result.text = track.publishing_status.capitalize()
binding.trackSearchStatusResult.text = track.publishing_status.capitalize(Locale.ROOT)
}
if (track.publishing_type.isNullOrBlank()) {
view.track_search_type.gone()
view.track_search_type_result.gone()
if (track.publishing_type.isBlank()) {
binding.trackSearchType.gone()
binding.trackSearchTypeResult.gone()
} else {
view.track_search_type_result.text = track.publishing_type.capitalize()
binding.trackSearchTypeResult.text = track.publishing_type.capitalize(Locale.ROOT)
}
if (track.start_date.isNullOrBlank()) {
view.track_search_start.gone()
view.track_search_start_result.gone()
if (track.start_date.isBlank()) {
binding.trackSearchStart.gone()
binding.trackSearchStartResult.gone()
} else {
view.track_search_start_result.text = track.start_date
binding.trackSearchStartResult.text = track.start_date
}
}
}

View File

@ -6,8 +6,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.SourceHeaderItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import kotlinx.android.synthetic.main.source_header_item.*
/**
* Item that contains the selection header.
@ -25,7 +25,7 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
* Creates a new view holder for this item.
*/
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder {
return SelectionHeader.Holder(view, adapter)
return Holder(view, adapter)
}
/**
@ -42,7 +42,8 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
class Holder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) : BaseFlexibleViewHolder(view, adapter) {
init {
title.text = view.context.getString(R.string.select_a_source_then_item_to_migrate)
val binding = SourceHeaderItemBinding.bind(view)
binding.title.text = view.context.getString(R.string.select_a_source_then_item_to_migrate)
}
}

View File

@ -7,11 +7,10 @@ import coil.api.clear
import coil.transform.CircleCropTransformation
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
import eu.kanade.tachiyomi.databinding.RecentChaptersItemBinding
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
import eu.kanade.tachiyomi.util.system.getResourceColor
import kotlinx.android.synthetic.main.download_button.*
import kotlinx.android.synthetic.main.recent_chapters_item.*
/**
* Holder that contains chapter item
@ -41,8 +40,9 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
*/
private var item: RecentChapterItem? = null
private val binding = RecentChaptersItemBinding.bind(view)
init {
manga_cover.setOnClickListener {
binding.mangaCover.setOnClickListener {
adapter.coverClickListener.onCoverClick(flexibleAdapterPosition)
}
}
@ -55,16 +55,16 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
fun bind(item: RecentChapterItem) {
this.item = item
// Set chapter title
chapter_title.text = item.chapter.name
// Set chapter binding.title
binding.chapterTitle.text = item.chapter.name
// Set manga title
title.text = item.manga.title
// Set manga binding.title
binding.title.text = item.manga.title
if (front_view.translationX == 0f) {
read.setImageDrawable(
if (binding.frontView.translationX == 0f) {
binding.read.setImageDrawable(
ContextCompat.getDrawable(
read.context,
binding.root.context,
if (item.read) R.drawable.ic_eye_off_24dp
else R.drawable.ic_eye_24dp
)
@ -73,15 +73,15 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
// Set cover
if ((view.context as? Activity)?.isDestroyed != true) {
manga_cover.clear()
manga_cover.loadLibraryManga(item.manga) {
binding.mangaCover.clear()
binding.mangaCover.loadLibraryManga(item.manga) {
transformations(CircleCropTransformation())
}
}
val chapterColor = ChapterUtil.chapterColor(itemView.context, item)
chapter_title.setTextColor(chapterColor)
title.setTextColor(chapterColor)
binding.chapterTitle.setTextColor(chapterColor)
binding.title.setTextColor(chapterColor)
// Set chapter status
notifyStatus(item.status, item.progress)
@ -89,15 +89,15 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
}
private fun resetFrontView() {
if (front_view.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) }
if (binding.frontView.translationX != 0f) itemView.post { adapter.notifyItemChanged(flexibleAdapterPosition) }
}
override fun getFrontView(): View {
return front_view
return binding.frontView
}
override fun getRearRightView(): View {
return right_view
return binding.rightView
}
/**
@ -106,5 +106,5 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
* @param status download status
*/
fun notifyStatus(status: Int, progress: Int) =
download_button.setDownloadStatus(status, progress)
binding.downloadButton.root.setDownloadStatus(status, progress)
}

View File

@ -5,9 +5,9 @@ import coil.api.clear
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory
import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga
import eu.kanade.tachiyomi.databinding.RecentlyReadItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.lang.toTimestampString
import kotlinx.android.synthetic.main.recently_read_item.*
import java.util.Date
/**
@ -24,16 +24,17 @@ class RecentlyReadHolder(
val adapter: RecentlyReadAdapter
) : BaseFlexibleViewHolder(view, adapter) {
private val binding = RecentlyReadItemBinding.bind(view)
init {
remove.setOnClickListener {
binding.remove.setOnClickListener {
adapter.removeClickListener.onRemoveClick(flexibleAdapterPosition)
}
resume.setOnClickListener {
binding.resume.setOnClickListener {
adapter.resumeClickListener.onResumeClick(flexibleAdapterPosition)
}
cover.setOnClickListener {
binding.cover.setOnClickListener {
adapter.coverClickListener.onCoverClick(flexibleAdapterPosition)
}
}
@ -48,18 +49,18 @@ class RecentlyReadHolder(
val (manga, chapter, history) = item
// Set manga title
title.text = manga.title
binding.title.text = manga.title
// Set source + chapter title
val formattedNumber = adapter.decimalFormat.format(chapter.chapter_number.toDouble())
manga_source.text = itemView.context.getString(R.string.source_dash_chapter_)
binding.mangaSource.text = itemView.context.getString(R.string.source_dash_chapter_)
.format(adapter.sourceManager.getOrStub(manga.source).toString(), formattedNumber)
// Set last read timestamp title
last_read.text = Date(history.last_read).toTimestampString(adapter.dateFormat)
binding.lastRead.text = Date(history.last_read).toTimestampString(adapter.dateFormat)
// Set cover
cover.clear()
cover.loadLibraryManga(manga)
// Set binding.cover
binding.cover.clear()
binding.cover.loadLibraryManga(manga)
}
}

View File

@ -6,10 +6,10 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractHeaderItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.RecentsHeaderItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.library.LibraryHeaderItem
import eu.kanade.tachiyomi.util.view.visibleIf
import kotlinx.android.synthetic.main.recents_header_item.*
class RecentMangaHeaderItem(val recentsType: Int) :
AbstractHeaderItem<RecentMangaHeaderItem.Holder>() {
@ -60,13 +60,14 @@ class RecentMangaHeaderItem(val recentsType: Int) :
true
) {
private val binding = RecentsHeaderItemBinding.bind(view)
init {
action_history.setOnClickListener { adapter.delegate.showHistory() }
action_update.setOnClickListener { adapter.delegate.showUpdates() }
binding.actionHistory.setOnClickListener { adapter.delegate.showHistory() }
binding.actionUpdate.setOnClickListener { adapter.delegate.showUpdates() }
}
fun bind(recentsType: Int) {
title.setText(
binding.title.setText(
when (recentsType) {
CONTINUE_READING -> R.string.continue_reading
NEW_CHAPTERS -> R.string.new_chapters
@ -74,9 +75,9 @@ class RecentMangaHeaderItem(val recentsType: Int) :
else -> R.string.continue_reading
}
)
action_history.visibleIf(recentsType == -1)
action_update.visibleIf(recentsType == -1)
title.visibleIf(recentsType != -1)
binding.actionHistory.visibleIf(recentsType == -1)
binding.actionUpdate.visibleIf(recentsType == -1)
binding.title.visibleIf(recentsType != -1)
}
}

View File

@ -5,8 +5,8 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.SettingsSearchControllerCardBinding
import eu.kanade.tachiyomi.util.lang.highlightText
import kotlinx.android.synthetic.main.settings_search_controller_card.view.*
import kotlin.reflect.full.createInstance
/**
@ -18,8 +18,9 @@ import kotlin.reflect.full.createInstance
class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
FlexibleViewHolder(view, adapter) {
private val binding = SettingsSearchControllerCardBinding.bind(view)
init {
view.title_wrapper.setOnClickListener {
binding.titleWrapper.setOnClickListener {
adapter.getItem(bindingAdapterPosition)?.let {
val ctrl = it.settingsSearchResult.searchController::class.createInstance()
ctrl.preferenceKey = it.settingsSearchResult.key
@ -37,8 +38,8 @@ class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) :
*/
fun bind(item: SettingsSearchItem) {
val color = ColorUtils.setAlphaComponent(ContextCompat.getColor(itemView.context, R.color.colorAccent), 75)
itemView.search_result_pref_title.text = item.settingsSearchResult.title.highlightText(item.searchResult, color)
itemView.search_result_pref_summary.text = item.settingsSearchResult.summary.highlightText(item.searchResult, color)
itemView.search_result_pref_breadcrumb.text = item.settingsSearchResult.breadcrumb.highlightText(item.searchResult, color)
binding.searchResultPrefTitle.text = item.settingsSearchResult.title.highlightText(item.searchResult, color)
binding.searchResultPrefSummary.text = item.settingsSearchResult.summary.highlightText(item.searchResult, color)
binding.searchResultPrefBreadcrumb.text = item.settingsSearchResult.breadcrumb.highlightText(item.searchResult, color)
}
}

View File

@ -4,14 +4,15 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.databinding.SourceHeaderItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.android.synthetic.main.source_header_item.*
class LangHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) :
BaseFlexibleViewHolder(view, adapter) {
fun bind(item: LangItem) {
title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
val binding = SourceHeaderItemBinding.bind(itemView)
binding.title.text = LocaleHelper.getSourceDisplayName(item.code, itemView.context)
}
}

View File

@ -12,8 +12,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.library.LibraryCategoryAdapter
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget
import kotlinx.android.synthetic.main.manga_grid_item.*
import kotlinx.android.synthetic.main.unread_download_badge.*
import eu.kanade.tachiyomi.databinding.MangaGridItemBinding
/**
* Class used to hold the displayed data of a manga in the library, like the cover or the title.
@ -30,12 +29,13 @@ class BrowseSourceGridHolder(
compact: Boolean
) : BrowseSourceHolder(view, adapter) {
private val binding = MangaGridItemBinding.bind(view)
init {
if (compact) {
text_layout.gone()
binding.textLayout.gone()
} else {
compact_title.gone()
gradient.gone()
binding.compactTitle.gone()
binding.gradient.gone()
}
}
@ -47,9 +47,9 @@ class BrowseSourceGridHolder(
*/
override fun onSetValues(manga: Manga) {
// Update the title of the manga.
title.text = manga.title
compact_title.text = title.text
badge_view.setInLibrary(manga.favorite)
binding.title.text = manga.title
binding.compactTitle.text = binding.title.text
binding.unreadDownloadBadge.root.setInLibrary(manga.favorite)
// Update the cover.
setImage(manga)
@ -58,11 +58,11 @@ class BrowseSourceGridHolder(
override fun setImage(manga: Manga) {
if ((view.context as? Activity)?.isDestroyed == true) return
if (manga.thumbnail_url == null) {
cover_thumbnail.clear()
binding.coverThumbnail.clear()
} else {
val id = manga.id ?: return
val request = LoadRequest.Builder(view.context).data(manga)
.target(CoverViewTarget(cover_thumbnail, progress)).build()
.target(CoverViewTarget(binding.coverThumbnail, binding.progress)).build()
Coil.imageLoader(view.context).execute(request)
}
}

View File

@ -15,10 +15,10 @@ import eu.davidea.flexibleadapter.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.databinding.MangaGridItemBinding
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import kotlinx.android.synthetic.main.manga_grid_item.view.*
class BrowseSourceItem(
val manga: Manga,
@ -40,32 +40,33 @@ class BrowseSourceItem(
return if (parent is AutofitRecyclerView && !catalogueAsList.getOrDefault()) {
val listType = catalogueListType.getOrDefault()
view.apply {
val binding = MangaGridItemBinding.bind(this)
val coverHeight = (parent.itemWidth / 3 * 4f).toInt()
if (listType == 1) {
gradient.layoutParams = FrameLayout.LayoutParams(
binding.gradient.layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
(coverHeight * 0.66f).toInt(),
Gravity.BOTTOM
)
card.updateLayoutParams<ConstraintLayout.LayoutParams> {
binding.card.updateLayoutParams<ConstraintLayout.LayoutParams> {
bottomMargin = 6.dpToPx
}
} else {
constraint_layout.background = ContextCompat.getDrawable(
binding.constraintLayout.background = ContextCompat.getDrawable(
context,
R.drawable.library_item_selector
)
}
constraint_layout.layoutParams = FrameLayout.LayoutParams(
binding.constraintLayout.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
cover_thumbnail.maxHeight = Int.MAX_VALUE
cover_thumbnail.minimumHeight = 0
constraint_layout.minHeight = 0
cover_thumbnail.scaleType = ImageView.ScaleType.CENTER_CROP
cover_thumbnail.adjustViewBounds = false
cover_thumbnail.layoutParams = FrameLayout.LayoutParams(
binding.coverThumbnail.maxHeight = Int.MAX_VALUE
binding.coverThumbnail.minimumHeight = 0
binding.constraintLayout.minHeight = 0
binding.coverThumbnail.scaleType = ImageView.ScaleType.CENTER_CROP
binding.coverThumbnail.adjustViewBounds = false
binding.coverThumbnail.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
(parent.itemWidth / 3f * 3.7f).toInt()
)

View File

@ -11,7 +11,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget
import kotlinx.android.synthetic.main.manga_list_item.*
import eu.kanade.tachiyomi.databinding.MangaListItemBinding
/**
* Class used to hold the displayed data of a manga in the catalogue, like the cover or the title.
@ -24,6 +24,8 @@ import kotlinx.android.synthetic.main.manga_list_item.*
class BrowseSourceListHolder(private val view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>) :
BrowseSourceHolder(view, adapter) {
private val binding = MangaListItemBinding.bind(view)
/**
* Method called from [CatalogueAdapter.onBindViewHolder]. It updates the data for this
* holder with the given manga.
@ -31,8 +33,8 @@ class BrowseSourceListHolder(private val view: View, adapter: FlexibleAdapter<IF
* @param manga the manga to bind.
*/
override fun onSetValues(manga: Manga) {
title.text = manga.title
with(subtitle) {
binding.title.text = manga.title
with(binding.subtitle) {
visibility = if (manga.favorite) View.VISIBLE else View.GONE
text = view.resources.getString(R.string.in_library)
setTextColor(view.context.getResourceColor(android.R.attr.colorAccent))
@ -44,11 +46,11 @@ class BrowseSourceListHolder(private val view: View, adapter: FlexibleAdapter<IF
override fun setImage(manga: Manga) {
// Update the cover.
if (manga.thumbnail_url == null) {
cover_thumbnail.clear()
binding.coverThumbnail.clear()
} else {
val id = manga.id ?: return
manga.id ?: return
val request = LoadRequest.Builder(view.context).data(manga)
.target(CoverViewTarget(cover_thumbnail)).build()
.target(CoverViewTarget(binding.coverThumbnail)).build()
Coil.imageLoader(view.context).execute(request)
}
}

View File

@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.ui.source.global_search
import android.view.View
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.databinding.SourceGlobalSearchControllerCardBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.source_global_search_controller_card.*
/**
* Holder that binds the [GlobalSearchItem] containing catalogue cards.
@ -23,11 +23,13 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
private var lastBoundResults: List<GlobalSearchMangaItem>? = null
private val binding = SourceGlobalSearchControllerCardBinding.bind(view)
init {
// Set layout horizontal.
recycler.layoutManager =
binding.recycler.layoutManager =
androidx.recyclerview.widget.LinearLayoutManager(view.context, androidx.recyclerview.widget.LinearLayoutManager.HORIZONTAL, false)
recycler.adapter = mangaAdapter
binding.recycler.adapter = mangaAdapter
}
/**
@ -43,20 +45,20 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
val langSuffix = if (source.lang.isNotEmpty()) " (${source.lang})" else ""
// Set Title with country code if available.
title.text = titlePrefix + source.name + langSuffix
binding.title.text = titlePrefix + source.name + langSuffix
when {
results == null -> {
progress.visible()
binding.progress.visible()
showHolder()
}
results.isEmpty() -> {
progress.gone()
no_results.visible()
source_card.gone()
binding.progress.gone()
binding.noResults.visible()
binding.sourceCard.gone()
}
else -> {
progress.gone()
binding.progress.gone()
showHolder()
}
}
@ -93,7 +95,7 @@ class GlobalSearchHolder(view: View, val adapter: GlobalSearchAdapter) :
}
private fun showHolder() {
source_card.visible()
no_results.gone()
binding.sourceCard.visible()
binding.noResults.gone()
}
}

View File

@ -9,11 +9,12 @@ import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.view.visibleIf
import eu.kanade.tachiyomi.data.image.coil.CoverViewTarget
import kotlinx.android.synthetic.main.source_global_search_controller_card_item.*
import eu.kanade.tachiyomi.databinding.SourceGlobalSearchControllerCardItemBinding
class GlobalSearchMangaHolder(view: View, adapter: GlobalSearchCardAdapter) :
BaseFlexibleViewHolder(view, adapter) {
private val binding = SourceGlobalSearchControllerCardItemBinding.bind(view)
init {
// Call onMangaClickListener when item is pressed.
itemView.setOnClickListener {
@ -32,18 +33,18 @@ class GlobalSearchMangaHolder(view: View, adapter: GlobalSearchCardAdapter) :
}
fun bind(manga: Manga) {
title.text = manga.title
favorite_button.visibleIf(manga.favorite)
binding.title.text = manga.title
binding.favoriteButton.visibleIf(manga.favorite)
setImage(manga)
}
fun setImage(manga: Manga) {
itemImage.clear()
binding.itemImage.clear()
if (!manga.thumbnail_url.isNullOrEmpty()) {
val request = LoadRequest.Builder(itemView.context).data(manga)
.placeholder(android.R.color.transparent)
.memoryCachePolicy(CachePolicy.DISABLED)
.target(CoverViewTarget(itemImage, progress)).build()
.target(CoverViewTarget(binding.itemImage, binding.progress)).build()
Coil.imageLoader(itemView.context).execute(request)
}
}

View File

@ -16,7 +16,7 @@
android:id="@+id/close_right"
android:layout_width="24dp"
android:layout_height="24dp"
android:tint="@color/md_white_1000"
app:tint="@color/md_white_1000"
android:layout_gravity="end|center"
android:contentDescription="@string/cancel"
android:layout_marginEnd="21dp"
@ -37,7 +37,7 @@
android:contentDescription="@string/cancel"
android:layout_gravity="start|center"
android:layout_marginStart="21dp"
android:tint="@color/md_white_1000"
app:tint="@color/md_white_1000"
android:src="@drawable/ic_close_24dp" />
</FrameLayout>
<androidx.constraintlayout.widget.ConstraintLayout
@ -55,7 +55,7 @@
android:layout_gravity="start"
android:contentDescription="@string/reorder"
android:scaleType="center"
android:tint="?android:attr/textColorPrimary"
app:tint="?android:attr/textColorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
@ -84,7 +84,7 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption"
app:layout_constraintEnd_toStartOf="@+id/migration_menu"
app:layout_constraintEnd_toStartOf="@+id/download_menu"
android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="@+id/title"
app:layout_constraintTop_toBottomOf="@+id/title"
@ -97,7 +97,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/migration_menu"
app:layout_constraintEnd_toStartOf="@+id/download_menu"
app:layout_constraintStart_toEndOf="@+id/reorder"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toBottomOf="@+id/chapter_title" />
@ -111,12 +111,12 @@
android:textAppearance="@style/TextAppearance.Regular.Caption.Hint"
app:layout_constraintBottom_toBottomOf="@+id/title"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toStartOf="@+id/migration_menu"
app:layout_constraintEnd_toStartOf="@+id/download_menu"
app:layout_constraintTop_toTopOf="@+id/title"
tools:text="(0/10)" />
<ImageView
android:id="@+id/migration_menu"
android:id="@+id/download_menu"
android:layout_width="44dp"
android:layout_height="@dimen/material_component_lists_single_line_with_avatar_height"
android:layout_toEndOf="@id/download_progress_text"

View File

@ -12,7 +12,7 @@
app:layout_constraintVertical_bias="1.0"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageView"
app:layout_constraintEnd_toStartOf="@id/imageView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -26,9 +26,9 @@
android:scaleType="center"
android:layout_marginBottom="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/migration_manga_card_to"
app:layout_constraintEnd_toStartOf="@id/migration_manga_card_to"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/migration_manga_card_from"
app:layout_constraintStart_toEndOf="@id/migration_manga_card_from"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_chevron_right_24dp" />
@ -39,9 +39,9 @@
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/migration_menu"
app:layout_constraintEnd_toStartOf="@id/migration_menu"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintStart_toEndOf="@id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
@ -55,7 +55,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/migration_manga_card_to"
app:layout_constraintStart_toEndOf="@id/migration_manga_card_to"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_more_vert_24dp"
android:visibility="invisible"/>
@ -65,9 +65,9 @@
android:id="@+id/skip_manga"
android:layout_width="48dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/migration_menu"
app:layout_constraintEnd_toEndOf="@+id/migration_menu"
app:layout_constraintStart_toStartOf="@+id/migration_menu"
app:layout_constraintTop_toTopOf="@+id/migration_menu"
app:layout_constraintBottom_toBottomOf="@id/migration_menu"
app:layout_constraintEnd_toEndOf="@id/migration_menu"
app:layout_constraintStart_toStartOf="@id/migration_menu"
app:layout_constraintTop_toTopOf="@id/migration_menu"
app:srcCompat="@drawable/ic_close_24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -51,9 +51,9 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Body1"
app:layout_constraintBottom_toTopOf="@+id/chapter_title"
app:layout_constraintEnd_toStartOf="@+id/download_button"
app:layout_constraintStart_toEndOf="@+id/manga_cover"
app:layout_constraintBottom_toTopOf="@id/chapter_title"
app:layout_constraintEnd_toStartOf="@id/download_button"
app:layout_constraintStart_toEndOf="@id/manga_cover"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="Manga title" />
@ -68,13 +68,14 @@
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Regular.Caption"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/download_button"
app:layout_constraintStart_toEndOf="@+id/manga_cover"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintEnd_toStartOf="@id/download_button"
app:layout_constraintStart_toEndOf="@id/manga_cover"
app:layout_constraintTop_toBottomOf="@id/title"
tools:text="Chapter title" />
<include
layout="@layout/download_button"
android:id="@+id/download_button"
android:layout_width="50dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"