This commit is contained in:
Milos Kozak 2022-12-11 12:57:19 +01:00
parent 80dd3b094b
commit 02c1bd1e52

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump
import info.nightscout.core.utils.DateTimeUtil import info.nightscout.core.utils.DateTimeUtil
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import java.util.Collections
/** /**
* History page contains data, sorted from newest to oldest (0=newest..n=oldest) * History page contains data, sorted from newest to oldest (0=newest..n=oldest)
@ -18,19 +17,19 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
private val searchEntry: PumpHistoryEntry? = null private val searchEntry: PumpHistoryEntry? = null
private var searchDate: Long? = null private var searchDate: Long? = null
private var searchType = SearchType.None private var searchType = SearchType.None
var unprocessedEntries: List<PumpHistoryEntry> = ArrayList() var unprocessedEntries: MutableList<PumpHistoryEntry> = ArrayList()
var validEntries: MutableList<PumpHistoryEntry> = ArrayList() var validEntries: MutableList<PumpHistoryEntry> = ArrayList()
fun addHistoryEntries(entries: List<PumpHistoryEntry> /*, page: Int*/) { fun addHistoryEntries(entries: MutableList<PumpHistoryEntry> /*, page: Int*/) {
unprocessedEntries = entries unprocessedEntries = entries
//aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries)); //aapsLogger.debug(LTag.PUMPCOMM,"PumpHistoryResult. Unprocessed entries: {}", MedtronicUtil.getGsonInstance().toJson(entries));
processEntries() processEntries()
} }
// TODO Bug #145 need to check if we had timeChange that went -1, that situation needs to be evaluated separately // TODO Bug #145 need to check if we had timeChange that went -1, that situation needs to be evaluated separately
fun processEntries() { private fun processEntries() {
var olderEntries = 0 var olderEntries = 0
Collections.reverse(unprocessedEntries) unprocessedEntries.reverse()
when (searchType) { when (searchType) {
SearchType.None -> //aapsLogger.debug(LTag.PUMPCOMM,"PE. None search"); SearchType.None -> //aapsLogger.debug(LTag.PUMPCOMM,"PE. None search");
validEntries.addAll(unprocessedEntries) validEntries.addAll(unprocessedEntries)
@ -42,7 +41,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime) aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: " + searchEntry!!.atechDateTime)
//val date = searchEntry.atechDateTime //val date = searchEntry.atechDateTime
for (unprocessedEntry in unprocessedEntries) { for (unprocessedEntry in unprocessedEntries) {
if (unprocessedEntry.equals(searchEntry)) { if (unprocessedEntry == searchEntry) {
//aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry); //aapsLogger.debug(LTag.PUMPCOMM,"PE. Item found {}.", unprocessedEntry);
isSearchFinished = true isSearchFinished = true
break break
@ -56,7 +55,7 @@ class PumpHistoryResult(private val aapsLogger: AAPSLogger, searchEntry: PumpHis
} }
SearchType.Date -> { SearchType.Date -> {
aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: " + searchDate) aapsLogger.debug(LTag.PUMPCOMM, "PE. Date search: Search date: $searchDate")
for (unprocessedEntry in unprocessedEntries) { for (unprocessedEntry in unprocessedEntries) {
if (unprocessedEntry.atechDateTime == 0L) { if (unprocessedEntry.atechDateTime == 0L) {
aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: Entry with no date: $unprocessedEntry") aapsLogger.debug(LTag.PUMPCOMM, "PE. PumpHistoryResult. Search entry date: Entry with no date: $unprocessedEntry")