mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 03:59:16 +01:00
Highlighting part of library text when searching in library
Only for comfort grid and list view Also show artist in comfort gird if it can fit
This commit is contained in:
parent
f1a6c9eea3
commit
970df326e8
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user