[Mangadex] Update content rating to use MultiSelectListPref (#9670)

This commit is contained in:
FlaminSarge 2021-10-30 06:56:35 -07:00 committed by GitHub
parent 0d788c402e
commit f3b3995174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 153 deletions

View File

@ -1,7 +1,7 @@
// used both in common.gradle and themesources library // used both in common.gradle and themesources library
dependencies { dependencies {
// Lib 1.2, but using specific commit so we don't need to bump up the version // 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 // These are provided by the app itself
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex' extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex' pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory' extClass = '.MangaDexFactory'
extVersionCode = 141 extVersionCode = 142
isNsfw = true isNsfw = true
} }

View File

@ -57,28 +57,15 @@ object MDConstants {
return "${standardHttpsPortPref}_$dexLang" 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 { fun getContentRatingPrefKey(dexLang: String): String {
return "${contentRatingSafePref}_$dexLang" return "${contentRatingPref}_$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"
} }
private const val originalLanguageJapanesePref = "originalLanguageJapanese" private const val originalLanguageJapanesePref = "originalLanguageJapanese"

View File

@ -4,6 +4,7 @@ import android.app.Application
import android.content.SharedPreferences import android.content.SharedPreferences
import android.util.Log import android.util.Log
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.extension.all.mangadex.dto.AggregateDto 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("limit", MDConstants.mangaLimit.toString())
addQueryParameter("offset", helper.getMangaListOffset(page)) addQueryParameter("offset", helper.getMangaListOffset(page))
addQueryParameter("includes[]", MDConstants.coverArt) addQueryParameter("includes[]", MDConstants.coverArt)
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), false)) { preferences.getStringSet(
addQueryParameter("contentRating[]", "safe") MDConstants.getContentRatingPrefKey(dexLang),
} MDConstants.contentRatingPrefDefaults
if (preferences.getBoolean( )?.forEach { addQueryParameter("contentRating[]", it) }
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")
}
if (preferences.getBoolean( if (preferences.getBoolean(
MDConstants.getOriginalLanguageJapanesePref(dexLang), MDConstants.getOriginalLanguageJapanesePref(dexLang),
false false
@ -155,18 +136,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
addQueryParameter("includes[]", MDConstants.coverArt) addQueryParameter("includes[]", MDConstants.coverArt)
addQueryParameter("limit", mangaIds.size.toString()) addQueryParameter("limit", mangaIds.size.toString())
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), true)) { preferences.getStringSet(
addQueryParameter("contentRating[]", "safe") MDConstants.getContentRatingPrefKey(dexLang),
} MDConstants.contentRatingPrefDefaults
if (preferences.getBoolean(MDConstants.getContentRatingSuggestivePrefKey(dexLang), true)) { )?.forEach { addQueryParameter("contentRating[]", it) }
addQueryParameter("contentRating[]", "suggestive")
}
if (preferences.getBoolean(MDConstants.getContentRatingEroticaPrefKey(dexLang), false)) {
addQueryParameter("contentRating[]", "erotica")
}
if (preferences.getBoolean(MDConstants.getContentRatingPornographicPrefKey(dexLang), false)) {
addQueryParameter("contentRating[]", "pornographic")
}
mangaIds.forEach { id -> mangaIds.forEach { id ->
addQueryParameter("ids[]", 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)) { if (preferences.getBoolean(MDConstants.getOriginalLanguageKoreanPref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "ko") addQueryParameter("originalLanguage[]", "ko")
} }
if (preferences.getBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), true)) { preferences.getStringSet(
addQueryParameter("contentRating[]", "safe") MDConstants.getContentRatingPrefKey(dexLang),
} MDConstants.contentRatingPrefDefaults
if (preferences.getBoolean(MDConstants.getContentRatingSuggestivePrefKey(dexLang), true)) { )?.forEach { addQueryParameter("contentRating[]", it) }
addQueryParameter("contentRating[]", "suggestive")
}
if (preferences.getBoolean(MDConstants.getContentRatingEroticaPrefKey(dexLang), false)) {
addQueryParameter("contentRating[]", "erotica")
}
if (preferences.getBoolean(MDConstants.getContentRatingPornographicPrefKey(dexLang), false)) {
addQueryParameter("contentRating[]", "pornographic")
}
}.build().toString() }.build().toString()
return GET(url, headers, CacheControl.FORCE_NETWORK) 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 { val contentRatingPref = MultiSelectListPreference(screen.context).apply {
key = MDConstants.getContentRatingSafePrefKey(dexLang) key = MDConstants.getContentRatingPrefKey(dexLang)
title = "Safe" title = "Default content rating"
summary = "If enabled, shows content with the rating of safe (manga without any sexual themes)" summary = "Show content with the selected ratings by default"
setDefaultValue(true) entries = arrayOf("Safe", "Suggestive", "Erotica", "Pornographic")
entryValues = arrayOf(
MDConstants.contentRatingPrefValSafe,
MDConstants.contentRatingPrefValSuggestive,
MDConstants.contentRatingPrefValErotica,
MDConstants.contentRatingPrefValPornographic
)
setDefaultValue(MDConstants.contentRatingPrefDefaults)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
val checkValue = newValue as Boolean val checkValue = newValue as Set<String>
preferences.edit() preferences.edit()
.putBoolean(MDConstants.getContentRatingSafePrefKey(dexLang), checkValue) .putStringSet(MDConstants.getContentRatingPrefKey(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
)
.commit() .commit()
} }
} }
@ -607,10 +534,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
screen.addPreference(coverQualityPref) screen.addPreference(coverQualityPref)
screen.addPreference(dataSaverPref) screen.addPreference(dataSaverPref)
screen.addPreference(standardHttpsPortPref) screen.addPreference(standardHttpsPortPref)
screen.addPreference(contentRatingSafePref) screen.addPreference(contentRatingPref)
screen.addPreference(contentRatingSuggestivePref)
screen.addPreference(contentRatingEroticaPref)
screen.addPreference(contentRatingPornographicPref)
screen.addPreference(originalLanguageJapanesePref) screen.addPreference(originalLanguageJapanesePref)
screen.addPreference(originalLanguageChinesePref) screen.addPreference(originalLanguageChinesePref)
screen.addPreference(originalLanguageKoreanPref) screen.addPreference(originalLanguageKoreanPref)

