From 89f4ad393b40aa74c953c22907c6a2b1e66df033 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 29 Mar 2021 23:07:05 -0400 Subject: [PATCH] Binding Holders I'm in absolute pain --- .../tachiyomi/ui/download/DownloadHolder.kt | 41 +++++++++---------- .../details/ExtensionDetailsHeaderAdapter.kt | 25 +++++------ .../ui/manga/track/TrackSearchAdapter.kt | 38 +++++++++-------- .../tachiyomi/ui/migration/SelectionHeader.kt | 7 ++-- .../ui/recent_updates/RecentChapterHolder.kt | 36 ++++++++-------- .../ui/recently_read/RecentlyReadHolder.kt | 21 +++++----- .../ui/recents/RecentMangaHeaderItem.kt | 15 +++---- .../ui/setting/search/SettingsSearchHolder.kt | 11 ++--- .../kanade/tachiyomi/ui/source/LangHolder.kt | 5 ++- .../source/browse/BrowseSourceGridHolder.kt | 20 ++++----- .../ui/source/browse/BrowseSourceItem.kt | 23 ++++++----- .../source/browse/BrowseSourceListHolder.kt | 14 ++++--- .../global_search/GlobalSearchHolder.kt | 24 ++++++----- .../global_search/GlobalSearchMangaHolder.kt | 11 ++--- app/src/main/res/layout/download_item.xml | 14 +++---- .../res/layout/migration_process_item.xml | 20 ++++----- .../main/res/layout/recent_chapters_item.xml | 13 +++--- 17 files changed, 176 insertions(+), 162 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt index 202b327c97..b282e194ea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt @@ -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 } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt index 06a0b05a82..e1775bf7b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/details/ExtensionDetailsHeaderAdapter.kt @@ -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() { @@ -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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt index a33616d57a..13a48a7486 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt @@ -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(context, R.layout.track_search_item, ArrayList()) { @@ -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 } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt index 6bf33dfef2..e26a2a4b09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SelectionHeader.kt @@ -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() { * Creates a new view holder for this item. */ override fun createViewHolder(view: View, adapter: FlexibleAdapter>): Holder { - return SelectionHeader.Holder(view, adapter) + return Holder(view, adapter) } /** @@ -42,7 +42,8 @@ class SelectionHeader : AbstractHeaderItem() { class Holder(view: View, adapter: FlexibleAdapter>) : 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt index d14bcd88ad..4ea8cb48c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChapterHolder.kt @@ -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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt index 886654b2a6..6a80f83425 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recently_read/RecentlyReadHolder.kt @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHeaderItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHeaderItem.kt index ffaf94bb8d..e11d631269 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHeaderItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHeaderItem.kt @@ -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() { @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt index 2c63bbe1a9..5d64608a7a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHolder.kt @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt index 4f81ccdc4d..6e1389f3db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/LangHolder.kt @@ -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>) : 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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt index 995579d5c7..42fab9c37c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceGridHolder.kt @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt index 3460fd0411..132cc5b17f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceItem.kt @@ -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 { + binding.card.updateLayoutParams { 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() ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt index ec2dbb13dd..543d596a42 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceListHolder.kt @@ -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>) : 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? = 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() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchMangaHolder.kt index b1c813c01f..c3975ae00e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchMangaHolder.kt @@ -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) } } diff --git a/app/src/main/res/layout/download_item.xml b/app/src/main/res/layout/download_item.xml index 9728d55b88..2ac312a1c8 100644 --- a/app/src/main/res/layout/download_item.xml +++ b/app/src/main/res/layout/download_item.xml @@ -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" /> @@ -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)" /> @@ -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" /> @@ -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" /> \ No newline at end of file diff --git a/app/src/main/res/layout/recent_chapters_item.xml b/app/src/main/res/layout/recent_chapters_item.xml index ab8683af7b..18b7a49312 100644 --- a/app/src/main/res/layout/recent_chapters_item.xml +++ b/app/src/main/res/layout/recent_chapters_item.xml @@ -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" />