Skip to content

Commit 05cb92b

Browse files
committed
refactor(deck-picker): AUTOMATIC_SYNC_MINIMAL_INTERVAL
Use the Kotlin 'Duration' Assisted-by: Claude Opus 4.7 - review
1 parent 9d3a70f commit 05cb92b

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ import kotlinx.coroutines.withContext
204204
import net.ankiweb.rsdroid.Translations
205205
import timber.log.Timber
206206
import java.io.File
207+
import kotlin.time.Duration
208+
import kotlin.time.Duration.Companion.minutes
207209

208210
/**
209211
* The current entry point for AnkiDroid. Displays decks, allowing users to study. Many other functions.
@@ -1410,10 +1412,8 @@ open class DeckPicker :
14101412
}
14111413
}
14121414

1413-
fun syncIntervalPassed(): Boolean {
1414-
val automaticSyncIntervalInMS = AUTOMATIC_SYNC_MINIMAL_INTERVAL_IN_MINUTES * 60 * 1000
1415-
return TimeManager.time.intTimeMS() - Prefs.lastSyncTime > automaticSyncIntervalInMS
1416-
}
1415+
fun syncIntervalPassed(): Boolean =
1416+
(TimeManager.time.intTimeMS() - Prefs.lastSyncTime) > AUTOMATIC_SYNC_MINIMAL_INTERVAL.inWholeMilliseconds
14171417

14181418
when {
14191419
!Prefs.isAutoSyncEnabled -> Timber.d("autoSync: not enabled")
@@ -2181,9 +2181,12 @@ open class DeckPicker :
21812181
@VisibleForTesting
21822182
const val REQUEST_STORAGE_PERMISSION = 0
21832183

2184-
// For automatic syncing
2185-
// 10 minutes in milliseconds..
2186-
private const val AUTOMATIC_SYNC_MINIMAL_INTERVAL_IN_MINUTES: Long = 10
2184+
/**
2185+
* Minimum delay between automatic syncs.
2186+
*
2187+
* Skips the automatic sync if this time has not elapsed.
2188+
*/
2189+
private val AUTOMATIC_SYNC_MINIMAL_INTERVAL: Duration = 10.minutes
21872190
private const val SWIPE_TO_SYNC_TRIGGER_DISTANCE = 400
21882191

21892192
private const val PREF_DECK_PICKER_PANE_WEIGHT = "deckPickerPaneWeight"

0 commit comments

Comments
 (0)