From 0327accecb9b2e369c479228c36655098867383d Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 24 Apr 2021 13:30:25 -0400 Subject: [PATCH] Download badge is now inverted for themes with black colorOnAccent --- .../java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt | 8 ++++++++ .../java/eu/kanade/tachiyomi/util/system/ImageUtil.kt | 5 +++++ app/src/main/res/values/colors.xml | 3 +++ 3 files changed, 16 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt index a3e2f73f85..26e0a9da01 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryBadge.kt @@ -5,6 +5,7 @@ import android.util.AttributeSet import com.google.android.material.card.MaterialCardView import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.UnreadDownloadBadgeBinding +import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.contextCompatColor import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor @@ -56,6 +57,13 @@ class LibraryBadge @JvmOverloads constructor(context: Context, attrs: AttributeS } else { downloads.toString() } + if (ImageUtil.isDarkish(context.getResourceColor(R.attr.colorOnAccent))) { + setTextColor(context.getColor(R.color.download_badge_light_text)) + setBackgroundColor(context.getColor(R.color.download_badge_light)) + } else { + setTextColor(context.getColor(R.color.download_badge_text)) + setBackgroundColor(context.getColor(R.color.download_badge)) + } } // Show the badge card if unread or downloads exists diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt index e019980386..a9759e96cb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ImageUtil.kt @@ -296,6 +296,11 @@ object ImageUtil { Color.alpha(color) > 200 } + fun isDarkish(color: Int): Boolean { + return Color.red(color) < 80 && Color.blue(color) < 80 && Color.green(color) < 80 && + Color.alpha(color) > 150 + } + private fun pixelIsClose(color1: Int, color2: Int): Boolean { return abs(Color.red(color1) - Color.red(color2)) < 30 && abs(Color.green(color1) - Color.green(color2)) < 30 && diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 329eeb1643..07ff435ef8 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -18,6 +18,8 @@ @color/md_white_1000 @color/pale_green @color/md_black_1000 + @color/strong_green + @color/md_white_1000 @color/material_deep_purple_500 @color/md_white_1000 @@ -59,6 +61,7 @@ #C14033 #99CC99 + #106010 #CC95818D