mirror of
https://github.com/keiyoushi/extensions-source.git
synced 2024-11-25 11:42:47 +01:00
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>
This commit is contained in:
parent
76d96adbfb
commit
27a68685f1
@ -1,7 +1,7 @@
|
||||
ext {
|
||||
extName = 'Hitomi'
|
||||
extClass = '.HitomiFactory'
|
||||
extVersionCode = 27
|
||||
extVersionCode = 28
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
@ -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<Application>().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"
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ data class Gallery(
|
||||
val title: String,
|
||||
val date: String,
|
||||
val type: String,
|
||||
val language: String,
|
||||
val tags: List<Tag>?,
|
||||
val artists: List<Artist>?,
|
||||
val groups: List<Group>?,
|
||||
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user