Add custom tag view for namespaced sources (E-Hentai, nHentai, Hitomi.la, and Pururin)

This commit is contained in:
Jobobby04
2020-07-16 17:27:36 -04:00
parent 74012e0830
commit 8b95d93a96
6 changed files with 129 additions and 12 deletions
@@ -4,6 +4,7 @@ import exh.EH_SOURCE_ID
import exh.EXH_SOURCE_ID
import exh.HITOMI_SOURCE_ID
import exh.NHENTAI_SOURCE_ID
import exh.PURURIN_SOURCE_ID
class SourceTagsUtil {
fun getWrappedTag(sourceId: Long, namespace: String? = null, tag: String? = null, fullTag: String? = null): String? {
@@ -13,6 +14,7 @@ class SourceTagsUtil {
when (sourceId) {
HITOMI_SOURCE_ID -> wrapTagHitomi(parsed.first, parsed.second.substringBefore('|').trim())
NHENTAI_SOURCE_ID -> wrapTagNHentai(parsed.first, parsed.second.substringBefore('|').trim())
PURURIN_SOURCE_ID -> parsed.second.substringBefore('|').trim()
else -> wrapTag(parsed.first, parsed.second.substringBefore('|').trim())
}
} else null
+14 -10
View File
@@ -1,5 +1,6 @@
package exh.util
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
@@ -114,16 +115,19 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
removeAllViews()
items?.forEach { item ->
val chip = Chip(context).apply {
text = item
val search = SourceTagsUtil().getWrappedTag(sourceId, fullTag = item) ?: item
setOnClickListener { onClick(search) }
setOnLongClickListener {
onLongClick(search)
false
}
}
val chip = makeSearchChip(item, onClick, onLongClick, sourceId, context)
addView(chip)
}
}
fun makeSearchChip(item: String, onClick: (item: String) -> Unit = {}, onLongClick: (item: String) -> Unit = {}, sourceId: Long, context: Context, namespace: String? = null): Chip {
return Chip(context).apply {
text = item
val search = (if (namespace != null) SourceTagsUtil().getWrappedTag(sourceId, namespace = namespace, tag = item) else SourceTagsUtil().getWrappedTag(sourceId, fullTag = item)) ?: item
setOnClickListener { onClick(search) }
setOnLongClickListener {
onLongClick(search)
false
}
}
}