Add author and artist wrapping if a EH based source
This commit is contained in:
parent
8434b880c6
commit
923f5213cd
@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.util.view.setTooltip
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||
import exh.MERGED_SOURCE_ID
|
||||
import exh.util.SourceTagsUtil
|
||||
import exh.util.setChipsExtended
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -153,31 +154,43 @@ class MangaInfoHeaderAdapter(
|
||||
|
||||
binding.mangaAuthor.longClicks()
|
||||
.onEach {
|
||||
// SY -->
|
||||
val author = binding.mangaAuthor.text.toString()
|
||||
controller.activity?.copyToClipboard(
|
||||
binding.mangaAuthor.text.toString(),
|
||||
binding.mangaAuthor.text.toString()
|
||||
author,
|
||||
SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = author) ?: author
|
||||
)
|
||||
// SY <--
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.mangaAuthor.clicks()
|
||||
.onEach {
|
||||
controller.performGlobalSearch(binding.mangaAuthor.text.toString())
|
||||
// SY -->
|
||||
val author = binding.mangaAuthor.text.toString()
|
||||
controller.performGlobalSearch(SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = author) ?: author)
|
||||
// SY <--
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.mangaArtist.longClicks()
|
||||
.onEach {
|
||||
// SY -->
|
||||
val artist = binding.mangaArtist.text.toString()
|
||||
controller.activity?.copyToClipboard(
|
||||
binding.mangaArtist.text.toString(),
|
||||
binding.mangaArtist.text.toString()
|
||||
artist,
|
||||
SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = artist) ?: artist
|
||||
)
|
||||
// SY <--
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
binding.mangaArtist.clicks()
|
||||
.onEach {
|
||||
controller.performGlobalSearch(binding.mangaArtist.text.toString())
|
||||
// SY -->
|
||||
val artist = binding.mangaArtist.text.toString()
|
||||
controller.performGlobalSearch(SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = artist) ?: artist)
|
||||
// SY <--
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
|
45
app/src/main/java/exh/util/SourceTagsUtil.kt
Normal file
45
app/src/main/java/exh/util/SourceTagsUtil.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package exh.util
|
||||
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import exh.HITOMI_SOURCE_ID
|
||||
import exh.NHENTAI_SOURCE_ID
|
||||
|
||||
class 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 == NHENTAI_SOURCE_ID || sourceId == HITOMI_SOURCE_ID) {
|
||||
val parsed = if (fullTag != null) parseTag(fullTag) else if (namespace != null && tag != null) Pair(namespace, tag) else null
|
||||
if (parsed != null) {
|
||||
when (sourceId) {
|
||||
HITOMI_SOURCE_ID -> wrapTagHitomi(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
NHENTAI_SOURCE_ID -> wrapTagNHentai(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
else -> wrapTag(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
}
|
||||
} else null
|
||||
} else null
|
||||
}
|
||||
|
||||
fun parseTag(tag: String) = tag.substringBefore(':').trim() to tag.substringAfter(':').trim()
|
||||
|
||||
private fun wrapTag(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
"$namespace:\"$tag$\""
|
||||
} else {
|
||||
"$namespace:$tag$"
|
||||
}
|
||||
|
||||
private fun wrapTagHitomi(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
"$namespace:$tag".replace("\\s".toRegex(), "_")
|
||||
} else {
|
||||
"$namespace:$tag"
|
||||
}
|
||||
|
||||
private fun wrapTagNHentai(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
if (namespace == "tag") {
|
||||
"\"$tag\""
|
||||
} else {
|
||||
"$namespace:\"$tag\""
|
||||
}
|
||||
} else {
|
||||
"$namespace:$tag"
|
||||
}
|
||||
}
|
@ -7,10 +7,6 @@ import android.widget.FrameLayout
|
||||
import androidx.annotation.Px
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import exh.EH_SOURCE_ID
|
||||
import exh.EXH_SOURCE_ID
|
||||
import exh.HITOMI_SOURCE_ID
|
||||
import exh.NHENTAI_SOURCE_ID
|
||||
|
||||
inline val View.marginTop: Int
|
||||
get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0
|
||||
@ -120,15 +116,7 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
|
||||
items?.forEach { item ->
|
||||
val chip = Chip(context).apply {
|
||||
text = item
|
||||
var search = item
|
||||
if (sourceId == EXH_SOURCE_ID || sourceId == EH_SOURCE_ID || sourceId == NHENTAI_SOURCE_ID || sourceId == HITOMI_SOURCE_ID) {
|
||||
val parsed = parseTag(search)
|
||||
search = when (sourceId) {
|
||||
HITOMI_SOURCE_ID -> wrapTagHitomi(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
NHENTAI_SOURCE_ID -> wrapTagNHentai(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
else -> wrapTag(parsed.first, parsed.second.substringBefore('|').trim())
|
||||
}
|
||||
}
|
||||
val search = SourceTagsUtil().getWrappedTag(sourceId, fullTag = item) ?: item
|
||||
setOnClickListener { onClick(search) }
|
||||
setOnLongClickListener {
|
||||
onLongClick(search)
|
||||
@ -139,27 +127,3 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
|
||||
addView(chip)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseTag(tag: String) = tag.substringBefore(':').trim() to tag.substringAfter(':').trim()
|
||||
|
||||
private fun wrapTag(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
"$namespace:\"$tag$\""
|
||||
} else {
|
||||
"$namespace:$tag$"
|
||||
}
|
||||
|
||||
private fun wrapTagHitomi(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
"$namespace:$tag".replace("\\s".toRegex(), "_")
|
||||
} else {
|
||||
"$namespace:$tag"
|
||||
}
|
||||
|
||||
private fun wrapTagNHentai(namespace: String, tag: String) = if (tag.contains(' ')) {
|
||||
if (namespace == "tag") {
|
||||
"\"$tag\""
|
||||
} else {
|
||||
"$namespace:\"$tag\""
|
||||
}
|
||||
} else {
|
||||
"$namespace:$tag"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user