From 27a68685f1558b67bf541ca6177eb5c2cd7eb560 Mon Sep 17 00:00:00 2001 From: ZIDOUZI <1662093634@qq.com> Date: Sun, 2 Jun 2024 14:53:17 +0800 Subject: [PATCH] Hitomi: Add language to manga description, add a preferences to show gender (#3314) * 1. Add language for manga description 2. Add a custom preference to choice if show gender as text or icon * fix code style * revert extra formatting * change preference into switch * remove unused import, increase extVersionCode * Apply suggestions from code review --------- Co-authored-by: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> --- src/all/hitomi/build.gradle | 2 +- .../tachiyomi/extension/all/hitomi/Hitomi.kt | 39 +++++++++++++++++-- .../extension/all/hitomi/HitomiDto.kt | 7 ++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/all/hitomi/build.gradle b/src/all/hitomi/build.gradle index a91f5a1c9..cf5dd65a3 100644 --- a/src/all/hitomi/build.gradle +++ b/src/all/hitomi/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Hitomi' extClass = '.HitomiFactory' - extVersionCode = 27 + extVersionCode = 28 isNsfw = true } diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt index b41ecde4b..331df72a6 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt @@ -1,7 +1,12 @@ package eu.kanade.tachiyomi.extension.all.hitomi +import android.app.Application +import android.content.SharedPreferences +import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.await +import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.Page @@ -21,6 +26,8 @@ import okhttp3.Call import okhttp3.Request import okhttp3.Response import rx.Observable +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.nio.ByteBuffer import java.nio.ByteOrder @@ -34,7 +41,7 @@ import kotlin.math.min class Hitomi( override val lang: String, private val nozomiLang: String, -) : HttpSource() { +) : ConfigurableSource, HttpSource() { override val name = "Hitomi" @@ -50,6 +57,12 @@ class Hitomi( override val client = network.cloudflareClient + private val preferences: SharedPreferences by lazy { + Injekt.get().getSharedPreferences("source_$id", 0x0000) + } + + private var iconified = preferences.getBoolean(PREF_TAG_GENDER_ICON, false) + override fun headersBuilder() = super.headersBuilder() .set("referer", "$baseUrl/") .set("origin", baseUrl) @@ -437,7 +450,7 @@ class Hitomi( url = galleryurl author = groups?.joinToString { it.formatted } artist = artists?.joinToString { it.formatted } - genre = tags?.joinToString { it.formatted } + genre = tags?.joinToString { it.getFormatted(iconified) } thumbnail_url = files.first().let { val hash = it.hash val imageId = imageIdFromHash(hash) @@ -452,7 +465,8 @@ class Hitomi( parodys?.joinToString { it.formatted }?.let { append("Parodies: ", it, "\n") } - append("Pages: ", files.size) + append("Pages: ", files.size, "\n") + append("Language: ", language) } status = SManga.COMPLETED update_strategy = UpdateStrategy.ONLY_FETCH_ONCE @@ -606,9 +620,28 @@ class Hitomi( override fun popularMangaParse(response: Response) = throw UnsupportedOperationException() override fun popularMangaRequest(page: Int) = throw UnsupportedOperationException() + + override fun setupPreferenceScreen(screen: PreferenceScreen) { + SwitchPreferenceCompat(screen.context).apply { + key = PREF_TAG_GENDER_ICON + title = "Show gender as text or icon in tags (requires refresh)" + summaryOff = "Show gender as text" + summaryOn = "Show gender as icon" + + setOnPreferenceChangeListener { _, newValue -> + iconified = newValue == true + true + } + }.also(screen::addPreference) + } + override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException() override fun latestUpdatesParse(response: Response) = throw UnsupportedOperationException() override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = throw UnsupportedOperationException() override fun searchMangaParse(response: Response) = throw UnsupportedOperationException() override fun imageUrlParse(response: Response) = throw UnsupportedOperationException() + + companion object { + private const val PREF_TAG_GENDER_ICON = "pref_tag_gender_icon" + } } diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiDto.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiDto.kt index 0e5a6d5be..9cc850f3a 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiDto.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/HitomiDto.kt @@ -9,6 +9,7 @@ data class Gallery( val title: String, val date: String, val type: String, + val language: String, val tags: List?, val artists: List?, val groups: List?, @@ -28,10 +29,10 @@ data class Tag( val male: JsonPrimitive?, val tag: String, ) { - val formatted get() = if (female?.content == "1") { - "${tag.toCamelCase()} (Female)" + fun getFormatted(iconified: Boolean) = if (female?.content == "1") { + tag.toCamelCase() + if (iconified) " ♀" else " (Female)" } else if (male?.content == "1") { - "${tag.toCamelCase()} (Male)" + tag.toCamelCase() + if (iconified) " ♂" else " (Male)" } else { tag.toCamelCase() }