-
Notifications
You must be signed in to change notification settings - Fork 97
implement sync interval every 24 hours #756
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High quality code. Well done.
@@ -90,7 +89,7 @@ open class DataStore( | |||
.subscribe { state -> | |||
when (state) { | |||
is State.Locked -> clearList() | |||
is State.Unlocked -> sync() | |||
is State.Unlocked -> syncIfRequired() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG AT LAST 😻
// this will be triggered when the system time is very low due to device restarts | ||
val currentTimeTooEarly = (syncTimerDate - currentSystemTime) > Constant.Common.twentyFourHours | ||
|
||
return syncTimerDate < currentSystemTime || currentTimeTooEarly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand the name and comment currentTimeTooEarly
.
syncTimerDate > currentSystemTime + twentyFourHours
Oh, so if syncTimerDate
(which should never be less than twenty four hours after the current time) is 24h after the current time, then we've had something weird happen, e.g. a reboot.
So, suggest: renaming currentTimeTooEarly
to followingDeviceReboot
.
val followingDeviceReboot = syncTimerDate > currentSystemTime + twentyFourHours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incidentally, I'd put 24 hours as a property.
open fun storeNextAutoLockTime() { | ||
settingStore.autoLockTime | ||
.take(1) | ||
.subscribe(this::updateNextLockTime) | ||
.addTo(compositeDisposable) | ||
} | ||
|
||
open fun storeNextSyncTime() { | ||
storeSyncTimerDate(systemTimingSupport.systemTimeElapsed + Constant.Common.twentyFourHours) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set Constant.Common.twentyFourHours
as a property of TimingSupport
.
e.g.
private val syncInterval = Constant.Common.twentyFourHours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stuck it in the constants with the expectation that it will eventually become a setting that users can configure per #757 .
} | ||
} | ||
|
||
private fun lockCurrentlyRequired(): Boolean { | ||
val currentSystemTime = lockingSupport.systemTimeElapsed | ||
val currentSystemTime = systemTimingSupport.systemTimeElapsed | ||
return if (currentSystemTime <= Constant.Common.sixtySeconds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why Constant.Common.sixtySeconds
is not in a property — isn't autoLockInterval
settable via SharedPreferences
?
Fixes #735
Connected to #754
Testing and Review Notes
Currently, manual sync resets the 24 hour timer, so if you would like to see an automatic sync, don't sync manually!
To Do