Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove BuildConfig from preference keys #3023

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ar/arabseed/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Arab Seed'
extClass = '.ArabSeed'
extVersionCode = 11
extVersionCode = 12
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package eu.kanade.tachiyomi.animeextension.ar.arabseed

import android.app.Application
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.BuildConfig
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
Expand All @@ -31,9 +28,9 @@ class ArabSeed : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "عرب سيد"

override val baseUrl by lazy {
preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT)!!
}
// TODO: Check frequency of url changes to potentially
// add back overridable baseurl preference
override val baseUrl = "https://m.asd.homes"

override val lang = "ar"

Expand Down Expand Up @@ -209,23 +206,6 @@ class ArabSeed : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

// =============================== Preferences ===============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val defaultDomainPref = EditTextPreference(screen.context).apply {
key = PREF_DOMAIN_KEY
title = PREF_DOMAIN_TITLE
dialogTitle = PREF_DOMAIN_DIALOG_TITLE
dialogMessage = PREF_DOMAIN_DIALOG_MESSAGE
setDefaultValue(PREF_DOMAIN_DEFAULT)
summary = PREF_DOMAIN_SUMMARY

setOnPreferenceChangeListener { _, newValue ->
runCatching {
val value = (newValue as String).ifEmpty { PREF_DOMAIN_DEFAULT }
Toast.makeText(screen.context, PREF_DOMAIN_TOAST, Toast.LENGTH_LONG).show()
preferences.edit().putString(key, value).commit()
}.getOrDefault(false)
}
}

val videoQualityPref = ListPreference(screen.context).apply {
key = PREF_QUALITY_KEY
title = PREF_QUALITY_TITLE
Expand All @@ -241,21 +221,11 @@ class ArabSeed : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
preferences.edit().putString(key, entry).commit()
}
}
screen.addPreference(defaultDomainPref)
screen.addPreference(videoQualityPref)
}

