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
dependencies {
// 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
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

View File

@ -24,17 +24,12 @@ object MDConstants {
const val prefixIdSearch = "id:"
const val dataSaverPrefTitle = "Data saver"
const val dataSaverPrefSummary = "Enables smaller more compressed images"
const val dataSaverPref = "dataSaverV5"
fun getDataSaverPreferenceKey(dexLang: String): String {
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"
fun getStandardHttpsPreferenceKey(dexLang: String): String {
@ -43,28 +38,24 @@ object MDConstants {
const val showByDefaultPrefTitle = "Show only by default"
const val contentRatingSafePrefSummary = "Content Rating: Safe"
private const val contentRatingSafePref = "contentRatingSafe"
fun getContentRatingSafePrefKey(dexLang: String): String {
return "${contentRatingSafePref}_$dexLang"
}
const val contentRatingSuggestivePrefSummary = "Content Rating: Suggestive"
private const val contentRatingSuggestivePref = "contentRatingSuggestive"
fun getContentRatingSuggestivePrefKey(dexLang: String): String {
return "${contentRatingSuggestivePref}_$dexLang"
}
const val contentRatingEroticaPrefSummary = "Content Rating: Erotica"
private const val contentRatingEroticaPref = "contentRatingErotica"
fun getContentRatingEroticaPrefKey(dexLang: String): String {
return "${contentRatingEroticaPref}_$dexLang"
}
const val contentRatingPornographicPrefSummary = "Content Rating: Pornographic"
private const val contentRatingPornographicPref = "contentRatingPornographic"
fun getContentRatingPornographicPrefKey(dexLang: String): String {

View File

@ -3,8 +3,8 @@ package eu.kanade.tachiyomi.extension.all.mangadex
import android.app.Application
import android.content.SharedPreferences
import android.util.Log
import androidx.preference.CheckBoxPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int
@ -31,7 +31,8 @@ import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
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() {
override val name = "MangaDex"
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 = ""
// mangadex is mvp no settings yet
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val dataSaverPref = CheckBoxPreference(screen.context).apply {
val dataSaverPref = SwitchPreferenceCompat(screen.context).apply {
key = MDConstants.getDataSaverPreferenceKey(dexLang)
title = MDConstants.dataSaverPrefTitle
summary = MDConstants.dataSaverPrefSummary
title = "Data saver"
summary = "Enables smaller, more compressed images"
setDefaultValue(false)
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)
title = MDConstants.standardHttpsPortTitle
summary = MDConstants.standardHttpsPortSummary
title = "Use HTTPS port 443 only"
summary =
"Enable to only request image servers that use port 443. This allows users with stricter firewall restrictions to access MangaDex images"
setDefaultValue(false)
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)
title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingSafePrefSummary
summary = "Content Rating: Safe"
setDefaultValue(true)
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)
title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingSuggestivePrefSummary
summary = "Content Rating: Suggestive"
setDefaultValue(true)
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)
title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingEroticaPrefSummary
summary = "Content Rating: Erotica"
setDefaultValue(false)
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)
title = MDConstants.showByDefaultPrefTitle
summary = MDConstants.contentRatingPornographicPrefSummary
summary = "Content Rating: Pornographic"
setDefaultValue(false)
setOnPreferenceChangeListener { _, newValue ->
@ -381,7 +381,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) : Config
}
screen.addPreference(dataSaverPref)
screen.addPreference(standardHTTPSPref)
screen.addPreference(standardHttpsPortPref)
screen.addPreference(contentRatingSafePref)
screen.addPreference(contentRatingSuggestivePref)
screen.addPreference(contentRatingEroticaPref)