Skip to content
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
1 change: 1 addition & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fun syncAuth(): SyncAuth? {
if (resolvedEndpoint != null) {
this.endpoint = resolvedEndpoint
}
this.ioTimeoutSecs = Prefs.networkTimeoutSecs
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ object UsageAnalytics {
R.string.automatic_sync_choice_key, // Automatic synchronization
R.string.sync_status_badge_key, // Display synchronization status
R.string.metered_sync_key, // Allow sync on metered connections
R.string.sync_io_timeout_secs_key, // Network timeout
R.string.one_way_sync_key, // One-way sync
// ******************************** Backup *************************************************
R.string.pref_minutes_between_automatic_backups_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
package com.ichi2.anki.preferences

import androidx.appcompat.app.AlertDialog
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.account.AccountActivity
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.runCatchingWithReport
import com.ichi2.anki.settings.Prefs
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.ext.ifNullOrEmpty
import com.ichi2.preferences.NumberRangePreferenceCompat
import com.ichi2.utils.show

/**
Expand All @@ -44,6 +47,18 @@ class SyncSettingsFragment : SettingsFragment() {
// Enable/disable one-way sync if the user is logged in
updateOneWaySyncEnabledState()

// Configure 'Network timeout'
// TODO: add 'reset to default' functionality
requirePreference<NumberRangePreferenceCompat>(R.string.sync_io_timeout_secs_key).apply {
title = TR.preferencesNetworkTimeout()
summaryProvider =
Preference.SummaryProvider<EditTextPreference> {
runCatchingWithReport("network_timeout") {
TR.qtMiscSecond(this.getValue())
}.getOrNull() ?: getString(R.string.pref__etc__summary__error)
}
}

// Configure one-way sync option
requirePreference<Preference>(R.string.one_way_sync_key).apply {
setSummary(TR.preferencesOnNextSyncForceChangesIn())
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/settings/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ open class PrefsRepository(
val shouldFetchMedia: ShouldFetchMedia
get() = getEnum(R.string.sync_fetch_media_key, ShouldFetchMedia.ALWAYS)

var networkTimeoutSecs by intPref(R.string.sync_io_timeout_secs_key, defaultValue = 60)

//region Custom sync server

val customSyncCertificate by stringPref(R.string.custom_sync_certificate_key)
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="pref_sync_screen_key">syncScreen</string>
<string name="sync_account_key">syncAccount</string>
<string name="sync_fetch_media_key">syncFetchMedia</string>
<string name="sync_io_timeout_secs_key">syncIoTimeoutSecs</string>
<string name="automatic_sync_choice_key">automaticSyncMode</string>
<string name="one_way_sync_key">one_way_sync</string>
<string name="sync_status_badge_key">showSyncStatusBadge</string>
Expand Down
18 changes: 16 additions & 2 deletions AnkiDroid/src/main/res/xml/preferences_sync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch"
xmlns:app="http://arbitrary.app.namespace/com.ichi2.anki"
xmlns:app1="http://schemas.android.com/apk/res-auto"
android:title="@string/pref_cat_sync"
android:key="@string/pref_sync_screen_key"
xmlns:tools="http://schemas.android.com/tools">
Expand All @@ -32,7 +33,7 @@
android:entryValues="@array/sync_media_values"
android:key="@string/sync_fetch_media_key"
android:title="@string/sync_fetch_missing_media"
app:useSimpleSummaryProvider="true"/>
app1:useSimpleSummaryProvider="true"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/automatic_sync_choice_key"
Expand All @@ -49,6 +50,19 @@
android:title="@string/metered_sync_title"
android:summary="@string/metered_sync_summary" />
<PreferenceCategory android:title="@string/pref_cat_advanced">
<!-- Network timeout
Anki Desktop:
min is 30s
max is 99999s
https://github.com/ankitects/anki/blob/8f2144534bff6efedb22b7f052fba13ffe28cbc2/qt/aqt/profiles.py#L734-L735
https://github.com/ankitects/anki/blob/8f2144534bff6efedb22b7f052fba13ffe28cbc2/qt/aqt/forms/preferences.ui#L718-L742
-->
<com.ichi2.preferences.IncrementerNumberRangePreferenceCompat
android:key="@string/sync_io_timeout_secs_key"
android:defaultValue="60"
app:min="30"
app:max="99999"
tools:title="Network timeout" />
<!-- `search:ignore` is set so that we can add this preference manually in the search index.
We want to add it manually because we provide the summary at run time instead of build time, because it comes from the backend.
If we didn't ignore it, searching for the title would return this preference twice.-->
Expand Down