Skip to content

Commit

Permalink
NF: make DeckPicker.automaticSync() more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Aug 26, 2022
1 parent 0942a29 commit de6d4c5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,12 @@ open class DeckPicker :

// Check whether the option is selected, the user is signed in and last sync was AUTOMATIC_SYNC_TIME ago
// (currently 10 minutes)
val hkey = preferences.getString("hkey", "")
val isLoggedIn = preferences.getString("hkey", "")!!.isNotEmpty()
val lastSyncTime = preferences.getLong("lastSyncTime", 0)
if (hkey!!.isNotEmpty() && preferences.getBoolean("automaticSyncMode", false) &&
Connection.isOnline && TimeManager.time.intTimeMS() - lastSyncTime > AUTOMATIC_SYNC_MIN_INTERVAL
) {
val autoSyncIsEnabled = preferences.getBoolean("automaticSyncMode", false)
val syncIntervalPassed = TimeManager.time.intTimeMS() - lastSyncTime > AUTOMATIC_SYNC_MIN_INTERVAL

if (isLoggedIn && autoSyncIsEnabled && Connection.isOnline && syncIntervalPassed) {
Timber.i("Triggering Automatic Sync")
sync()
}
Expand Down

0 comments on commit de6d4c5

Please sign in to comment.