Use bookmark icon instead of changing text color

Didn't look at the upstream code for this, but maybe should've
This commit is contained in:
Jay 2020-05-19 02:41:02 -04:00
parent 6341077abf
commit 27bc2bacfb
4 changed files with 55 additions and 23 deletions

View File

@ -47,10 +47,7 @@ class ChapterHolder(
localSource = manga.source == LocalSource.ID localSource = manga.source == LocalSource.ID
download_button.visibleIf(!localSource && !isLocked) download_button.visibleIf(!localSource && !isLocked)
val chapterColor = ChapterUtil.chapterColor(itemView.context, item, isLocked) ChapterUtil.setTextViewForChapter(chapter_title, item, hideStatus = isLocked)
// Set correct text color
chapter_title.setTextColor(chapterColor)
val statuses = mutableListOf<String>() val statuses = mutableListOf<String>()
@ -83,7 +80,9 @@ class ChapterHolder(
) )
} }
// this will color the scanlator the same bookmarks // this will color the scanlator the same bookmarks
chapter_scanlator.setTextColor(chapterColor) ChapterUtil.setTextViewForChapter(
chapter_scanlator, item, showBookmark = false, hideStatus = isLocked
)
chapter_scanlator.text = statuses.joinToString("") chapter_scanlator.text = statuses.joinToString("")
val status = when { val status = when {
@ -94,8 +93,7 @@ class ChapterHolder(
notifyStatus(status, item.isLocked, item.progress) notifyStatus(status, item.isLocked, item.progress)
resetFrontView() resetFrontView()
if (adapterPosition == 1) { if (adapterPosition == 1) {
if (!adapter.hasShownSwipeTut.get()) if (!adapter.hasShownSwipeTut.get()) showSlideAnimation()
showSlideAnimation()
} }
} }

View File

@ -16,8 +16,8 @@ import java.text.DecimalFormat
import java.text.DecimalFormatSymbols import java.text.DecimalFormatSymbols
class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: Boolean) : class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: Boolean) :
AbstractItem<ReaderChapterItem.ViewHolder> AbstractItem<ReaderChapterItem.ViewHolder>(),
() { Chapter by chapter {
val decimalFormat = val decimalFormat =
DecimalFormat("#.###", DecimalFormatSymbols().apply { decimalSeparator = '.' }) DecimalFormat("#.###", DecimalFormatSymbols().apply { decimalSeparator = '.' })
@ -28,9 +28,7 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
/** defines the layout which will be used for this item in the list */ /** defines the layout which will be used for this item in the list */
override val layoutRes: Int = R.layout.reader_chapter_item override val layoutRes: Int = R.layout.reader_chapter_item
override var identifier: Long override var identifier: Long = chapter.id!!
get() = chapter.id!!
set(value) {}
override fun getViewHolder(v: View): ViewHolder { override fun getViewHolder(v: View): ViewHolder {
return ViewHolder(v) return ViewHolder(v)
@ -43,23 +41,22 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
private var bookmarkImage: ImageView = view.findViewById(R.id.bookmark_image) private var bookmarkImage: ImageView = view.findViewById(R.id.bookmark_image)
override fun bindView(item: ReaderChapterItem, payloads: List<Any>) { override fun bindView(item: ReaderChapterItem, payloads: List<Any>) {
val chapter = item.chapter
val manga = item.manga val manga = item.manga
val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter) val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter)
chapterTitle.setTextColor(chapterColor) ChapterUtil.setTextViewForChapter(chapterTitle, item)
chapterTitle.text = when (manga.displayMode) { chapterTitle.text = when (manga.displayMode) {
Manga.DISPLAY_NUMBER -> { Manga.DISPLAY_NUMBER -> {
val number = item.decimalFormat.format(chapter.chapter_number.toDouble()) val number = item.decimalFormat.format(item.chapter_number.toDouble())
itemView.context.getString(R.string.chapter_, number) itemView.context.getString(R.string.chapter_, number)
} }
else -> chapter.name else -> item.name
} }
val statuses = mutableListOf<String>() val statuses = mutableListOf<String>()
ChapterUtil.relativeDate(chapter)?.let { statuses.add(it) } ChapterUtil.relativeDate(item)?.let { statuses.add(it) }
chapter.scanlator?.isNotBlank()?.let { statuses.add(chapter.scanlator!!) } item.scanlator?.isNotBlank()?.let { statuses.add(item.scanlator!!) }
if (item.isCurrent) { if (item.isCurrent) {
chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC) chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC)
@ -73,11 +70,11 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
chapterSubtitle.setTextColor(chapterColor) chapterSubtitle.setTextColor(chapterColor)
bookmarkImage.setImageResource( bookmarkImage.setImageResource(
if (chapter.bookmark) R.drawable.ic_bookmark_24dp if (item.bookmark) R.drawable.ic_bookmark_24dp
else R.drawable.ic_bookmark_border_24dp else R.drawable.ic_bookmark_border_24dp
) )
val drawableColor = ChapterUtil.bookmarkColor(itemView.context, chapter) val drawableColor = ChapterUtil.bookmarkColor(itemView.context, item)
DrawableCompat.setTint(bookmarkImage.drawable, drawableColor) DrawableCompat.setTint(bookmarkImage.drawable, drawableColor)

View File

@ -38,7 +38,7 @@ class RecentMangaHolder(
title.apply { title.apply {
text = item.chapter.name text = item.chapter.name
setTextColor(ChapterUtil.chapterColor(context, item)) ChapterUtil.setTextViewForChapter(this, item)
} }
subtitle.apply { subtitle.apply {
text = item.mch.manga.title text = item.mch.manga.title

View File

@ -1,10 +1,15 @@
package eu.kanade.tachiyomi.util.chapter package eu.kanade.tachiyomi.util.chapter
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.widget.TextView
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.util.system.contextCompatColor import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.dpToPxEnd
import eu.kanade.tachiyomi.util.system.timeSpanFromNow import eu.kanade.tachiyomi.util.system.timeSpanFromNow
class ChapterUtil { class ChapterUtil {
@ -17,11 +22,43 @@ class ChapterUtil {
} }
} }
fun setTextViewForChapter(
textView: TextView,
chapter: Chapter,
showBookmark: Boolean = true,
hideStatus: Boolean = false
) {
val context = textView.context
textView.setTextColor(chapterColor(context, chapter, hideStatus))
if (!hideStatus && showBookmark) {
setBookmark(textView, chapter)
}
}
fun setBookmark(textView: TextView, chapter: Chapter) {
if (chapter.bookmark) {
val context = textView.context
val drawable = VectorDrawableCompat.create(
textView.resources, R.drawable.ic_bookmark_24dp, context.theme
)
drawable?.setBounds(0, 0, textView.textSize.toInt(), textView.textSize.toInt())
textView.setCompoundDrawablesRelative(
drawable, null, null, null
)
textView.compoundDrawableTintList = ColorStateList.valueOf(
bookmarkedColor(context)
)
textView.compoundDrawablePadding = 3.dpToPx
textView.translationX = (-2f).dpToPxEnd
} else {
textView.setCompoundDrawablesRelative(null, null, null, null)
textView.translationX = 0f
}
}
fun chapterColor(context: Context, chapter: Chapter, hideStatus: Boolean = false): Int { fun chapterColor(context: Context, chapter: Chapter, hideStatus: Boolean = false): Int {
return when { return when {
hideStatus -> unreadColor(context) hideStatus -> unreadColor(context)
chapter.bookmark && chapter.read -> bookmarkedAndReadColor(context)
chapter.bookmark -> bookmarkedColor(context)
chapter.read -> readColor(context) chapter.read -> readColor(context)
else -> unreadColor(context) else -> unreadColor(context)
} }