diff --git a/app/build.gradle b/app/build.gradle index a2af9bac0..f26e16455 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,7 +82,7 @@ afterEvaluate { } dependencies { //noinspection GradleDependency - implementation('com.github.KotatsuApp:kotatsu-parsers:7ed8c9f787') { + implementation('com.github.KotatsuApp:kotatsu-parsers:7433fb8fa0') { exclude group: 'org.json', module: 'json' } @@ -96,9 +96,9 @@ dependencies { implementation 'androidx.fragment:fragment-ktx:1.8.1' implementation 'androidx.transition:transition-ktx:1.5.0' implementation 'androidx.collection:collection-ktx:1.4.0' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.2' - implementation 'androidx.lifecycle:lifecycle-service:2.8.2' - implementation 'androidx.lifecycle:lifecycle-process:2.8.2' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3' + implementation 'androidx.lifecycle:lifecycle-service:2.8.3' + implementation 'androidx.lifecycle:lifecycle-process:2.8.3' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.3.2' @@ -106,7 +106,7 @@ dependencies { implementation 'androidx.preference:preference-ktx:1.2.1' implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05' implementation 'com.google.android.material:material:1.12.0' - implementation 'androidx.lifecycle:lifecycle-common-java8:2.8.2' + implementation 'androidx.lifecycle:lifecycle-common-java8:2.8.3' implementation 'androidx.webkit:webkit:1.11.0' implementation 'androidx.work:work-runtime:2.9.0' diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt index 8b87e8169..6fa8a8ae4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/SourceSettings.kt @@ -38,6 +38,7 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue) is ConfigKey.SplitByTranslations -> prefs.getBoolean(key.key, key.defaultValue) + is ConfigKey.PreferredImageServer -> prefs.getString(key.key, key.defaultValue)?.takeUnless(String::isEmpty) } as T } @@ -47,6 +48,7 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig is ConfigKey.ShowSuspiciousContent -> putBoolean(key.key, value as Boolean) is ConfigKey.UserAgent -> putString(key.key, (value as String?)?.sanitizeHeaderValue()) is ConfigKey.SplitByTranslations -> putBoolean(key.key, value as Boolean) + is ConfigKey.PreferredImageServer -> putString(key.key, value as String?) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsExt.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsExt.kt index 064697808..59f249c17 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsExt.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsExt.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.settings.sources import android.view.inputmethod.EditorInfo import androidx.preference.EditTextPreference +import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreferenceCompat @@ -23,9 +24,9 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang is ConfigKey.Domain -> { val presetValues = key.presetValues if (presetValues.size <= 1) { - EditTextPreference(requireContext()) + EditTextPreference(screen.context) } else { - AutoCompleteTextViewPreference(requireContext()).apply { + AutoCompleteTextViewPreference(screen.context).apply { entries = presetValues.toStringArray() } }.apply { @@ -43,7 +44,7 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang } is ConfigKey.UserAgent -> { - AutoCompleteTextViewPreference(requireContext()).apply { + AutoCompleteTextViewPreference(screen.context).apply { entries = arrayOf( UserAgents.FIREFOX_MOBILE, UserAgents.CHROME_MOBILE, @@ -64,19 +65,32 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang } is ConfigKey.ShowSuspiciousContent -> { - SwitchPreferenceCompat(requireContext()).apply { + SwitchPreferenceCompat(screen.context).apply { setDefaultValue(key.defaultValue) setTitle(R.string.show_suspicious_content) } } is ConfigKey.SplitByTranslations -> { - SwitchPreferenceCompat(requireContext()).apply { + SwitchPreferenceCompat(screen.context).apply { setDefaultValue(key.defaultValue) setTitle(R.string.split_by_translations) setSummary(R.string.split_by_translations_summary) } } + + is ConfigKey.PreferredImageServer -> { + ListPreference(screen.context).apply { + entries = key.presetValues.values.mapToArray { + it ?: context.getString(R.string.automatic) + } + entryValues = key.presetValues.keys.mapToArray { it.orEmpty() } + setDefaultValue(key.defaultValue.orEmpty()) + setTitle(R.string.image_server) + setDialogTitle(R.string.image_server) + summaryProvider = ListPreference.SimpleSummaryProvider.getInstance() + } + } } preference.isIconSpaceReserved = false preference.key = key.key @@ -88,3 +102,10 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang private fun Array.toStringArray(): Array { return Array(size) { i -> this[i] as? String ?: "" } } + +@Suppress("UNCHECKED_CAST") +private inline fun Collection.mapToArray(transform: (T) -> R): Array { + val result = arrayOfNulls(size) + forEachIndexed { index, t -> result[index] = transform(t) } + return result as Array +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt index 460bdabcc..55923a382 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourceSettingsFragment.kt @@ -36,7 +36,7 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc addPreferencesFromRepository(viewModel.repository) findPreference(KEY_ENABLE)?.run { - setOnPreferenceChangeListener(this@SourceSettingsFragment) + onPreferenceChangeListener = this@SourceSettingsFragment } findPreference(KEY_AUTH)?.run { val authProvider = viewModel.repository.getAuthProvider() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2e0983cd..0c1e79e42 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -654,4 +654,5 @@ New All languages Block when incognito mode + Preferred image server diff --git a/app/src/main/res/xml/pref_source.xml b/app/src/main/res/xml/pref_source.xml index e27b1eb4a..3ce86fef8 100644 --- a/app/src/main/res/xml/pref_source.xml +++ b/app/src/main/res/xml/pref_source.xml @@ -23,14 +23,14 @@ android:order="101" android:persistent="false" android:summary="@string/clear_source_cookies_summary" - android:title="@string/clear_cookies" /> + android:title="@string/clear_cookies" + app:allowDividerAbove="true" /> + android:title="@string/download_slowdown" /> diff --git a/build.gradle b/build.gradle index 72ac4332e..e4c4dcc09 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:8.4.1' + classpath 'com.android.tools.build:gradle:8.5.0' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24' classpath 'com.google.dagger:hilt-android-gradle-plugin:2.51.1' classpath 'com.google.devtools.ksp:symbol-processing-gradle-plugin:1.9.24-1.0.20'