View File

@ -22,32 +22,30 @@ class MangaDexFilters {
) )
} }
private fun getContentRating(preferences: SharedPreferences, dexLang: String) = listOf( private fun getContentRating(preferences: SharedPreferences, dexLang: String): List<ContentRating> {
ContentRating("Safe").apply { val contentRatings = preferences.getStringSet(
state = preferences.getBoolean( MDConstants.getContentRatingPrefKey(dexLang),
MDConstants.getContentRatingSafePrefKey(dexLang), MDConstants.contentRatingPrefDefaults
true )
) return listOf(
}, ContentRating("Safe").apply {
ContentRating("Suggestive").apply { state = contentRatings
state = preferences.getBoolean( ?.contains(MDConstants.contentRatingPrefValSafe) ?: true
MDConstants.getContentRatingSuggestivePrefKey(dexLang), },
true ContentRating("Suggestive").apply {
) state = contentRatings
}, ?.contains(MDConstants.contentRatingPrefValSuggestive) ?: true
ContentRating("Erotica").apply { },
state = preferences.getBoolean( ContentRating("Erotica").apply {
MDConstants.getContentRatingEroticaPrefKey(dexLang), state = contentRatings
false ?.contains(MDConstants.contentRatingPrefValErotica) ?: false
) },
}, ContentRating("Pornographic").apply {
ContentRating("Pornographic").apply { state = contentRatings
state = preferences.getBoolean( ?.contains(MDConstants.contentRatingPrefValPornographic) ?: false
MDConstants.getContentRatingPornographicPrefKey(dexLang), },
false )
) }
},
)
private class Demographic(name: String) : Filter.CheckBox(name) private class Demographic(name: String) : Filter.CheckBox(name)
private class DemographicList(demographics: List<Demographic>) : private class DemographicList(demographics: List<Demographic>) :