Use a Enum for genre color

This commit is contained in:
Jobobby04 2021-01-25 21:37:50 -05:00
parent 1e2f4fc35e
commit 64eeab7c5e
3 changed files with 52 additions and 45 deletions

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.browse.source.browse package eu.kanade.tachiyomi.ui.browse.source.browse
import android.graphics.Color
import android.view.View import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.CenterCrop
@ -59,21 +58,21 @@ class SourceEnhancedEHentaiListHolder(private val view: View, adapter: FlexibleA
} }
val pair = when (metadata.genre) { val pair = when (metadata.genre) {
"doujinshi" -> SourceTagsUtil.DOUJINSHI_COLOR to R.string.doujinshi "doujinshi" -> SourceTagsUtil.GenreColor.DOUJINSHI_COLOR to R.string.doujinshi
"manga" -> SourceTagsUtil.MANGA_COLOR to R.string.manga "manga" -> SourceTagsUtil.GenreColor.MANGA_COLOR to R.string.manga
"artistcg" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.artist_cg "artistcg" -> SourceTagsUtil.GenreColor.ARTIST_CG_COLOR to R.string.artist_cg
"gamecg" -> SourceTagsUtil.GAME_CG_COLOR to R.string.game_cg "gamecg" -> SourceTagsUtil.GenreColor.GAME_CG_COLOR to R.string.game_cg
"western" -> SourceTagsUtil.WESTERN_COLOR to R.string.western "western" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.western
"non-h" -> SourceTagsUtil.NON_H_COLOR to R.string.non_h "non-h" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.non_h
"imageset" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.image_set "imageset" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.image_set
"cosplay" -> SourceTagsUtil.COSPLAY_COLOR to R.string.cosplay "cosplay" -> SourceTagsUtil.GenreColor.COSPLAY_COLOR to R.string.cosplay
"asianporn" -> SourceTagsUtil.ASIAN_PORN_COLOR to R.string.asian_porn "asianporn" -> SourceTagsUtil.GenreColor.ASIAN_PORN_COLOR to R.string.asian_porn
"misc" -> SourceTagsUtil.MISC_COLOR to R.string.misc "misc" -> SourceTagsUtil.GenreColor.MISC_COLOR to R.string.misc
else -> "" to 0 else -> null
} }
if (pair.first.isNotBlank()) { if (pair != null) {
binding.genre.setBackgroundColor(Color.parseColor(pair.first)) binding.genre.setBackgroundColor(pair.first.color)
binding.genre.text = view.context.getString(pair.second) binding.genre.text = view.context.getString(pair.second)
} else binding.genre.text = metadata.genre } else binding.genre.text = metadata.genre

View File

