Cleanup some tag stuff

This commit is contained in:
Jobobby04 2021-05-11 12:38:50 -04:00
parent b657af8d1c
commit 3f56c81c03
3 changed files with 31 additions and 10 deletions

View File

@ -135,14 +135,35 @@ class MangaInfoItemAdapter(
var namespaceTags: List<NamespaceTagsItem> = emptyList()
if (source.isEhBasedSource() && metaTags != null && metaTags.all { it.key != null }) {
namespaceTags = metaTags
.mapValues { values -> values.value.map { makeSearchChip(it.name, controller::performSearch, controller::performGlobalSearch, source.id, itemView.context, it.namespace, it.type) } }
.mapValues { values ->
values.value.map {
itemView.context.makeSearchChip(
it.name,
controller::performSearch,
controller::performGlobalSearch,
source.id,
it.namespace,
it.type
)
}
}
.map { NamespaceTagsItem(it.key!!, it.value) }
} else {
val genre = manga.getRaisedTags()
if (!genre.isNullOrEmpty()) {
namespaceTags = genre
.groupBy { it.namespace }
.mapValues { values -> values.value.map { makeSearchChip(it.name, controller::performSearch, controller::performGlobalSearch, source.id, itemView.context, it.namespace) } }
.mapValues { values ->
values.value.map {
itemView.context.makeSearchChip(
it.name,
controller::performSearch,
controller::performGlobalSearch,
source.id,
it.namespace
)
}
}
.map { NamespaceTagsItem(it.key, it.value) }
}
}

View File

@ -14,11 +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 = when {
fullTag != null -> parseTag(fullTag)
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())

View File

@ -19,13 +19,13 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
removeAllViews()
items?.forEach { item ->
val chip = makeSearchChip(item, onClick, onLongClick, sourceId, context)
val chip = context.makeSearchChip(item, onClick, onLongClick, sourceId)
addView(chip)
}
}
fun makeSearchChip(item: String, onClick: (item: String) -> Unit = {}, onLongClick: (item: String) -> Unit = {}, sourceId: Long, context: Context, namespace: String? = null, type: Int? = null): Chip {
return Chip(context).apply {
fun Context.makeSearchChip(item: String, onClick: (item: String) -> Unit = {}, onLongClick: (item: String) -> Unit = {}, sourceId: Long, namespace: String? = null, type: Int? = null): Chip {
return Chip(this).apply {
text = item
val search = if (namespace != null) {
SourceTagsUtil.getWrappedTag(sourceId, namespace = namespace, tag = item)