Option to disable automatic mirror switching

This commit is contained in:
Koitharu
2023-05-07 19:19:57 +03:00
parent 1ead369ee2
commit fc1755612b
4 changed files with 19 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import okhttp3.internal.closeQuietly
import okhttp3.internal.publicsuffix.PublicSuffixDatabase
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.parser.RemoteMangaRepository
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.parsers.model.MangaSource
import javax.inject.Inject
import javax.inject.Singleton
@@ -18,10 +19,14 @@ import javax.inject.Singleton
@Singleton
class MirrorSwitchInterceptor @Inject constructor(
private val mangaRepositoryFactoryLazy: Lazy<MangaRepository.Factory>,
private val settings: AppSettings,
) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
if (!settings.isMirrorSwitchingAvailable) {
return chain.proceed(request)
}
return try {
val response = chain.proceed(request)
if (response.isFailed) {

View File

@@ -165,6 +165,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
get() = prefs.getBoolean(KEY_PROTECT_APP_BIOMETRIC, true)
set(value) = prefs.edit { putBoolean(KEY_PROTECT_APP_BIOMETRIC, value) }
val isMirrorSwitchingAvailable: Boolean
get() = prefs.getBoolean(KEY_MIRROR_SWITCHING, true)
val isExitConfirmationEnabled: Boolean
get() = prefs.getBoolean(KEY_EXIT_CONFIRM, false)
@@ -405,6 +408,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_TIPS_CLOSED = "tips_closed"
const val KEY_SSL_BYPASS = "ssl_bypass"
const val KEY_READER_AUTOSCROLL_SPEED = "as_speed"
const val KEY_MIRROR_SWITCHING = "mirror_switching"
// About
const val KEY_APP_UPDATE = "app_update"

View File

@@ -438,4 +438,7 @@
<string name="sync_settings">Synchronization settings</string>
<string name="server_address">Server address</string>
<string name="sync_host_description">You can use a self-hosted synchronization server or a default one. Don\'t change this if you\'re not sure what you\'re doing.</string>
<string name="ignore_ssl_errors">Ignore SSL errors</string>
<string name="mirror_switching">Choose mirror automatically</string>
<string name="mirror_switching_summary">Automatically switch domains for remote sources on errors if mirrors are available</string>
</resources>

View File

@@ -59,7 +59,13 @@
<SwitchPreferenceCompat
android:key="ssl_bypass"
android:title="Ignore SSL errors" />
android:title="@string/ignore_ssl_errors" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="mirror_switching"
android:summary="@string/mirror_switching_summary"
android:title="@string/mirror_switching" />
<PreferenceScreen
android:fragment="org.koitharu.kotatsu.settings.backup.BackupSettingsFragment"