diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 4ae573a94c..33a4b96aac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -11,6 +11,7 @@ import coil.size.Scale import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga import eu.kanade.tachiyomi.databinding.MangaGridItemBinding +import eu.kanade.tachiyomi.util.lang.highlightText /** * Class used to hold the displayed data of a manga in the library, like the cover or the title. @@ -55,10 +56,25 @@ class LibraryGridHolder( override fun onSetValues(item: LibraryItem) { // Update the title and subtitle of the manga. binding.constraintLayout.isVisible = !item.manga.isBlank() - binding.title.text = item.manga.title - binding.subtitle.text = item.manga.author?.trim() + binding.title.text = item.manga.title.highlightText(item.filter, color) + val authorArtist = if (item.manga.author == item.manga.artist || item.manga.artist.isNullOrBlank()) { + item.manga.author?.trim() ?: "" + } else { + listOfNotNull( + item.manga.author?.trim()?.takeIf { it.isNotBlank() }, + item.manga.artist?.trim()?.takeIf { it.isNotBlank() } + ).joinToString(", ") + } + binding.subtitle.text = authorArtist.highlightText(item.filter, color) - binding.compactTitle.text = binding.title.text + binding.compactTitle.text = binding.title.text?.toString()?.highlightText(item.filter, color) + + binding.title.post { + val hasAuthorInFilter = + item.filter.isNotBlank() && authorArtist.contains(item.filter, true) + binding.subtitle.isVisible = binding.title.lineCount <= 1 || hasAuthorInFilter + binding.title.maxLines = if (hasAuthorInFilter) 1 else 2 + } setUnreadBadge(binding.unreadDownloadBadge.badgeView, item) setReadingButton(item) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt index 9f86d3f1be..cb3dffc734 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHolder.kt @@ -1,10 +1,12 @@ package eu.kanade.tachiyomi.ui.library import android.view.View +import androidx.core.graphics.ColorUtils import androidx.core.view.isVisible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder +import eu.kanade.tachiyomi.util.system.getResourceColor /** * Generic class used to hold the displayed data of a manga in the library. @@ -18,6 +20,8 @@ abstract class LibraryHolder( val adapter: LibraryCategoryAdapter ) : BaseFlexibleViewHolder(view, adapter) { + protected val color = ColorUtils.setAlphaComponent(itemView.context.getResourceColor(R.attr.colorAccent), 75) + /** * Method called from [LibraryCategoryAdapter.onBindViewHolder]. It updates the data for this * holder with the given manga. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt index 6d981e4139..4e167632bb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryItem.kt @@ -33,6 +33,7 @@ class LibraryItem( var downloadCount = -1 var unreadType = 2 + var filter = "" private val sourceManager: SourceManager by injectLazy() private val uniformSize: Boolean @@ -142,6 +143,7 @@ class LibraryItem( * @return true if the manga should be included, false otherwise. */ override fun filter(constraint: String): Boolean { + filter = constraint if (manga.isBlank() && manga.title.isBlank()) { return constraint.isEmpty() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 9dfdecdf8d..1060035511 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -7,6 +7,7 @@ import coil.clear import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.image.coil.loadLibraryManga import eu.kanade.tachiyomi.databinding.MangaListItemBinding +import eu.kanade.tachiyomi.util.lang.highlightText import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.updateLayoutParams @@ -61,14 +62,25 @@ class LibraryListHolder( binding.title.textAlignment = View.TEXT_ALIGNMENT_TEXT_START // Update the binding.title of the manga. - binding.title.text = item.manga.title + binding.title.text = item.manga.title.highlightText(item.filter, color) setUnreadBadge(binding.unreadDownloadBadge.badgeView, item) - binding.subtitle.text = item.manga.author?.trim() + val authorArtist = if (item.manga.author == item.manga.artist || item.manga.artist.isNullOrBlank()) { + item.manga.author?.trim() ?: "" + } else { + listOfNotNull( + item.manga.author?.trim()?.takeIf { it.isNotBlank() }, + item.manga.artist?.trim()?.takeIf { it.isNotBlank() } + ).joinToString(", ") + } + + binding.subtitle.text = authorArtist.highlightText(item.filter, color) + binding.title.maxLines = 2 binding.title.post { - if (binding.title.text == item.manga.title) { - binding.subtitle.isVisible = binding.title.lineCount == 1 && !item.manga.author.isNullOrBlank() - } + val hasAuthorInFilter = + item.filter.isNotBlank() && authorArtist.contains(item.filter, true) + binding.subtitle.isVisible = binding.title.lineCount <= 1 || hasAuthorInFilter + binding.title.maxLines = if (hasAuthorInFilter) 1 else 2 } // Update the cover. diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt index b698b11b1b..2ea9ef383e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/StringExtensions.kt @@ -100,6 +100,7 @@ fun CharSequence.tintText(@ColorInt color: Int): Spanned { fun String.highlightText(highlight: String, @ColorInt color: Int): Spanned { val wordToSpan: Spannable = SpannableString(this) + if (highlight.isBlank()) return wordToSpan indexesOf(highlight).forEach { wordToSpan.setSpan(BackgroundColorSpan(color), it, it + highlight.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) }