// ============================= Utilities ==============================
companion object {
// From egydead(ar)
private const val PREF_DOMAIN_KEY = "default_domain_v${BuildConfig.VERSION_NAME}"
private const val PREF_DOMAIN_TITLE = "Override default domain with a custom, different one"
private const val PREF_DOMAIN_DEFAULT = "https://m95.arabseed.show"
private const val PREF_DOMAIN_DIALOG_TITLE = "Enter custom domain"
private const val PREF_DOMAIN_DIALOG_MESSAGE = "Default/Original domain: $PREF_DOMAIN_DEFAULT"
private const val PREF_DOMAIN_SUMMARY = "You can change the site domain from here"
private const val PREF_DOMAIN_TOAST = "Restart Aniyomi to apply changes"

private const val PREF_QUALITY_KEY = "preferred_quality"
private const val PREF_QUALITY_TITLE = "Preferred quality"
private const val PREF_QUALITY_DEFAULT = "1080"
Expand Down
2 changes: 1 addition & 1 deletion src/ar/egydead/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Egy Dead'
extClass = '.EgyDead'
extVersionCode = 11
extVersionCode = 12
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package eu.kanade.tachiyomi.animeextension.ar.egydead

import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.BuildConfig
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
Expand All @@ -29,15 +26,14 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.lang.Exception

class EgyDead : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "Egy Dead"

override val baseUrl by lazy {
getPrefHostUrl(preferences)
}
// TODO: Check frequency of url changes to potentially
// add back overridable baseurl preference
override val baseUrl = "https://egydead.space"

override val lang = "ar"

Expand Down Expand Up @@ -297,32 +293,7 @@ class EgyDead : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

// ================================== preferences ==================================

private fun getPrefHostUrl(preferences: SharedPreferences): String = preferences.getString(
"default_domain_v${BuildConfig.VERSION_CODE}",
"https://egydead.space/",
)!!.trim()

override fun setupPreferenceScreen(screen: PreferenceScreen) {
val defaultDomain = EditTextPreference(screen.context).apply {
key = "default_domain"
title = "Override default domain with a different one"
summary = getPrefHostUrl(preferences)
this.setDefaultValue(getPrefHostUrl(preferences))
dialogTitle = "Enter default domain"
dialogMessage = "You can change the site domain from here"

setOnPreferenceChangeListener { _, newValue ->
try {
val res = preferences.edit().putString("default_domain", newValue as String).commit()
Toast.makeText(screen.context, "Restart Aniyomi to apply changes", Toast.LENGTH_LONG).show()
res
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}

val videoQualityPref = ListPreference(screen.context).apply {
key = "preferred_quality"
title = "Preferred quality"
Expand All @@ -338,7 +309,6 @@ class EgyDead : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
preferences.edit().putString(key, entry).commit()
}
}
screen.addPreference(defaultDomain)
screen.addPreference(videoQualityPref)
}

Expand Down
2 changes: 1 addition & 1 deletion src/ar/tuktukcinema/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Tuktuk Cinema'
extClass = '.Tuktukcinema'
extVersionCode = 17
extVersionCode = 18
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package eu.kanade.tachiyomi.animeextension.ar.tuktukcinema

import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import dev.datlag.jsunpacker.JsUnpacker
import eu.kanade.tachiyomi.animeextension.BuildConfig
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
Expand All @@ -30,15 +27,14 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.lang.Exception

class Tuktukcinema : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "توك توك سينما"

override val baseUrl by lazy {
getPrefHostUrl(preferences)
}
// TODO: Check frequency of url changes to potentially
// add back overridable baseurl preference
override val baseUrl = "https://w.tuktokcinema.com"

override val lang = "ar"

Expand Down Expand Up @@ -292,33 +288,7 @@ class Tuktukcinema : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
CatUnit("مسلسلات هندى", "category/series-9/مسلسلات-هندي/"),
)

// preferred quality settings
private fun getPrefHostUrl(preferences: SharedPreferences): String = preferences.getString(
"default_domain_v${BuildConfig.VERSION_CODE}",
"https://ww.tuktukcima.com/",
)!!.trim()

override fun setupPreferenceScreen(screen: PreferenceScreen) {
val defaultDomain = EditTextPreference(screen.context).apply {
key = "default_domain"
title = "Enter default domain"
summary = getPrefHostUrl(preferences)
this.setDefaultValue(getPrefHostUrl(preferences))
dialogTitle = "Default domain"
dialogMessage = "You can change the site domain from here"

setOnPreferenceChangeListener { _, newValue ->
try {
val res = preferences.edit().putString("default_domain", newValue as String).commit()
Toast.makeText(screen.context, "Restart Aniyomi to apply changes", Toast.LENGTH_LONG).show()
res
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}

val videoQualityPref = ListPreference(screen.context).apply {
key = "preferred_quality"
title = "Preferred quality"
Expand All @@ -334,7 +304,6 @@ class Tuktukcinema : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
preferences.edit().putString(key, entry).commit()
}
}
screen.addPreference(defaultDomain)
screen.addPreference(videoQualityPref)
}
}
2 changes: 1 addition & 1 deletion src/en/ask4movie/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Ask4Movie'
extClass = '.Ask4Movie'
extVersionCode = 11
extVersionCode = 12
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package eu.kanade.tachiyomi.animeextension.en.ask4movie

import android.app.Application
import android.content.SharedPreferences
import android.widget.Toast
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.BuildConfig
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
Expand All @@ -21,23 +14,19 @@ 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

class Ask4Movie : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
class Ask4Movie : ParsedAnimeHttpSource() {

override val name = "Ask4Movie"

override val baseUrl by lazy { preferences.getString(PREF_DOMAIN_KEY, PREF_DOMAIN_DEFAULT)!! }
// TODO: Check frequency of url changes to potentially
// add back overridable baseurl preference
override val baseUrl = "https://ask4movie.li"

override val lang = "en"

override val supportsLatest = true

private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

// ============================== Popular ===============================

override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/channel_cat/trending/page/$page/", headers)
Expand Down Expand Up @@ -191,32 +180,6 @@ class Ask4Movie : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
}
}

companion object {
private val PREF_DOMAIN_KEY = "preferred_domain_name_v${BuildConfig.VERSION_NAME}"
private const val PREF_DOMAIN_TITLE = "Override BaseUrl"
private const val PREF_DOMAIN_DEFAULT = "https://ask4movie.li"
private const val PREF_DOMAIN_SUMMARY = "For temporary uses. Updating the extension will erase this setting."
}

// ============================== Settings ==============================

override fun setupPreferenceScreen(screen: PreferenceScreen) {
EditTextPreference(screen.context).apply {
key = PREF_DOMAIN_KEY
title = PREF_DOMAIN_TITLE
summary = PREF_DOMAIN_SUMMARY
dialogTitle = PREF_DOMAIN_TITLE
dialogMessage = "Default: $PREF_DOMAIN_DEFAULT"
setDefaultValue(PREF_DOMAIN_DEFAULT)

setOnPreferenceChangeListener { _, newValue ->
val newValueString = newValue as String
Toast.makeText(screen.context, "Restart Aniyomi to apply new setting.", Toast.LENGTH_LONG).show()
preferences.edit().putString(key, newValueString.trim()).commit()
}
}.also(screen::addPreference)
}

// ============================== Filters ===============================

override fun getFilterList(): AnimeFilterList = AnimeFilterList(
Expand Down
2 changes: 1 addition & 1 deletion src/en/dramacool/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'DramaCool'
extClass = '.DramaCool'
extVersionCode = 47
extVersionCode = 48
}

apply from: "$rootDir/common.gradle"
Expand Down
Loading