Add support for SwitchPreferenceCompat

This commit is contained in:
arkon 2021-05-08 09:34:08 -04:00
parent 63e4175b96
commit 8a13a17a52
3 changed files with 20 additions and 29 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:cc271c3" compileOnly "com.github.tachiyomiorg:extensions-lib:8dd92e3"
// 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

@ -24,17 +24,12 @@ object MDConstants {
const val prefixIdSearch = "id:" const val prefixIdSearch = "id:"
const val dataSaverPrefTitle = "Data saver"
const val dataSaverPrefSummary = "Enables smaller more compressed images"
const val dataSaverPref = "dataSaverV5" const val dataSaverPref = "dataSaverV5"
fun getDataSaverPreferenceKey(dexLang: String): String { fun getDataSaverPreferenceKey(dexLang: String): String {
return "${dataSaverPref}_$dexLang" return "${dataSaverPref}_$dexLang"
} }
const val standardHttpsPortTitle = "Use HTTPS port 443 only"
const val standardHttpsPortSummary =
"Enable to only request image servers that use port 443. This allows users with stricter firewall restrictions to access MangaDex images"
private const val standardHttpsPortPref = "usePort443" private const val standardHttpsPortPref = "usePort443"
fun getStandardHttpsPreferenceKey(dexLang: String): String { fun getStandardHttpsPreferenceKey(dexLang: String): String {
@ -43,28 +38,24 @@ object MDConstants {
const val showByDefaultPrefTitle = "Show only by default" const val showByDefaultPrefTitle = "Show only by default"
const val contentRatingSafePrefSummary = "Content Rating: Safe"
private const val contentRatingSafePref = "contentRatingSafe" private const val contentRatingSafePref = "contentRatingSafe"
fun getContentRatingSafePrefKey(dexLang: String): String { fun getContentRatingSafePrefKey(dexLang: String): String {
return "${contentRatingSafePref}_$dexLang" return "${contentRatingSafePref}_$dexLang"
} }
const val contentRatingSuggestivePrefSummary = "Content Rating: Suggestive"
private const val contentRatingSuggestivePref = "contentRatingSuggestive" private const val contentRatingSuggestivePref = "contentRatingSuggestive"
fun getContentRatingSuggestivePrefKey(dexLang: String): String { fun getContentRatingSuggestivePrefKey(dexLang: String): String {
return "${contentRatingSuggestivePref}_$dexLang" return "${contentRatingSuggestivePref}_$dexLang"
} }
const val contentRatingEroticaPrefSummary = "Content Rating: Erotica"
private const val contentRatingEroticaPref = "contentRatingErotica" private const val contentRatingEroticaPref = "contentRatingErotica"
fun getContentRatingEroticaPrefKey(dexLang: String): String { fun getContentRatingEroticaPrefKey(dexLang: String): String {
return "${contentRatingEroticaPref}_$dexLang" return "${contentRatingEroticaPref}_$dexLang"
} }
const val contentRatingPornographicPrefSummary = "Content Rating: Pornographic"
private const val contentRatingPornographicPref = "contentRatingPornographic" private const val contentRatingPornographicPref = "contentRatingPornographic"
fun getContentRatingPornographicPrefKey(dexLang: String): String { fun getContentRatingPornographicPrefKey(dexLang: String): String {

View File

@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.extension.all.mangadex
import android.app.Application import android.app.Application
import android.content.SharedPreferences import android.content.SharedPreferences
import android.util.Log import android.util.Log
import androidx.preference.CheckBoxPreference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import com.github.salomonbrys.kotson.array import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int import com.github.salomonbrys.kotson.int
@ -31,7 +31,8 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.util.Date import java.util.Date
abstract class MangaDex(override val lang: String, val dexLang: String) : ConfigurableSource, abstract class MangaDex(override val lang: String, val dexLang: String) :
ConfigurableSource,
HttpSource() { HttpSource() {
override val name = "MangaDex" override val name = "MangaDex"
override val baseUrl = "https://www.mangadex.org" override val baseUrl = "https://www.mangadex.org"
@ -291,13 +292,11 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
override fun imageUrlParse(response: Response): String = "" override fun imageUrlParse(response: Response): String = ""
// mangadex is mvp no settings yet
override fun setupPreferenceScreen(screen: PreferenceScreen) { override fun setupPreferenceScreen(screen: PreferenceScreen) {
val dataSaverPref = SwitchPreferenceCompat(screen.context).apply {
val dataSaverPref = CheckBoxPreference(screen.context).apply {
key = MDConstants.getDataSaverPreferenceKey(dexLang) key = MDConstants.getDataSaverPreferenceKey(dexLang)
title = MDConstants.dataSaverPrefTitle title = "Data saver"
summary = MDConstants.dataSaverPrefSummary summary = "Enables smaller, more compressed images"
setDefaultValue(false) setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -308,10 +307,11 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
} }
val standardHTTPSPref = CheckBoxPreference(screen.context).apply { val standardHttpsPortPref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getStandardHttpsPreferenceKey(dexLang) key = MDConstants.getStandardHttpsPreferenceKey(dexLang)
title = MDConstants.standardHttpsPortTitle title = "Use HTTPS port 443 only"
summary = MDConstants.standardHttpsPortSummary summary =
"Enable to only request image servers that use port 443. This allows users with stricter firewall restrictions to access MangaDex images"
setDefaultValue(false) setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -322,10 +322,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
} }
val contentRatingSafePref = CheckBoxPreference(screen.context).apply { val contentRatingSafePref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getContentRatingSafePrefKey(dexLang) key = MDConstants.getContentRatingSafePrefKey(dexLang)
title = MDConstants.showByDefaultPrefTitle title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingSafePrefSummary summary = "Content Rating: Safe"
setDefaultValue(true) setDefaultValue(true)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -336,10 +336,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
} }
val contentRatingSuggestivePref = CheckBoxPreference(screen.context).apply { val contentRatingSuggestivePref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getContentRatingSuggestivePrefKey(dexLang) key = MDConstants.getContentRatingSuggestivePrefKey(dexLang)
title = MDConstants.showByDefaultPrefTitle title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingSuggestivePrefSummary summary = "Content Rating: Suggestive"
setDefaultValue(true) setDefaultValue(true)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -350,10 +350,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
} }
val contentRatingEroticaPref = CheckBoxPreference(screen.context).apply { val contentRatingEroticaPref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getContentRatingEroticaPrefKey(dexLang) key = MDConstants.getContentRatingEroticaPrefKey(dexLang)
title = MDConstants.showByDefaultPrefTitle title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingEroticaPrefSummary summary = "Content Rating: Erotica"
setDefaultValue(false) setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -364,10 +364,10 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
} }
val contentRatingPornographicPref = CheckBoxPreference(screen.context).apply { val contentRatingPornographicPref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getContentRatingPornographicPrefKey(dexLang) key = MDConstants.getContentRatingPornographicPrefKey(dexLang)
title = MDConstants.showByDefaultPrefTitle title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingPornographicPrefSummary summary = "Content Rating: Pornographic"
setDefaultValue(false) setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
@ -381,7 +381,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
} }
screen.addPreference(dataSaverPref) screen.addPreference(dataSaverPref)
screen.addPreference(standardHTTPSPref) screen.addPreference(standardHttpsPortPref)
screen.addPreference(contentRatingSafePref) screen.addPreference(contentRatingSafePref)
screen.addPreference(contentRatingSuggestivePref) screen.addPreference(contentRatingSuggestivePref)
screen.addPreference(contentRatingEroticaPref) screen.addPreference(contentRatingEroticaPref)