mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 17:25:09 +01:00
Cleanup/Refactoring of Chapter colors
Also using util in recents
This commit is contained in:
parent
1519395267
commit
f6318d83ee
@ -2,13 +2,11 @@ package eu.kanade.tachiyomi.ui.library
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
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.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import eu.kanade.tachiyomi.util.view.isNotGone
|
|
||||||
import eu.kanade.tachiyomi.util.view.isVisible
|
import eu.kanade.tachiyomi.util.view.isVisible
|
||||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
@ -20,20 +18,20 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
|
|||||||
fun setUnreadDownload(unread: Int, downloads: Int, showTotalChapters: Boolean) {
|
fun setUnreadDownload(unread: Int, downloads: Int, showTotalChapters: Boolean) {
|
||||||
// Update the unread count and its visibility.
|
// Update the unread count and its visibility.
|
||||||
|
|
||||||
val unreadBadgeBackground = when (showTotalChapters) {
|
val unreadBadgeBackground = context.contextCompatColor(
|
||||||
true -> context.contextCompatColor(R.color.total_badge)
|
if (showTotalChapters) R.color.total_badge else R.color.unread_badge
|
||||||
false -> context.contextCompatColor(R.color.unread_badge)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
with(unread_text) {
|
with(unread_text) {
|
||||||
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
|
visibleIf(unread > 0 || unread == -1 || showTotalChapters)
|
||||||
|
if (!isVisible()) { return@with }
|
||||||
text = if (unread == -1) "0" else unread.toString()
|
text = if (unread == -1) "0" else unread.toString()
|
||||||
setTextColor(
|
setTextColor(
|
||||||
when (unread == -1 && !showTotalChapters) {
|
context.contextCompatColor(
|
||||||
true -> context.contextCompatColor(R.color.unread_badge) // hide the 0 in the badge
|
// hide the badge text when preference is only show badge
|
||||||
false -> context.contextCompatColor(R.color.unread_badge_text)
|
if (unread == -1 && !showTotalChapters) R.color.unread_badge
|
||||||
}
|
else R.color.unread_badge_text
|
||||||
|
)
|
||||||
)
|
)
|
||||||
setBackgroundColor(unreadBadgeBackground)
|
setBackgroundColor(unreadBadgeBackground)
|
||||||
}
|
}
|
||||||
@ -41,6 +39,7 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
|
|||||||
// Update the download count or local status and its visibility.
|
// Update the download count or local status and its visibility.
|
||||||
with(download_text) {
|
with(download_text) {
|
||||||
visibleIf(downloads == -2 || downloads > 0)
|
visibleIf(downloads == -2 || downloads > 0)
|
||||||
|
if (!isVisible()) { return@with }
|
||||||
text = if (downloads == -2) {
|
text = if (downloads == -2) {
|
||||||
resources.getString(R.string.local)
|
resources.getString(R.string.local)
|
||||||
} else {
|
} else {
|
||||||
@ -49,10 +48,10 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show the badge card if unread or downloads exists
|
// Show the badge card if unread or downloads exists
|
||||||
this.visibleIf(download_text.isVisible() || unread_text.isNotGone())
|
visibleIf(download_text.isVisible() || unread_text.isVisible())
|
||||||
|
|
||||||
// Show the angles divider if both unread and downloads exists
|
// Show the angles divider if both unread and downloads exists
|
||||||
unread_angle.visibleIf(download_text.isVisible() && unread_text.isNotGone())
|
unread_angle.visibleIf(download_text.isVisible() && unread_text.isVisible())
|
||||||
|
|
||||||
unread_angle.setColorFilter(unreadBadgeBackground)
|
unread_angle.setColorFilter(unreadBadgeBackground)
|
||||||
if (unread_angle.isVisible()) {
|
if (unread_angle.isVisible()) {
|
||||||
|
@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterAdapter
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.DecimalFormatSymbols
|
import java.text.DecimalFormatSymbols
|
||||||
@ -25,14 +24,6 @@ class MangaDetailsAdapter(
|
|||||||
val delegate: MangaDetailsInterface = controller
|
val delegate: MangaDetailsInterface = controller
|
||||||
val presenter = controller.presenter
|
val presenter = controller.presenter
|
||||||
|
|
||||||
val readColor = ChapterUtil.readColor(context)
|
|
||||||
|
|
||||||
val unreadColor = ChapterUtil.unreadColor(context)
|
|
||||||
|
|
||||||
val bookmarkedColor = ChapterUtil.bookmarkedColor(context)
|
|
||||||
|
|
||||||
val bookmarkedAndReadColor = ChapterUtil.bookmarkedAndReadColor(context)
|
|
||||||
|
|
||||||
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
val decimalFormat = DecimalFormat("#.###", DecimalFormatSymbols()
|
||||||
.apply { decimalSeparator = '.' })
|
.apply { decimalSeparator = '.' })
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.data.download.model.Download
|
|||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaDetailsAdapter
|
import eu.kanade.tachiyomi.ui.manga.MangaDetailsAdapter
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||||
import eu.kanade.tachiyomi.util.system.contextCompatDrawable
|
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
import kotlinx.android.synthetic.main.chapters_item.*
|
import kotlinx.android.synthetic.main.chapters_item.*
|
||||||
@ -41,13 +40,7 @@ class ChapterHolder(
|
|||||||
localSource = manga.source == LocalSource.ID
|
localSource = manga.source == LocalSource.ID
|
||||||
download_button.visibleIf(!localSource && !isLocked)
|
download_button.visibleIf(!localSource && !isLocked)
|
||||||
|
|
||||||
var chapterColor = when {
|
val chapterColor = ChapterUtil.chapterColor(itemView.context, item, isLocked)
|
||||||
isLocked -> adapter.unreadColor
|
|
||||||
chapter.bookmark && chapter.read -> adapter.bookmarkedAndReadColor
|
|
||||||
chapter.bookmark -> adapter.bookmarkedColor
|
|
||||||
chapter.read -> adapter.readColor
|
|
||||||
else -> adapter.unreadColor
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set correct text color
|
// Set correct text color
|
||||||
chapter_title.setTextColor(chapterColor)
|
chapter_title.setTextColor(chapterColor)
|
||||||
@ -75,30 +68,20 @@ class ChapterHolder(
|
|||||||
chapter.scanlator?.isNotBlank()?.let { statuses.add(chapter.scanlator!!) }
|
chapter.scanlator?.isNotBlank()?.let { statuses.add(chapter.scanlator!!) }
|
||||||
|
|
||||||
if (front_view.translationX == 0f) {
|
if (front_view.translationX == 0f) {
|
||||||
read.setImageDrawable(
|
read.setImageResource(
|
||||||
read.context.contextCompatDrawable(
|
if (item.read) R.drawable.ic_eye_off_24dp else R.drawable.ic_eye_24dp
|
||||||
when (item.read) {
|
|
||||||
true -> R.drawable.ic_eye_off_24dp
|
|
||||||
false -> R.drawable.ic_eye_24dp
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
bookmark.setImageDrawable(
|
|
||||||
read.context.contextCompatDrawable(
|
|
||||||
when (item.bookmark) {
|
|
||||||
true -> R.drawable.ic_bookmark_off_24dp
|
|
||||||
false -> R.drawable.ic_bookmark_24dp
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
bookmark.setImageResource(
|
||||||
|
if (item.bookmark) R.drawable.ic_bookmark_off_24dp else R.drawable.ic_bookmark_24dp
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// this will color the scanlator the same bookmarks
|
// this will color the scanlator the same bookmarks
|
||||||
chapter_scanlator.setTextColor(chapterColor)
|
chapter_scanlator.setTextColor(chapterColor)
|
||||||
chapter_scanlator.text = statuses.joinToString(" • ")
|
chapter_scanlator.text = statuses.joinToString(" • ")
|
||||||
|
|
||||||
val status = when (adapter.isSelected(adapterPosition)) {
|
val status = when {
|
||||||
true -> Download.CHECKED
|
adapter.isSelected(adapterPosition) -> Download.CHECKED
|
||||||
false -> item.status
|
else -> item.status
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyStatus(status, item.isLocked, item.progress)
|
notifyStatus(status, item.isLocked, item.progress)
|
||||||
|
@ -12,7 +12,6 @@ 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.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||||
import eu.kanade.tachiyomi.util.system.contextCompatDrawable
|
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.text.DecimalFormatSymbols
|
import java.text.DecimalFormatSymbols
|
||||||
|
|
||||||
@ -38,29 +37,16 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ViewHolder(view: View) : FastAdapter.ViewHolder<ReaderChapterItem>(view) {
|
class ViewHolder(view: View) : FastAdapter.ViewHolder<ReaderChapterItem>(view) {
|
||||||
var chapterTitle: TextView = view.findViewById(R.id.chapter_title)
|
private var chapterTitle: TextView = view.findViewById(R.id.chapter_title)
|
||||||
var chapterSubtitle: TextView = view.findViewById(R.id.chapter_scanlator)
|
private var chapterSubtitle: TextView = view.findViewById(R.id.chapter_scanlator)
|
||||||
var bookmarkButton: FrameLayout = view.findViewById(R.id.bookmark_layout)
|
var bookmarkButton: FrameLayout = view.findViewById(R.id.bookmark_layout)
|
||||||
var bookmarkImage: ImageView = view.findViewById(R.id.bookmark_image)
|
private var bookmarkImage: ImageView = view.findViewById(R.id.bookmark_image)
|
||||||
|
|
||||||
private var readColor = ChapterUtil.readColor(view.context)
|
|
||||||
private var unreadColor = ChapterUtil.unreadColor(view.context)
|
|
||||||
private var bookmarkColor = ChapterUtil.bookmarkedColor(view.context)
|
|
||||||
private var bookmarkReadColor = ChapterUtil.bookmarkedAndReadColor(view.context)
|
|
||||||
|
|
||||||
private var unbookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_border_24dp)
|
|
||||||
private var bookmark = view.context.contextCompatDrawable(R.drawable.ic_bookmark_24dp)
|
|
||||||
|
|
||||||
override fun bindView(item: ReaderChapterItem, payloads: List<Any>) {
|
override fun bindView(item: ReaderChapterItem, payloads: List<Any>) {
|
||||||
val chapter = item.chapter
|
val chapter = item.chapter
|
||||||
val manga = item.manga
|
val manga = item.manga
|
||||||
|
|
||||||
var chapterColor = when {
|
val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter)
|
||||||
chapter.bookmark && chapter.read -> bookmarkReadColor
|
|
||||||
chapter.bookmark -> bookmarkColor
|
|
||||||
chapter.read && !item.isCurrent -> readColor
|
|
||||||
else -> unreadColor
|
|
||||||
}
|
|
||||||
|
|
||||||
chapterTitle.setTextColor(chapterColor)
|
chapterTitle.setTextColor(chapterColor)
|
||||||
chapterTitle.text = when (manga.displayMode) {
|
chapterTitle.text = when (manga.displayMode) {
|
||||||
@ -86,16 +72,12 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B
|
|||||||
// match color of the chapter title
|
// match color of the chapter title
|
||||||
chapterSubtitle.setTextColor(chapterColor)
|
chapterSubtitle.setTextColor(chapterColor)
|
||||||
|
|
||||||
bookmarkImage.setImageDrawable(when (chapter.bookmark) {
|
bookmarkImage.setImageResource(
|
||||||
true -> bookmark
|
if (chapter.bookmark) R.drawable.ic_bookmark_border_24dp
|
||||||
false -> unbookmark
|
else R.drawable.ic_bookmark_24dp
|
||||||
})
|
)
|
||||||
|
|
||||||
val drawableColor = when {
|
val drawableColor = ChapterUtil.bookmarkColor(itemView.context, chapter)
|
||||||
chapter.bookmark && chapter.read -> bookmarkReadColor
|
|
||||||
chapter.bookmark -> bookmarkColor
|
|
||||||
else -> readColor
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawableCompat.setTint(bookmarkImage.drawable, drawableColor)
|
DrawableCompat.setTint(bookmarkImage.drawable, drawableColor)
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
||||||
|
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import kotlinx.android.synthetic.main.download_button.*
|
import kotlinx.android.synthetic.main.download_button.*
|
||||||
import kotlinx.android.synthetic.main.recent_chapters_item.*
|
import kotlinx.android.synthetic.main.recent_chapters_item.*
|
||||||
@ -77,14 +78,9 @@ class RecentChapterHolder(private val view: View, private val adapter: RecentCha
|
|||||||
.into(manga_cover)
|
.into(manga_cover)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if chapter is read and set correct color
|
val chapterColor = ChapterUtil.chapterColor(itemView.context, item)
|
||||||
if (item.chapter.read) {
|
chapter_title.setTextColor(chapterColor)
|
||||||
chapter_title.setTextColor(readColor)
|
title.setTextColor(chapterColor)
|
||||||
title.setTextColor(readColor)
|
|
||||||
} else {
|
|
||||||
chapter_title.setTextColor(unreadColor)
|
|
||||||
title.setTextColor(unreadColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set chapter status
|
// Set chapter status
|
||||||
notifyStatus(item.status, item.progress)
|
notifyStatus(item.status, item.progress)
|
||||||
|
@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.data.download.model.Download
|
|||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
import eu.kanade.tachiyomi.ui.manga.chapter.BaseChapterHolder
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.chapter.ChapterUtil
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
import kotlinx.android.synthetic.main.download_button.*
|
import kotlinx.android.synthetic.main.download_button.*
|
||||||
import kotlinx.android.synthetic.main.recent_manga_item.*
|
import kotlinx.android.synthetic.main.recent_manga_item.*
|
||||||
@ -38,20 +38,14 @@ class RecentMangaHolder(
|
|||||||
|
|
||||||
fun bind(item: RecentMangaItem) {
|
fun bind(item: RecentMangaItem) {
|
||||||
download_button.visibleIf(item.mch.manga.source != LocalSource.ID)
|
download_button.visibleIf(item.mch.manga.source != LocalSource.ID)
|
||||||
|
|
||||||
title.apply {
|
title.apply {
|
||||||
text = item.chapter.name
|
text = item.chapter.name
|
||||||
setTextColor(when {
|
setTextColor(ChapterUtil.chapterColor(context, item))
|
||||||
item.chapter.bookmark -> context.getResourceColor(R.attr.colorAccent)
|
|
||||||
item.chapter.read -> context.getResourceColor(android.R.attr.textColorHint)
|
|
||||||
else -> context.getResourceColor(android.R.attr.textColorPrimary)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
subtitle.apply {
|
subtitle.apply {
|
||||||
text = item.mch.manga.title
|
text = item.mch.manga.title
|
||||||
setTextColor(when {
|
setTextColor(ChapterUtil.readColor(context, item))
|
||||||
item.chapter.read -> context.getResourceColor(android.R.attr.textColorHint)
|
|
||||||
else -> context.getResourceColor(android.R.attr.textColorPrimary)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
val notValidNum = item.mch.chapter.chapter_number <= 0
|
val notValidNum = item.mch.chapter.chapter_number <= 0
|
||||||
body.text = when {
|
body.text = when {
|
||||||
|
@ -18,12 +18,36 @@ class ChapterUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readColor(context: Context): Int = context.contextCompatColor(R.color.read_chapter)
|
fun chapterColor(context: Context, chapter: Chapter, hideStatus: Boolean = false): Int {
|
||||||
|
return when {
|
||||||
fun unreadColor(context: Context): Int = context.contextCompatColor(R.color.unread_chapter)
|
hideStatus -> unreadColor(context)
|
||||||
|
chapter.bookmark && chapter.read -> bookmarkedAndReadColor(context)
|
||||||
fun bookmarkedColor(context: Context): Int = context.contextCompatColor(R.color.bookmarked_chapter)
|
chapter.bookmark -> bookmarkedColor(context)
|
||||||
|
chapter.read -> readColor(context)
|
||||||
fun bookmarkedAndReadColor(context: Context): Int = ColorUtils.setAlphaComponent(context.contextCompatColor(R.color.bookmarked_chapter), 150)
|
else -> unreadColor(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun readColor(context: Context, chapter: Chapter): Int {
|
||||||
|
return when {
|
||||||
|
chapter.read -> readColor(context)
|
||||||
|
else -> unreadColor(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bookmarkColor(context: Context, chapter: Chapter): Int {
|
||||||
|
return when {
|
||||||
|
chapter.bookmark -> bookmarkedColor(context)
|
||||||
|
else -> readColor(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readColor(context: Context): Int = context.contextCompatColor(R.color.read_chapter)
|
||||||
|
|
||||||
|
private fun unreadColor(context: Context): Int = context.contextCompatColor(R.color.unread_chapter)
|
||||||
|
|
||||||
|
private fun bookmarkedColor(context: Context): Int = context.contextCompatColor(R.color.bookmarked_chapter)
|
||||||
|
|
||||||
|
private fun bookmarkedAndReadColor(context: Context): Int = ColorUtils.setAlphaComponent(context.contextCompatColor(R.color.bookmarked_chapter), 150)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,10 +101,6 @@ inline fun View.isVisible(): Boolean {
|
|||||||
return visibility == View.VISIBLE
|
return visibility == View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun View.isNotGone(): Boolean {
|
|
||||||
return visibility != View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun View.visibleIf(show: Boolean) {
|
inline fun View.visibleIf(show: Boolean) {
|
||||||
visibility = if (show) View.VISIBLE else View.GONE
|
visibility = if (show) View.VISIBLE else View.GONE
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user