Use a Enum for genre color
This commit is contained in:
parent
1e2f4fc35e
commit
64eeab7c5e
@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
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) {
|
||||
"doujinshi" -> SourceTagsUtil.DOUJINSHI_COLOR to R.string.doujinshi
|
||||
"manga" -> SourceTagsUtil.MANGA_COLOR to R.string.manga
|
||||
"artistcg" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.artist_cg
|
||||
"gamecg" -> SourceTagsUtil.GAME_CG_COLOR to R.string.game_cg
|
||||
"western" -> SourceTagsUtil.WESTERN_COLOR to R.string.western
|
||||
"non-h" -> SourceTagsUtil.NON_H_COLOR to R.string.non_h
|
||||
"imageset" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.image_set
|
||||
"cosplay" -> SourceTagsUtil.COSPLAY_COLOR to R.string.cosplay
|
||||
"asianporn" -> SourceTagsUtil.ASIAN_PORN_COLOR to R.string.asian_porn
|
||||
"misc" -> SourceTagsUtil.MISC_COLOR to R.string.misc
|
||||
else -> "" to 0
|
||||
"doujinshi" -> SourceTagsUtil.GenreColor.DOUJINSHI_COLOR to R.string.doujinshi
|
||||
"manga" -> SourceTagsUtil.GenreColor.MANGA_COLOR to R.string.manga
|
||||
"artistcg" -> SourceTagsUtil.GenreColor.ARTIST_CG_COLOR to R.string.artist_cg
|
||||
"gamecg" -> SourceTagsUtil.GenreColor.GAME_CG_COLOR to R.string.game_cg
|
||||
"western" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.western
|
||||
"non-h" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.non_h
|
||||
"imageset" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.image_set
|
||||
"cosplay" -> SourceTagsUtil.GenreColor.COSPLAY_COLOR to R.string.cosplay
|
||||
"asianporn" -> SourceTagsUtil.GenreColor.ASIAN_PORN_COLOR to R.string.asian_porn
|
||||
"misc" -> SourceTagsUtil.GenreColor.MISC_COLOR to R.string.misc
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (pair.first.isNotBlank()) {
|
||||
binding.genre.setBackgroundColor(Color.parseColor(pair.first))
|
||||
if (pair != null) {
|
||||
binding.genre.setBackgroundColor(pair.first.color)
|
||||
binding.genre.text = view.context.getString(pair.second)
|
||||
} else binding.genre.text = metadata.genre
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package exh.metadata
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.FloatRange
|
||||
@ -68,7 +67,7 @@ object MetadataUtil {
|
||||
|
||||
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
|
||||
1 -> R.string.rating1
|
||||
2 -> R.string.rating2
|
||||
@ -84,24 +83,24 @@ object MetadataUtil {
|
||||
}.let { context.getString(it) }
|
||||
|
||||
fun getGenreAndColour(context: Context, genre: String) = when (genre) {
|
||||
"doujinshi", "Doujinshi" -> SourceTagsUtil.DOUJINSHI_COLOR to R.string.doujinshi
|
||||
"manga", "Japanese Manga", "Manga" -> SourceTagsUtil.MANGA_COLOR to R.string.manga
|
||||
"artistcg", "artist CG", "artist-cg", "Artist CG" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.artist_cg
|
||||
"gamecg", "game CG", "game-cg", "Game CG" -> SourceTagsUtil.GAME_CG_COLOR to R.string.game_cg
|
||||
"western" -> SourceTagsUtil.WESTERN_COLOR to R.string.western
|
||||
"non-h", "non-H" -> SourceTagsUtil.NON_H_COLOR to R.string.non_h
|
||||
"imageset", "image Set" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.image_set
|
||||
"cosplay" -> SourceTagsUtil.COSPLAY_COLOR to R.string.cosplay
|
||||
"asianporn", "asian Porn" -> SourceTagsUtil.ASIAN_PORN_COLOR to R.string.asian_porn
|
||||
"misc" -> SourceTagsUtil.MISC_COLOR to R.string.misc
|
||||
"Korean Manhwa" -> SourceTagsUtil.ARTIST_CG_COLOR to R.string.manhwa
|
||||
"Chinese Manhua" -> SourceTagsUtil.GAME_CG_COLOR to R.string.manhua
|
||||
"Comic" -> SourceTagsUtil.WESTERN_COLOR to R.string.comic
|
||||
"artbook" -> SourceTagsUtil.IMAGE_SET_COLOR to R.string.artbook
|
||||
"webtoon" -> SourceTagsUtil.NON_H_COLOR to R.string.webtoon
|
||||
"Video" -> SourceTagsUtil.WESTERN_COLOR to R.string.video
|
||||
else -> "" to 0
|
||||
}.let { if (it.second == 0) null else Color.parseColor(it.first) to context.getString(it.second) }
|
||||
"doujinshi", "Doujinshi" -> SourceTagsUtil.GenreColor.DOUJINSHI_COLOR to R.string.doujinshi
|
||||
"manga", "Japanese Manga", "Manga" -> SourceTagsUtil.GenreColor.MANGA_COLOR to R.string.manga
|
||||
"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.GenreColor.GAME_CG_COLOR to R.string.game_cg
|
||||
"western" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.western
|
||||
"non-h", "non-H" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.non_h
|
||||
"imageset", "image Set" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.image_set
|
||||
"cosplay" -> SourceTagsUtil.GenreColor.COSPLAY_COLOR to R.string.cosplay
|
||||
"asianporn", "asian Porn" -> SourceTagsUtil.GenreColor.ASIAN_PORN_COLOR to R.string.asian_porn
|
||||
"misc" -> SourceTagsUtil.GenreColor.MISC_COLOR to R.string.misc
|
||||
"Korean Manhwa" -> SourceTagsUtil.GenreColor.ARTIST_CG_COLOR to R.string.manhwa
|
||||
"Chinese Manhua" -> SourceTagsUtil.GenreColor.GAME_CG_COLOR to R.string.manhua
|
||||
"Comic" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.comic
|
||||
"artbook" -> SourceTagsUtil.GenreColor.IMAGE_SET_COLOR to R.string.artbook
|
||||
"webtoon" -> SourceTagsUtil.GenreColor.NON_H_COLOR to R.string.webtoon
|
||||
"Video" -> SourceTagsUtil.GenreColor.WESTERN_COLOR to R.string.video
|
||||
else -> null
|
||||
}?.let { it.first.color to context.getString(it.second) }
|
||||
}
|
||||
|
||||
fun <K, V> Set<Map.Entry<K, V>>.forEach(action: (K, V) -> Unit) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package exh.util
|
||||
|
||||
import android.graphics.Color
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
@ -13,7 +14,11 @@ import java.util.Locale
|
||||
object SourceTagsUtil {
|
||||
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) {
|
||||
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) {
|
||||
when (sourceId) {
|
||||
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 DOUJINSHI_COLOR = "#f44336"
|
||||
const val MANGA_COLOR = "#ff9800"
|
||||
const val ARTIST_CG_COLOR = "#fbc02d"
|
||||
const val GAME_CG_COLOR = "#4caf50"
|
||||
const val WESTERN_COLOR = "#8bc34a"
|
||||
const val NON_H_COLOR = "#2196f3"
|
||||
const val IMAGE_SET_COLOR = "#3f51b5"
|
||||
const val COSPLAY_COLOR = "#9c27b0"
|
||||
const val ASIAN_PORN_COLOR = "#9575cd"
|
||||
const val MISC_COLOR = "#f06292"
|
||||
enum class GenreColor(val color: Int) {
|
||||
DOUJINSHI_COLOR("#f44336"),
|
||||
MANGA_COLOR("#ff9800"),
|
||||
ARTIST_CG_COLOR("#fbc02d"),
|
||||
GAME_CG_COLOR("#4caf50"),
|
||||
WESTERN_COLOR("#8bc34a"),
|
||||
NON_H_COLOR("#2196f3"),
|
||||
IMAGE_SET_COLOR("#3f51b5"),
|
||||
COSPLAY_COLOR("#9c27b0"),
|
||||
ASIAN_PORN_COLOR("#9575cd"),
|
||||
MISC_COLOR("#f06292");
|
||||
|
||||
constructor(color: String) : this(Color.parseColor(color))
|
||||
}
|
||||
|
||||
fun getLocaleSourceUtil(language: String?) = when (language) {
|
||||
"english", "eng" -> Locale("en")
|
||||
|
Loading…
x
Reference in New Issue
Block a user