hbrowse add option to only show chapters (#9725)
This commit is contained in:
parent
390016c379
commit
93c16093a6
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'HBrowse'
|
||||
pkgNameSuffix = 'en.hbrowse'
|
||||
extClass = '.HBrowse'
|
||||
extVersionCode = 6
|
||||
extVersionCode = 7
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package eu.kanade.tachiyomi.extension.en.hbrowse
|
||||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
|
@ -10,17 +15,19 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.Response
|
||||
import okhttp3.Request
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.CookieJar
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.IOException
|
||||
|
||||
class HBrowse : ParsedHttpSource() {
|
||||
class HBrowse : ParsedHttpSource(), ConfigurableSource {
|
||||
|
||||
override val name = "HBrowse"
|
||||
|
||||
|
@ -163,7 +170,7 @@ class HBrowse : ParsedHttpSource() {
|
|||
|
||||
// Chapters
|
||||
|
||||
override fun chapterListSelector() = "h2:contains(read manga online) + table tr"
|
||||
override fun chapterListSelector() = if (!hbrowseOnlyChapters()) "h2:contains(read manga online) + table tr" else "h2:contains(read manga online) + table tr:contains(chapter)"
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
return super.chapterListParse(response).reversed()
|
||||
|
@ -222,4 +229,34 @@ class HBrowse : ParsedHttpSource() {
|
|||
)
|
||||
|
||||
private fun getAdvTriStateList(groupName: String, vals: List<String>) = vals.map { AdvTriStateFilter(groupName, it) }
|
||||
|
||||
// Preferences
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ONLYCHAPTERS_PREF_KEY = "HBROWSE_ONLYCHAPTERS"
|
||||
private const val ONLYCHAPTERS_PREF_TITLE = "Only show chapters"
|
||||
private const val ONLYCHAPTERS_PREF_SUMMARY = "Only show chapters and not the cover/final pages"
|
||||
private const val ONLYCHAPTERS_PREF_DEFAULT_VALUE = false
|
||||
}
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val onlychaptersPref = CheckBoxPreference(screen.context).apply {
|
||||
key = "${ONLYCHAPTERS_PREF_KEY}_$lang"
|
||||
title = ONLYCHAPTERS_PREF_TITLE
|
||||
summary = ONLYCHAPTERS_PREF_SUMMARY
|
||||
setDefaultValue(ONLYCHAPTERS_PREF_DEFAULT_VALUE)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
preferences.edit().putBoolean("${ONLYCHAPTERS_PREF_KEY}_$lang", checkValue).commit()
|
||||
}
|
||||
}
|
||||
screen.addPreference(onlychaptersPref)
|
||||
}
|
||||
|
||||
private fun hbrowseOnlyChapters(): Boolean = preferences.getBoolean("${ONLYCHAPTERS_PREF_KEY}_$lang", ONLYCHAPTERS_PREF_DEFAULT_VALUE)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue