Update parsers and add image server option support

master
Koitharu 2 years ago
parent 77e393ae48
commit 1f03e0a84b
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -82,7 +82,7 @@ afterEvaluate {
} }
dependencies { dependencies {
//noinspection GradleDependency //noinspection GradleDependency
implementation('com.github.KotatsuApp:kotatsu-parsers:7ed8c9f787') { implementation('com.github.KotatsuApp:kotatsu-parsers:7433fb8fa0') {
exclude group: 'org.json', module: 'json' exclude group: 'org.json', module: 'json'
} }
@ -96,9 +96,9 @@ dependencies {
implementation 'androidx.fragment:fragment-ktx:1.8.1' implementation 'androidx.fragment:fragment-ktx:1.8.1'
implementation 'androidx.transition:transition-ktx:1.5.0' implementation 'androidx.transition:transition-ktx:1.5.0'
implementation 'androidx.collection:collection-ktx:1.4.0' implementation 'androidx.collection:collection-ktx:1.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.2' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3'
implementation 'androidx.lifecycle:lifecycle-service:2.8.2' implementation 'androidx.lifecycle:lifecycle-service:2.8.3'
implementation 'androidx.lifecycle:lifecycle-process:2.8.2' implementation 'androidx.lifecycle:lifecycle-process:2.8.3'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2' implementation 'androidx.recyclerview:recyclerview:1.3.2'
@ -106,7 +106,7 @@ dependencies {
implementation 'androidx.preference:preference-ktx:1.2.1' implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05' implementation 'androidx.biometric:biometric-ktx:1.2.0-alpha05'
implementation 'com.google.android.material:material:1.12.0' 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.webkit:webkit:1.11.0'
implementation 'androidx.work:work-runtime:2.9.0' implementation 'androidx.work:work-runtime:2.9.0'

@ -38,6 +38,7 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue) is ConfigKey.ShowSuspiciousContent -> prefs.getBoolean(key.key, key.defaultValue)
is ConfigKey.SplitByTranslations -> 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 } as T
} }
@ -47,6 +48,7 @@ class SourceSettings(context: Context, source: MangaSource) : MangaSourceConfig
is ConfigKey.ShowSuspiciousContent -> putBoolean(key.key, value as Boolean) is ConfigKey.ShowSuspiciousContent -> putBoolean(key.key, value as Boolean)
is ConfigKey.UserAgent -> putString(key.key, (value as String?)?.sanitizeHeaderValue()) is ConfigKey.UserAgent -> putString(key.key, (value as String?)?.sanitizeHeaderValue())
is ConfigKey.SplitByTranslations -> putBoolean(key.key, value as Boolean) is ConfigKey.SplitByTranslations -> putBoolean(key.key, value as Boolean)
is ConfigKey.PreferredImageServer -> putString(key.key, value as String?)
} }
} }

@ -2,6 +2,7 @@ package org.koitharu.kotatsu.settings.sources
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
@ -23,9 +24,9 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang
is ConfigKey.Domain -> { is ConfigKey.Domain -> {
val presetValues = key.presetValues val presetValues = key.presetValues
if (presetValues.size <= 1) { if (presetValues.size <= 1) {
EditTextPreference(requireContext()) EditTextPreference(screen.context)
} else { } else {
AutoCompleteTextViewPreference(requireContext()).apply { AutoCompleteTextViewPreference(screen.context).apply {
entries = presetValues.toStringArray() entries = presetValues.toStringArray()
} }
}.apply { }.apply {
@ -43,7 +44,7 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang
} }
is ConfigKey.UserAgent -> { is ConfigKey.UserAgent -> {
AutoCompleteTextViewPreference(requireContext()).apply { AutoCompleteTextViewPreference(screen.context).apply {
entries = arrayOf( entries = arrayOf(
UserAgents.FIREFOX_MOBILE, UserAgents.FIREFOX_MOBILE,
UserAgents.CHROME_MOBILE, UserAgents.CHROME_MOBILE,
@ -64,19 +65,32 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang
} }
is ConfigKey.ShowSuspiciousContent -> { is ConfigKey.ShowSuspiciousContent -> {
SwitchPreferenceCompat(requireContext()).apply { SwitchPreferenceCompat(screen.context).apply {
setDefaultValue(key.defaultValue) setDefaultValue(key.defaultValue)
setTitle(R.string.show_suspicious_content) setTitle(R.string.show_suspicious_content)
} }
} }
is ConfigKey.SplitByTranslations -> { is ConfigKey.SplitByTranslations -> {
SwitchPreferenceCompat(requireContext()).apply { SwitchPreferenceCompat(screen.context).apply {
setDefaultValue(key.defaultValue) setDefaultValue(key.defaultValue)
setTitle(R.string.split_by_translations) setTitle(R.string.split_by_translations)
setSummary(R.string.split_by_translations_summary) 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.isIconSpaceReserved = false
preference.key = key.key preference.key = key.key
@ -88,3 +102,10 @@ fun PreferenceFragmentCompat.addPreferencesFromRepository(repository: RemoteMang
private fun Array<out String>.toStringArray(): Array<String> { private fun Array<out String>.toStringArray(): Array<String> {
return Array(size) { i -> this[i] as? String ?: "" } return Array(size) { i -> this[i] as? String ?: "" }
} }
@Suppress("UNCHECKED_CAST")
private inline fun <T, reified R> Collection<T>.mapToArray(transform: (T) -> R): Array<R> {
val result = arrayOfNulls<R>(size)
forEachIndexed { index, t -> result[index] = transform(t) }
return result as Array<R>
}

@ -36,7 +36,7 @@ class SourceSettingsFragment : BasePreferenceFragment(0), Preference.OnPreferenc
addPreferencesFromRepository(viewModel.repository) addPreferencesFromRepository(viewModel.repository)
findPreference<SwitchPreferenceCompat>(KEY_ENABLE)?.run { findPreference<SwitchPreferenceCompat>(KEY_ENABLE)?.run {
setOnPreferenceChangeListener(this@SourceSettingsFragment) onPreferenceChangeListener = this@SourceSettingsFragment
} }
findPreference<Preference>(KEY_AUTH)?.run { findPreference<Preference>(KEY_AUTH)?.run {
val authProvider = viewModel.repository.getAuthProvider() val authProvider = viewModel.repository.getAuthProvider()

@ -654,4 +654,5 @@
<string name="_new">New</string> <string name="_new">New</string>
<string name="all_languages">All languages</string> <string name="all_languages">All languages</string>
<string name="screenshots_block_incognito">Block when incognito mode</string> <string name="screenshots_block_incognito">Block when incognito mode</string>
<string name="image_server">Preferred image server</string>
</resources> </resources>

@ -23,14 +23,14 @@
android:order="101" android:order="101"
android:persistent="false" android:persistent="false"
android:summary="@string/clear_source_cookies_summary" android:summary="@string/clear_source_cookies_summary"
android:title="@string/clear_cookies" /> android:title="@string/clear_cookies"
app:allowDividerAbove="true" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
android:key="slowdown" android:key="slowdown"
android:order="105" android:order="105"
android:summary="@string/download_slowdown_summary" android:summary="@string/download_slowdown_summary"
android:title="@string/download_slowdown" android:title="@string/download_slowdown" />
app:allowDividerAbove="true" />
</PreferenceScreen> </PreferenceScreen>

@ -4,7 +4,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { 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 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.51.1' 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' classpath 'com.google.devtools.ksp:symbol-processing-gradle-plugin:1.9.24-1.0.20'

Loading…
Cancel
Save