@ -1,7 +1,6 @@
package exh.metadata package exh.metadata
import android.content.Context import android.content.Context
import android.graphics.Color
import android.widget.TextView import android.widget.TextView
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.FloatRange import androidx.annotation.FloatRange
@ -68,7 +67,7 @@ object MetadataUtil {
val EX_DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US) val EX_DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US)
fun getRatingString(context: Context, @FloatRange(from = 0.0, to = 10.0) rating: Float?) = when ((rating ?: 100F).roundToInt()) { fun getRatingString(context: Context, @FloatRange(from = 0.0, to = 10.0) rating: Float? = null) = when (rating?.roundToInt()) {
0 -> R.string.rating0 0 -> R.string.rating0
1 -> R.string.rating1 1 -> R.string.rating1
2 -> R.string.rating2 2 -> R.string.rating2
@ -84,24 +83,24 @@ object MetadataUtil {
}.let { context.getString(it) } }.let { context.getString(it) }
fun getGenreAndColour(context: Context, genre: String) = when (genre) { fun getGenreAndColour(context: Context, genre: String) = when (genre) {
"doujinshi", "Doujinshi" -> SourceTagsUtil.DOUJINSHI_COLOR to R.string.doujinshi "doujinshi", "Doujinshi" -> SourceTagsUtil.GenreColor.DOUJINSHI_COLOR to R.string.doujinshi
"manga", "Japanese Manga", "Manga" -> SourceTagsUtil.MANGA_COLOR to R.string.manga "manga", "Japanese Manga", "Manga" -> SourceTagsUtil.GenreColor.MANGA_COLOR to R.string.manga
"artistcg", "artist CG", "artist-cg", "Artist CG" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.artist_cg "artistcg", "artist CG", "artist-cg", "Artist CG" -> SourceTagsUtil.GenreColor.ARTIST_CG_COLOR to R.string.artist_cg
"gamecg", "game CG", "game-cg", "Game CG" -> SourceTagsUtil.GAME_CG_COLOR to R.string.game_cg "gamecg", "game CG", "game-cg", "Game CG" -> SourceTagsUtil.GenreColor.GAME_CG_COLOR to R.string.game_cg
"western" -> SourceTagsUtil.WESTERN_COLOR to R.string.western "western" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.western
"non-h", "non-H" -> SourceTagsUtil.NON_H_COLOR to R.string.non_h "non-h", "non-H" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.non_h
"imageset", "image Set" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.image_set "imageset", "image Set" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.image_set
"cosplay" -> SourceTagsUtil.COSPLAY_COLOR to R.string.cosplay "cosplay" -> SourceTagsUtil.GenreColor.COSPLAY_COLOR to R.string.cosplay
"asianporn", "asian Porn" -> SourceTagsUtil.ASIAN_PORN_COLOR to R.string.asian_porn "asianporn", "asian Porn" -> SourceTagsUtil.GenreColor.ASIAN_PORN_COLOR to R.string.asian_porn
"misc" -> SourceTagsUtil.MISC_COLOR to R.string.misc "misc" -> SourceTagsUtil.GenreColor.MISC_COLOR to R.string.misc
"Korean Manhwa" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.manhwa "Korean Manhwa" -> SourceTagsUtil.GenreColor.ARTIST_CG_COLOR to R.string.manhwa
"Chinese Manhua" -> SourceTagsUtil.GAME_CG_COLOR to R.string.manhua "Chinese Manhua" -> SourceTagsUtil.GenreColor.GAME_CG_COLOR to R.string.manhua
"Comic" -> SourceTagsUtil.WESTERN_COLOR to R.string.comic "Comic" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.comic
"artbook" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.artbook "artbook" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.artbook
"webtoon" -> SourceTagsUtil.NON_H_COLOR to R.string.webtoon "webtoon" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.webtoon
"Video" -> SourceTagsUtil.WESTERN_COLOR to R.string.video "Video" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.video
else -> "" to 0 else -> null
}.let { if (it.second == 0) null else Color.parseColor(it.first) to context.getString(it.second) } }?.let { it.first.color to context.getString(it.second) }
} }
fun <K, V> Set<Map.Entry<K, V>>.forEach(action: (K, V) -> Unit) { fun <K, V> Set<Map.Entry<K, V>>.forEach(action: (K, V) -> Unit) {

View File

@ -1,5 +1,6 @@
package exh.util package exh.util
import android.graphics.Color
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import exh.EH_SOURCE_ID import exh.EH_SOURCE_ID
import exh.EXH_SOURCE_ID import exh.EXH_SOURCE_ID
@ -13,7 +14,11 @@ import java.util.Locale
object SourceTagsUtil { object SourceTagsUtil {
fun getWrappedTag(sourceId: Long, namespace: String? = null, tag: String? = null, fullTag: String? = null): String? { fun getWrappedTag(sourceId: Long, namespace: String? = null, tag: String? = null, fullTag: String? = null): String? {
return if (sourceId == EXH_SOURCE_ID || sourceId == EH_SOURCE_ID || sourceId in nHentaiSourceIds || sourceId in hitomiSourceIds) { return if (sourceId == EXH_SOURCE_ID || sourceId == EH_SOURCE_ID || sourceId in nHentaiSourceIds || sourceId in hitomiSourceIds) {
val parsed = if (fullTag != null) parseTag(fullTag) else if (namespace != null && tag != null) RaisedTag(namespace, tag, TAG_TYPE_DEFAULT) else null val parsed = if (fullTag != null) {
parseTag(fullTag)
} else if (namespace != null && tag != null) {
RaisedTag(namespace, tag, TAG_TYPE_DEFAULT)
} else null
if (parsed?.namespace != null) { if (parsed?.namespace != null) {
when (sourceId) { when (sourceId) {
in hitomiSourceIds -> wrapTagHitomi(parsed.namespace, parsed.name.substringBefore('|').trim()) in hitomiSourceIds -> wrapTagHitomi(parsed.namespace, parsed.name.substringBefore('|').trim())
@ -60,16 +65,20 @@ object SourceTagsUtil {
const val TAG_TYPE_EXCLUDE = 69 // why not const val TAG_TYPE_EXCLUDE = 69 // why not
const val DOUJINSHI_COLOR = "#f44336" enum class GenreColor(val color: Int) {
const val MANGA_COLOR = "#ff9800" DOUJINSHI_COLOR("#f44336"),
const val ARTIST_CG_COLOR = "#fbc02d" MANGA_COLOR("#ff9800"),
const val GAME_CG_COLOR = "#4caf50" ARTIST_CG_COLOR("#fbc02d"),
const val WESTERN_COLOR = "#8bc34a" GAME_CG_COLOR("#4caf50"),
const val NON_H_COLOR = "#2196f3" WESTERN_COLOR("#8bc34a"),
const val IMAGE_SET_COLOR = "#3f51b5" NON_H_COLOR("#2196f3"),
const val COSPLAY_COLOR = "#9c27b0" IMAGE_SET_COLOR("#3f51b5"),
const val ASIAN_PORN_COLOR = "#9575cd" COSPLAY_COLOR("#9c27b0"),
const val MISC_COLOR = "#f06292" ASIAN_PORN_COLOR("#9575cd"),
MISC_COLOR("#f06292");
constructor(color: String) : this(Color.parseColor(color))
}
fun getLocaleSourceUtil(language: String?) = when (language) { fun getLocaleSourceUtil(language: String?) = when (language) {
"english", "eng" -> Locale("en") "english", "eng" -> Locale("en")