Skip to content

Commit 25aeacf

Browse files
david-allisonmikehardy
authored andcommitted
feat(sync): add 'network timeout' preference
Exposed as `SyncAuth.io_timeout_secs` in the backend https://github.com/ankitects/anki/blob/8f2144534bff6efedb22b7f052fba13ffe28cbc2/proto/anki/sync.proto#L29-L33 **UI** Upstream exposes this as a '60 seconds' textbox with an up/down picker We expose it as a NumberRangePreferenceCompat: * `@string/sync_io_timeout_secs_key` => `syncIoTimeoutSecs` * Default: 60s * Minimum: 30s * Max: 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 Fixes 20000
1 parent 3f0b776 commit 25aeacf

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fun syncAuth(): SyncAuth? {
7070
if (resolvedEndpoint != null) {
7171
this.endpoint = resolvedEndpoint
7272
}
73+
this.ioTimeoutSecs = Prefs.networkTimeoutSecs
7374
}
7475
}
7576
}

AnkiDroid/src/main/java/com/ichi2/anki/analytics/UsageAnalytics.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ object UsageAnalytics {
491491
R.string.automatic_sync_choice_key, // Automatic synchronization
492492
R.string.sync_status_badge_key, // Display synchronization status
493493
R.string.metered_sync_key, // Allow sync on metered connections
494+
R.string.sync_io_timeout_secs_key, // Network timeout
494495
R.string.one_way_sync_key, // One-way sync
495496
// ******************************** Backup *************************************************
496497
R.string.pref_minutes_between_automatic_backups_key,

AnkiDroid/src/main/java/com/ichi2/anki/preferences/SyncSettingsFragment.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616
package com.ichi2.anki.preferences
1717

1818
import androidx.appcompat.app.AlertDialog
19+
import androidx.preference.EditTextPreference
1920
import androidx.preference.Preference
2021
import com.google.android.material.snackbar.Snackbar
2122
import com.ichi2.anki.CollectionManager.TR
2223
import com.ichi2.anki.CollectionManager.withCol
2324
import com.ichi2.anki.R
2425
import com.ichi2.anki.account.AccountActivity
2526
import com.ichi2.anki.launchCatchingTask
27+
import com.ichi2.anki.runCatchingWithReport
2628
import com.ichi2.anki.settings.Prefs
2729
import com.ichi2.anki.snackbar.showSnackbar
2830
import com.ichi2.anki.utils.ext.ifNullOrEmpty
31+
import com.ichi2.preferences.NumberRangePreferenceCompat
2932
import com.ichi2.utils.show
3033

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

50+
// Configure 'Network timeout'
51+
// TODO: add 'reset to default' functionality
52+
requirePreference<NumberRangePreferenceCompat>(R.string.sync_io_timeout_secs_key).apply {
53+
title = TR.preferencesNetworkTimeout()
54+
summaryProvider =
55+
Preference.SummaryProvider<EditTextPreference> {
56+
runCatchingWithReport("network_timeout") {
57+
TR.qtMiscSecond(this.getValue())
58+
}.getOrNull() ?: getString(R.string.pref__etc__summary__error)
59+
}
60+
}
61+
4762
// Configure one-way sync option
4863
requirePreference<Preference>(R.string.one_way_sync_key).apply {
4964
setSummary(TR.preferencesOnNextSyncForceChangesIn())

AnkiDroid/src/main/java/com/ichi2/anki/settings/Prefs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ open class PrefsRepository(
255255
val shouldFetchMedia: ShouldFetchMedia
256256
get() = getEnum(R.string.sync_fetch_media_key, ShouldFetchMedia.ALWAYS)
257257

258+
var networkTimeoutSecs by intPref(R.string.sync_io_timeout_secs_key, defaultValue = 60)
259+
258260
//region Custom sync server
259261

260262
val customSyncCertificate by stringPref(R.string.custom_sync_certificate_key)

AnkiDroid/src/main/res/values/preferences.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<string name="pref_sync_screen_key">syncScreen</string>
1919
<string name="sync_account_key">syncAccount</string>
2020
<string name="sync_fetch_media_key">syncFetchMedia</string>
21+
<string name="sync_io_timeout_secs_key">syncIoTimeoutSecs</string>
2122
<string name="automatic_sync_choice_key">automaticSyncMode</string>
2223
<string name="one_way_sync_key">one_way_sync</string>
2324
<string name="sync_status_badge_key">showSyncStatusBadge</string>

AnkiDroid/src/main/res/xml/preferences_sync.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
~ this program. If not, see <http://www.gnu.org/licenses/>.
1616
-->
1717
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
18-
xmlns:app="http://schemas.android.com/apk/res-auto"
1918
xmlns:search="http://schemas.android.com/apk/com.bytehamster.lib.preferencesearch"
19+
xmlns:app="http://arbitrary.app.namespace/com.ichi2.anki"
20+
xmlns:app1="http://schemas.android.com/apk/res-auto"
2021
android:title="@string/pref_cat_sync"
2122
android:key="@string/pref_sync_screen_key"
2223
xmlns:tools="http://schemas.android.com/tools">
@@ -32,7 +33,7 @@
3233
android:entryValues="@array/sync_media_values"
3334
android:key="@string/sync_fetch_media_key"
3435
android:title="@string/sync_fetch_missing_media"
35-
app:useSimpleSummaryProvider="true"/>
36+
app1:useSimpleSummaryProvider="true"/>
3637
<SwitchPreferenceCompat
3738
android:defaultValue="false"
3839
android:key="@string/automatic_sync_choice_key"
@@ -49,6 +50,19 @@
4950
android:title="@string/metered_sync_title"
5051
android:summary="@string/metered_sync_summary" />
5152
<PreferenceCategory android:title="@string/pref_cat_advanced">
53+
<!-- Network timeout
54+
Anki Desktop:
55+
min is 30s
56+
max is 99999s
57+
https://github.com/ankitects/anki/blob/8f2144534bff6efedb22b7f052fba13ffe28cbc2/qt/aqt/profiles.py#L734-L735
58+
https://github.com/ankitects/anki/blob/8f2144534bff6efedb22b7f052fba13ffe28cbc2/qt/aqt/forms/preferences.ui#L718-L742
59+
-->
60+
<com.ichi2.preferences.IncrementerNumberRangePreferenceCompat
61+
android:key="@string/sync_io_timeout_secs_key"
62+
android:defaultValue="60"
63+
app:min="30"
64+
app:max="99999"
65+
tools:title="Network timeout" />
5266
<!-- `search:ignore` is set so that we can add this preference manually in the search index.
5367
We want to add it manually because we provide the summary at run time instead of build time, because it comes from the backend.
5468
If we didn't ignore it, searching for the title would return this preference twice.-->

0 commit comments

Comments
 (0)