Overhaul 2025 (See PR for changes)
This commit is contained in:
@@ -1,23 +1,3 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
kotlin("android")
|
||||
id("kotlinx-serialization")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = AndroidConfig.compileSdk
|
||||
|
||||
defaultConfig {
|
||||
minSdk = AndroidConfig.minSdk
|
||||
}
|
||||
|
||||
namespace = "eu.kanade.tachiyomi.lib.randomua"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.bundles.common)
|
||||
id("lib-android")
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ private class RandomUserAgentInterceptor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val UA_DB_URL = "https://tachiyomiorg.github.io/user-agents/user-agents.json"
|
||||
private const val UA_DB_URL = "https://keiyoushi.github.io/user-agents/user-agents.json"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import androidx.preference.PreferenceScreen
|
||||
import okhttp3.Headers
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to return UserAgentType based on SharedPreference value
|
||||
*/
|
||||
/**
|
||||
* Helper function to return UserAgentType based on SharedPreference value
|
||||
*/
|
||||
fun SharedPreferences.getPrefUAType(): UserAgentType {
|
||||
return when (getString(PREF_KEY_RANDOM_UA, "off")) {
|
||||
"mobile" -> UserAgentType.MOBILE
|
||||
@@ -34,7 +34,9 @@ fun SharedPreferences.getPrefCustomUA(): String? {
|
||||
fun addRandomUAPreferenceToScreen(
|
||||
screen: PreferenceScreen,
|
||||
) {
|
||||
ListPreference(screen.context).apply {
|
||||
val context = screen.context
|
||||
|
||||
ListPreference(context).apply {
|
||||
key = PREF_KEY_RANDOM_UA
|
||||
title = TITLE_RANDOM_UA
|
||||
entries = RANDOM_UA_ENTRIES
|
||||
@@ -43,28 +45,27 @@ fun addRandomUAPreferenceToScreen(
|
||||
setDefaultValue("off")
|
||||
}.also(screen::addPreference)
|
||||
|
||||
EditTextPreference(screen.context).apply {
|
||||
EditTextPreference(context).apply {
|
||||
key = PREF_KEY_CUSTOM_UA
|
||||
title = TITLE_CUSTOM_UA
|
||||
summary = CUSTOM_UA_SUMMARY
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
try {
|
||||
Headers.Builder().add("User-Agent", newValue as String).build()
|
||||
Headers.headersOf("User-Agent", newValue as String)
|
||||
true
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Toast.makeText(screen.context, "User Agent invalid:${e.message}", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, "Invalid user agent string: ${e.message}", Toast.LENGTH_LONG).show()
|
||||
false
|
||||
}
|
||||
}
|
||||
}.also(screen::addPreference)
|
||||
}
|
||||
|
||||
const val TITLE_RANDOM_UA = "Random User-Agent (Requires Restart)"
|
||||
const val TITLE_RANDOM_UA = "Random user agent string (requires restart)"
|
||||
const val PREF_KEY_RANDOM_UA = "pref_key_random_ua_"
|
||||
val RANDOM_UA_ENTRIES = arrayOf("OFF", "Desktop", "Mobile")
|
||||
val RANDOM_UA_VALUES = arrayOf("off", "desktop", "mobile")
|
||||
|
||||
const val TITLE_CUSTOM_UA = "Custom User-Agent (Requires Restart)"
|
||||
const val TITLE_CUSTOM_UA = "Custom user agent string (requires restart)"
|
||||
const val PREF_KEY_CUSTOM_UA = "pref_key_custom_ua_"
|
||||
const val CUSTOM_UA_SUMMARY = "Leave blank to use application default user-agent (IGNORED if Random User-Agent is enabled)"
|
||||
|
||||
const val CUSTOM_UA_SUMMARY = "Leave blank to use the default user agent string (ignored if random user agent string is enabled)"
|
||||
|
||||
Reference in New Issue
Block a user