NSC: fix sync if there is messed up date in phone
This commit is contained in:
parent
656e3e44be
commit
fec3e71aef
|
@ -81,10 +81,15 @@ class NsIncomingDataProcessor @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess list of SGVs
|
||||
*
|
||||
* @return true if there was an accepted SGV
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
fun processSgvs(sgvs: Any) {
|
||||
fun processSgvs(sgvs: Any): Boolean {
|
||||
|
||||
if (!nsClientSource.isEnabled() && !sp.getBoolean(app.aaps.core.utils.R.string.key_ns_receive_cgm, false)) return
|
||||
if (!nsClientSource.isEnabled() && !sp.getBoolean(app.aaps.core.utils.R.string.key_ns_receive_cgm, false)) return false
|
||||
|
||||
var latestDateInReceivedData: Long = 0
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Received NS Data: $sgvs")
|
||||
|
@ -104,16 +109,24 @@ class NsIncomingDataProcessor @Inject constructor(
|
|||
glucoseValues += sgv
|
||||
}
|
||||
}
|
||||
activePlugin.activeNsClient?.updateLatestBgReceivedIfNewer(latestDateInReceivedData)
|
||||
// Was that sgv more less 5 mins ago ?
|
||||
if (T.msecs(dateUtil.now() - latestDateInReceivedData).mins() < 5L) {
|
||||
rxBus.send(EventDismissNotification(Notification.NS_ALARM))
|
||||
rxBus.send(EventDismissNotification(Notification.NS_URGENT_ALARM))
|
||||
if (latestDateInReceivedData > 0) {
|
||||
activePlugin.activeNsClient?.updateLatestBgReceivedIfNewer(latestDateInReceivedData)
|
||||
// Was that sgv more less 5 mins ago ?
|
||||
if (T.msecs(dateUtil.now() - latestDateInReceivedData).mins() < 5L) {
|
||||
rxBus.send(EventDismissNotification(Notification.NS_ALARM))
|
||||
rxBus.send(EventDismissNotification(Notification.NS_URGENT_ALARM))
|
||||
}
|
||||
storeDataForDb.glucoseValues.addAll(glucoseValues)
|
||||
}
|
||||
storeDataForDb.glucoseValues.addAll(glucoseValues)
|
||||
return latestDateInReceivedData > 0
|
||||
}
|
||||
|
||||
fun processTreatments(treatments: List<NSTreatment>) {
|
||||
/**
|
||||
* Preprocess list of treatments
|
||||
*
|
||||
* @return true if there was an accepted treatment
|
||||
*/
|
||||
fun processTreatments(treatments: List<NSTreatment>): Boolean {
|
||||
try {
|
||||
var latestDateInReceivedData: Long = 0
|
||||
for (treatment in treatments) {
|
||||
|
@ -189,11 +202,14 @@ class NsIncomingDataProcessor @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
activePlugin.activeNsClient?.updateLatestTreatmentReceivedIfNewer(latestDateInReceivedData)
|
||||
if (latestDateInReceivedData > 0)
|
||||
activePlugin.activeNsClient?.updateLatestTreatmentReceivedIfNewer(latestDateInReceivedData)
|
||||
return latestDateInReceivedData > 0
|
||||
} catch (error: Exception) {
|
||||
aapsLogger.error("Error: ", error)
|
||||
rxBus.send(EventNSClientNewLog("◄ ERROR", error.localizedMessage))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun processFood(data: Any) {
|
||||
|
|
|
@ -65,7 +65,7 @@ class LoadBgWorker(
|
|||
sp.putBoolean(app.aaps.core.utils.R.string.key_objectives_bg_is_available_in_ns, true)
|
||||
// Schedule processing of fetched data and continue of loading
|
||||
continueLoading = response.code != 304
|
||||
nsIncomingDataProcessor.processSgvs(sgvs)
|
||||
continueLoading = nsIncomingDataProcessor.processSgvs(sgvs)
|
||||
} else {
|
||||
// End first load
|
||||
if (isFirstLoad) {
|
||||
|
|
|
@ -58,8 +58,8 @@ class LoadTreatmentsWorker(
|
|||
val action = if (isFirstLoad) "RCV-F" else "RCV"
|
||||
rxBus.send(EventNSClientNewLog("◄ $action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||
// Schedule processing of fetched data and continue of loading
|
||||
continueLoading = response.code != 304
|
||||
nsIncomingDataProcessor.processTreatments(response.values)
|
||||
continueLoading =
|
||||
response.code != 304 && nsIncomingDataProcessor.processTreatments(response.values)
|
||||
} else {
|
||||
// End first load
|
||||
if (isFirstLoad) {
|
||||
|
|
Loading…
Reference in a new issue