[Akuma] fix language filter & add a preference for show short title (#4599)

* [Akuma] fix language filter

* dev

* fix typo

* fix order

* fix build bug

* fix build bug again

* fix build bug 3

* fix

* change default value

* fix property getter function

* fix manga detail title
This commit is contained in:
子斗子 2024-08-14 19:35:46 +08:00 committed by GitHub
parent 78d7ea776a
commit 9d3edbb49c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 5 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Akuma'
extClass = '.AkumaFactory'
extVersionCode = 4
extVersionCode = 5
isNsfw = true
}

View File

@ -1,8 +1,13 @@
package eu.kanade.tachiyomi.extension.all.akuma
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.POST
import eu.kanade.tachiyomi.network.interceptor.rateLimit
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
@ -20,6 +25,8 @@ import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.IOException
import java.text.ParseException
import java.text.SimpleDateFormat
@ -29,7 +36,7 @@ import java.util.TimeZone
class Akuma(
override val lang: String,
private val akumaLang: String,
) : ParsedHttpSource() {
) : ConfigurableSource, ParsedHttpSource() {
override val name = "Akuma"
@ -105,6 +112,23 @@ class Akuma(
return storedToken!!
}
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
private val displayFullTitle: Boolean get() = preferences.getBoolean(PREF_TITLE, false)
private val shortenTitleRegex = Regex("""(\[[^]]*]|[({][^)}]*[)}])""")
private fun String.shortenTitle() = this.replace(shortenTitleRegex, "").trim()
override fun setupPreferenceScreen(screen: PreferenceScreen) {
SwitchPreferenceCompat(screen.context).apply {
key = PREF_TITLE
title = "Display manga title as full title"
setDefaultValue(false)
}.also(screen::addPreference)
}
override fun popularMangaRequest(page: Int): Request {
val payload = FormBody.Builder()
.add("view", "3")
@ -149,7 +173,9 @@ class Akuma(
override fun popularMangaFromElement(element: Element): SManga {
return SManga.create().apply {
setUrlWithoutDomain(element.select("a").attr("href"))
title = element.select(".overlay-title").text()
title = element.select(".overlay-title").text().replace("\"", "").let {
if (displayFullTitle) it.trim() else it.shortenTitle()
}
thumbnail_url = element.select("img").attr("abs:src")
}
}
@ -176,7 +202,7 @@ class Akuma(
val finalQuery: MutableList<String> = mutableListOf(query)
if (lang != "all") {
finalQuery.add("language: $akumaLang$")
finalQuery.add("language:$akumaLang$")
}
filters.forEach { filter ->
when (filter) {
@ -220,7 +246,9 @@ class Akuma(
override fun mangaDetailsParse(document: Document) = with(document) {
SManga.create().apply {
title = select(".entry-title").text()
title = select(".entry-title").text().replace("\"", "").let {
if (displayFullTitle) it.trim() else it.shortenTitle()
}
thumbnail_url = select(".img-thumbnail").attr("abs:src")
author = select(".group~.value").eachText().joinToString()
@ -302,6 +330,7 @@ class Akuma(
companion object {
const val PREFIX_ID = "id:"
private const val PREF_TITLE = "pref_title"
}
override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException()