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.visible
|
||||||
import eu.kanade.tachiyomi.util.view.visibleIf
|
import eu.kanade.tachiyomi.util.view.visibleIf
|
||||||
import exh.MERGED_SOURCE_ID
|
import exh.MERGED_SOURCE_ID
|
||||||
|
import exh.util.SourceTagsUtil
|
||||||
import exh.util.setChipsExtended
|
import exh.util.setChipsExtended
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -153,31 +154,43 @@ class MangaInfoHeaderAdapter(
|
|||||||
|
|
||||||
binding.mangaAuthor.longClicks()
|
binding.mangaAuthor.longClicks()
|
||||||
.onEach {
|
.onEach {
|
||||||
|
// SY -->
|
||||||
|
val author = binding.mangaAuthor.text.toString()
|
||||||
controller.activity?.copyToClipboard(
|
controller.activity?.copyToClipboard(
|
||||||
binding.mangaAuthor.text.toString(),
|
author,
|
||||||
binding.mangaAuthor.text.toString()
|
SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = author) ?: author
|
||||||
)
|
)
|
||||||
|
// SY <--
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
binding.mangaAuthor.clicks()
|
binding.mangaAuthor.clicks()
|
||||||
.onEach {
|
.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)
|
.launchIn(scope)
|
||||||
|
|
||||||
binding.mangaArtist.longClicks()
|
binding.mangaArtist.longClicks()
|
||||||
.onEach {
|
.onEach {
|
||||||
|
// SY -->
|
||||||
|
val artist = binding.mangaArtist.text.toString()
|
||||||
controller.activity?.copyToClipboard(
|
controller.activity?.copyToClipboard(
|
||||||
binding.mangaArtist.text.toString(),
|
artist,
|
||||||
binding.mangaArtist.text.toString()
|
SourceTagsUtil().getWrappedTag(source.id, namespace = "artist", tag = artist) ?: artist
|
||||||
)
|
)
|
||||||
|
// SY <--
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
binding.mangaArtist.clicks()
|
binding.mangaArtist.clicks()
|
||||||
.onEach {
|
.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)
|
.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 androidx.annotation.Px
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipGroup
|
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
|
inline val View.marginTop: Int
|
||||||
get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0
|
get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0
|
||||||
@ -120,15 +116,7 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
|
|||||||
items?.forEach { item ->
|
items?.forEach { item ->
|
||||||
val chip = Chip(context).apply {
|
val chip = Chip(context).apply {
|
||||||
text = item
|
text = item
|
||||||
var search = item
|
val search = SourceTagsUtil().getWrappedTag(sourceId, fullTag = item) ?: 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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setOnClickListener { onClick(search) }
|
setOnClickListener { onClick(search) }
|
||||||
setOnLongClickListener {
|
setOnLongClickListener {
|
||||||
onLongClick(search)
|
onLongClick(search)
|
||||||
@ -139,27 +127,3 @@ fun ChipGroup.setChipsExtended(items: List<String>?, onClick: (item: String) ->
|
|||||||
addView(chip)
|
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