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