[Mangadex] Update content rating to use MultiSelectListPref (#9670)
This commit is contained in:
parent
0d788c402e
commit
f3b3995174
@ -1,7 +1,7 @@
|
||||
// used both in common.gradle and themesources library
|
||||
dependencies {
|
||||
// Lib 1.2, but using specific commit so we don't need to bump up the version
|
||||
compileOnly "com.github.tachiyomiorg:extensions-lib:8dd92e3"
|
||||
compileOnly "com.github.tachiyomiorg:extensions-lib:cfa9530"
|
||||
|
||||
// These are provided by the app itself
|
||||
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
|
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'MangaDex'
|
||||
pkgNameSuffix = 'all.mangadex'
|
||||
extClass = '.MangaDexFactory'
|
||||
extVersionCode = 141
|
||||
extVersionCode = 142
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
@ -57,28 +57,15 @@ object MDConstants {
|
||||
return "${standardHttpsPortPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val contentRatingSafePref = "contentRatingSafe"
|
||||
private const val contentRatingPref = "contentRating"
|
||||
const val contentRatingPrefValSafe = "safe"
|
||||
const val contentRatingPrefValSuggestive = "suggestive"
|
||||
const val contentRatingPrefValErotica = "erotica"
|
||||
const val contentRatingPrefValPornographic = "pornographic"
|
||||
val contentRatingPrefDefaults = setOf(contentRatingPrefValSafe, contentRatingPrefValSuggestive)
|
||||
|
||||
fun getContentRatingSafePrefKey(dexLang: String): String {
|
||||
return "${contentRatingSafePref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val contentRatingSuggestivePref = "contentRatingSuggestive"
|
||||
|
||||
fun getContentRatingSuggestivePrefKey(dexLang: String): String {
|
||||
return "${contentRatingSuggestivePref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val contentRatingEroticaPref = "contentRatingErotica"
|
||||
|
||||
fun getContentRatingEroticaPrefKey(dexLang: String): String {
|
||||
return "${contentRatingEroticaPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val contentRatingPornographicPref = "contentRatingPornographic"
|
||||
|
||||
fun getContentRatingPornographicPrefKey(dexLang: String): String {
|
||||
return "${contentRatingPornographicPref}_$dexLang"
|
||||
fun getContentRatingPrefKey(dexLang: String): String {
|
||||
return "${contentRatingPref}_$dexLang"
|
||||
}
|
||||
|
||||
private const val originalLanguageJapanesePref = "originalLanguageJapanese"
|
||||
|
@ -4,6 +4,7 @@ import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.MultiSelectListPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import eu.kanade.tachiyomi.extension.all.mangadex.dto.AggregateDto
|
||||
@ -65,30 +66,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||
addQueryParameter("limit", MDConstants.mangaLimit.toString())
|
||||
addQueryParameter("offset", helper.getMangaListOffset(page))
|
||||
addQueryParameter("includes[]", MDConstants.coverArt)
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), false)) {
|
||||
addQueryParameter("contentRating[]", "safe")
|
||||
}
|
||||
if (preferences.getBoolean(
|
||||
MDConstants.getContentRatingSuggestivePrefKey(dexLang),
|
||||
false
|
||||
)
|
||||
) {
|
||||
addQueryParameter("contentRating[]", "suggestive")
|
||||
}
|
||||
if (preferences.getBoolean(
|
||||
MDConstants.getContentRatingEroticaPrefKey(dexLang),
|
||||
false
|
||||
)
|
||||
) {
|
||||
addQueryParameter("contentRating[]", "erotica")
|
||||
}
|
||||
if (preferences.getBoolean(
|
||||
MDConstants.getContentRatingPornographicPrefKey(dexLang),
|
||||
false
|
||||
)
|
||||
) {
|
||||
addQueryParameter("contentRating[]", "pornographic")
|
||||
}
|
||||
preferences.getStringSet(
|
||||
MDConstants.getContentRatingPrefKey(dexLang),
|
||||
MDConstants.contentRatingPrefDefaults
|
||||
)?.forEach { addQueryParameter("contentRating[]", it) }
|
||||
if (preferences.getBoolean(
|
||||
MDConstants.getOriginalLanguageJapanesePref(dexLang),
|
||||
false
|
||||
@ -155,18 +136,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||
addQueryParameter("includes[]", MDConstants.coverArt)
|
||||
addQueryParameter("limit", mangaIds.size.toString())
|
||||
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), true)) {
|
||||
addQueryParameter("contentRating[]", "safe")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingSuggestivePrefKey(dexLang), true)) {
|
||||
addQueryParameter("contentRating[]", "suggestive")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingEroticaPrefKey(dexLang), false)) {
|
||||
addQueryParameter("contentRating[]", "erotica")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingPornographicPrefKey(dexLang), false)) {
|
||||
addQueryParameter("contentRating[]", "pornographic")
|
||||
}
|
||||
preferences.getStringSet(
|
||||
MDConstants.getContentRatingPrefKey(dexLang),
|
||||
MDConstants.contentRatingPrefDefaults
|
||||
)?.forEach { addQueryParameter("contentRating[]", it) }
|
||||
|
||||
mangaIds.forEach { id ->
|
||||
addQueryParameter("ids[]", id)
|
||||
@ -208,18 +181,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||
if (preferences.getBoolean(MDConstants.getOriginalLanguageKoreanPref(dexLang), false)) {
|
||||
addQueryParameter("originalLanguage[]", "ko")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), true)) {
|
||||
addQueryParameter("contentRating[]", "safe")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingSuggestivePrefKey(dexLang), true)) {
|
||||
addQueryParameter("contentRating[]", "suggestive")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingEroticaPrefKey(dexLang), false)) {
|
||||
addQueryParameter("contentRating[]", "erotica")
|
||||
}
|
||||
if (preferences.getBoolean(MDConstants.getContentRatingPornographicPrefKey(dexLang), false)) {
|
||||
addQueryParameter("contentRating[]", "pornographic")
|
||||
}
|
||||
preferences.getStringSet(
|
||||
MDConstants.getContentRatingPrefKey(dexLang),
|
||||
MDConstants.contentRatingPrefDefaults
|
||||
)?.forEach { addQueryParameter("contentRating[]", it) }
|
||||
}.build().toString()
|
||||
return GET(url, headers, CacheControl.FORCE_NETWORK)
|
||||
}
|
||||
@ -504,60 +469,22 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||
}
|
||||
}
|
||||
|
||||
val contentRatingSafePref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getContentRatingSafePrefKey(dexLang)
|
||||
title = "Safe"
|
||||
summary = "If enabled, shows content with the rating of safe (manga without any sexual themes)"
|
||||
setDefaultValue(true)
|
||||
|
||||
val contentRatingPref = MultiSelectListPreference(screen.context).apply {
|
||||
key = MDConstants.getContentRatingPrefKey(dexLang)
|
||||
title = "Default content rating"
|
||||
summary = "Show content with the selected ratings by default"
|
||||
entries = arrayOf("Safe", "Suggestive", "Erotica", "Pornographic")
|
||||
entryValues = arrayOf(
|
||||
MDConstants.contentRatingPrefValSafe,
|
||||
MDConstants.contentRatingPrefValSuggestive,
|
||||
MDConstants.contentRatingPrefValErotica,
|
||||
MDConstants.contentRatingPrefValPornographic
|
||||
)
|
||||
setDefaultValue(MDConstants.contentRatingPrefDefaults)
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
val checkValue = newValue as Set<String>
|
||||
preferences.edit()
|
||||
.putBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
val contentRatingSuggestivePref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getContentRatingSuggestivePrefKey(dexLang)
|
||||
title = "Suggestive"
|
||||
summary = "If enabled, shows content with the rating of suggestive (manga usually tagged as ecchi)"
|
||||
setDefaultValue(true)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
preferences.edit()
|
||||
.putBoolean(MDConstants.getContentRatingSuggestivePrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
val contentRatingEroticaPref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getContentRatingEroticaPrefKey(dexLang)
|
||||
title = "Erotica"
|
||||
summary = "If enabled, shows content with the rating of erotica (manga usually tagged as smut)"
|
||||
setDefaultValue(false)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
preferences.edit()
|
||||
.putBoolean(MDConstants.getContentRatingEroticaPrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
val contentRatingPornographicPref = SwitchPreferenceCompat(screen.context).apply {
|
||||
key = MDConstants.getContentRatingPornographicPrefKey(dexLang)
|
||||
title = "Pornographic"
|
||||
summary = "If enabled, shows content with the rating of pornographic (manga usually tagged as hentai)"
|
||||
setDefaultValue(false)
|
||||
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val checkValue = newValue as Boolean
|
||||
preferences.edit().putBoolean(
|
||||
MDConstants.getContentRatingPornographicPrefKey(dexLang),
|
||||
checkValue
|
||||
)
|
||||
.putStringSet(MDConstants.getContentRatingPrefKey(dexLang), checkValue)
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
@ -607,10 +534,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
|
||||
screen.addPreference(coverQualityPref)
|
||||
screen.addPreference(dataSaverPref)
|
||||
screen.addPreference(standardHttpsPortPref)
|
||||
screen.addPreference(contentRatingSafePref)
|
||||
screen.addPreference(contentRatingSuggestivePref)
|
||||
screen.addPreference(contentRatingEroticaPref)
|
||||
screen.addPreference(contentRatingPornographicPref)
|
||||
screen.addPreference(contentRatingPref)
|
||||
screen.addPreference(originalLanguageJapanesePref)
|
||||
screen.addPreference(originalLanguageChinesePref)
|
||||
screen.addPreference(originalLanguageKoreanPref)
|
||||
|
@ -22,32 +22,30 @@ class MangaDexFilters {
|
||||
)
|
||||
}
|
||||
|
||||
private fun getContentRating(preferences: SharedPreferences, dexLang: String) = listOf(
|
||||
ContentRating("Safe").apply {
|
||||
state = preferences.getBoolean(
|
||||
MDConstants.getContentRatingSafePrefKey(dexLang),
|
||||
true
|
||||
)
|
||||
},
|
||||
ContentRating("Suggestive").apply {
|
||||
state = preferences.getBoolean(
|
||||
MDConstants.getContentRatingSuggestivePrefKey(dexLang),
|
||||
true
|
||||
)
|
||||
},
|
||||
ContentRating("Erotica").apply {
|
||||
state = preferences.getBoolean(
|
||||
MDConstants.getContentRatingEroticaPrefKey(dexLang),
|
||||
false
|
||||
)
|
||||
},
|
||||
ContentRating("Pornographic").apply {
|
||||
state = preferences.getBoolean(
|
||||
MDConstants.getContentRatingPornographicPrefKey(dexLang),
|
||||
false
|
||||
)
|
||||
},
|
||||
)
|
||||
private fun getContentRating(preferences: SharedPreferences, dexLang: String): List<ContentRating> {
|
||||
val contentRatings = preferences.getStringSet(
|
||||
MDConstants.getContentRatingPrefKey(dexLang),
|
||||
MDConstants.contentRatingPrefDefaults
|
||||
)
|
||||
return listOf(
|
||||
ContentRating("Safe").apply {
|
||||
state = contentRatings
|
||||
?.contains(MDConstants.contentRatingPrefValSafe) ?: true
|
||||
},
|
||||
ContentRating("Suggestive").apply {
|
||||
state = contentRatings
|
||||
?.contains(MDConstants.contentRatingPrefValSuggestive) ?: true
|
||||
},
|
||||
ContentRating("Erotica").apply {
|
||||
state = contentRatings
|
||||
?.contains(MDConstants.contentRatingPrefValErotica) ?: false
|
||||
},
|
||||
ContentRating("Pornographic").apply {
|
||||
state = contentRatings
|
||||
?.contains(MDConstants.contentRatingPrefValPornographic) ?: false
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private class Demographic(name: String) : Filter.CheckBox(name)
|
||||
private class DemographicList(demographics: List<Demographic>) :
|
||||
|
Loading…
x
Reference in New Issue
Block a user