Insight get rid of Date.class
This commit is contained in:
parent
57e7d63794
commit
dd90051b97
2 changed files with 35 additions and 38 deletions
|
@ -34,8 +34,8 @@ class HistoryIntentAdapter {
|
|||
|
||||
private HistoryLogAdapter logAdapter = new HistoryLogAdapter();
|
||||
|
||||
private static Date getDateExtra(Intent intent, String name) {
|
||||
return (Date) intent.getSerializableExtra(name);
|
||||
private static long getDateExtra(Intent intent, String name) {
|
||||
return ((Date) intent.getSerializableExtra(name)).getTime();
|
||||
}
|
||||
|
||||
static long getRecordUniqueID(long pump_serial_number, long pump_record_id) {
|
||||
|
@ -52,8 +52,7 @@ class HistoryIntentAdapter {
|
|||
pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
|
||||
}
|
||||
final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
|
||||
final Date event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
final Date start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
|
||||
final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
|
||||
|
||||
if ((pump_tbr_duration == -1) || (pump_tbr_percent == -1) || (pump_record_id == -1)) {
|
||||
log.error("Invalid TBR record!!!");
|
||||
|
@ -76,8 +75,8 @@ class HistoryIntentAdapter {
|
|||
pump_record_id = intent.getIntExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
|
||||
}
|
||||
final long pump_serial_number = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
|
||||
final Date event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
final Date start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
|
||||
final long event_time = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
final long start_time = getDateExtra(intent, HistoryBroadcast.EXTRA_START_TIME);
|
||||
final double immediate_amount = intent.getDoubleExtra(HistoryBroadcast.EXTRA_IMMEDIATE_AMOUNT, -1);
|
||||
final double extended_insulin = intent.getDoubleExtra(HistoryBroadcast.EXTRA_EXTENDED_AMOUNT, -1);
|
||||
final int extended_minutes = intent.getIntExtra(HistoryBroadcast.EXTRA_DURATION, -1);
|
||||
|
@ -90,7 +89,7 @@ class HistoryIntentAdapter {
|
|||
log.error("ERROR Standard bolus fails sanity check");
|
||||
return;
|
||||
}
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U ", event_time.getTime());
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U ", event_time);
|
||||
logAdapter.createStandardBolusRecord(start_time, immediate_amount, record_unique_id);
|
||||
break;
|
||||
|
||||
|
@ -99,7 +98,7 @@ class HistoryIntentAdapter {
|
|||
log.error("ERROR: Extended bolus fails sanity check");
|
||||
return;
|
||||
}
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + extended_insulin + "U over " + extended_minutes + " min, ", event_time.getTime());
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + extended_insulin + "U over " + extended_minutes + " min, ", event_time);
|
||||
logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id);
|
||||
break;
|
||||
|
||||
|
@ -108,7 +107,7 @@ class HistoryIntentAdapter {
|
|||
log.error("ERROR: Multiwave bolus fails sanity check");
|
||||
return;
|
||||
}
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U + " + extended_insulin + "U over " + extended_minutes + " min, ", event_time.getTime());
|
||||
LiveHistory.setStatus(bolus_type + " BOLUS\n" + immediate_amount + "U + " + extended_insulin + "U over " + extended_minutes + " min, ", event_time);
|
||||
logAdapter.createStandardBolusRecord(start_time, immediate_amount, pump_serial_number + pump_record_id);
|
||||
logAdapter.createExtendedBolusRecord(start_time, extended_insulin, extended_minutes, record_unique_id);
|
||||
break;
|
||||
|
@ -118,31 +117,31 @@ class HistoryIntentAdapter {
|
|||
}
|
||||
|
||||
void processDailyTotalIntent(Intent intent) {
|
||||
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_TOTAL_DATE);
|
||||
long date = getDateExtra(intent, HistoryBroadcast.EXTRA_TOTAL_DATE);
|
||||
double basal = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BASAL_TOTAL, 0D);
|
||||
double bolus = intent.getDoubleExtra(HistoryBroadcast.EXTRA_BOLUS_TOTAL, 0D);
|
||||
TDD tdd = new TDD(date.getTime(), bolus, basal, bolus + basal);
|
||||
TDD tdd = new TDD(date, bolus, basal, bolus + basal);
|
||||
MainApp.getDbHelper().createOrUpdateTDD(tdd);
|
||||
}
|
||||
|
||||
void processCannulaFilledIntent(Intent intent) {
|
||||
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
uploadCareportalEvent(date, CareportalEvent.SITECHANGE);
|
||||
}
|
||||
|
||||
void processCartridgeInsertedIntent(Intent intent) {
|
||||
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
uploadCareportalEvent(date, CareportalEvent.INSULINCHANGE);
|
||||
}
|
||||
|
||||
void processBatteryInsertedIntent(Intent intent) {
|
||||
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
uploadCareportalEvent(date, CareportalEvent.PUMPBATTERYCHANGE);
|
||||
}
|
||||
|
||||
private void uploadCareportalEvent(Date date, String event) {
|
||||
private void uploadCareportalEvent(long date, String event) {
|
||||
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null)
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
|
||||
return;
|
||||
try {
|
||||
JSONObject data = new JSONObject();
|
||||
|
@ -159,18 +158,18 @@ class HistoryIntentAdapter {
|
|||
|
||||
void processOccurenceOfAlertIntent(Intent intent) {
|
||||
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
|
||||
Date date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
long date = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
String alertType = intent.getStringExtra(HistoryBroadcast.EXTRA_ALERT_TYPE);
|
||||
int alertText = getAlertText(alertType);
|
||||
if (alertText == 0) return;
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null)
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
|
||||
return;
|
||||
logNote(date, MainApp.gs(alertText));
|
||||
}
|
||||
}
|
||||
|
||||
void processPumpStatusChangedIntent(Intent intent) {
|
||||
Date newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
long newStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_EVENT_TIME);
|
||||
if (SP.getBoolean("insight_automatic_careportal_events", false)) {
|
||||
String newStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_NEW_STATUS);
|
||||
switch (newStatus) {
|
||||
|
@ -188,8 +187,8 @@ class HistoryIntentAdapter {
|
|||
if (intent.hasExtra(HistoryBroadcast.EXTRA_OLD_STATUS_TIME)) {
|
||||
String oldStatus = intent.getStringExtra(HistoryBroadcast.EXTRA_OLD_STATUS);
|
||||
if (oldStatus.equals("STOPPED")) {
|
||||
Date oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME);
|
||||
int duration = (int) ((newStatusTime.getTime() - oldStatusTime.getTime()) / 60000);
|
||||
long oldStatusTime = getDateExtra(intent, HistoryBroadcast.EXTRA_OLD_STATUS_TIME);
|
||||
int duration = (int) ((newStatusTime - oldStatusTime) / 60000);
|
||||
|
||||
long serialNumber = Long.parseLong(intent.getStringExtra(HistoryBroadcast.EXTRA_PUMP_SERIAL_NUMBER));
|
||||
long recordId = intent.getLongExtra(HistoryBroadcast.EXTRA_EVENT_NUMBER, -1);
|
||||
|
@ -200,9 +199,9 @@ class HistoryIntentAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
private void logNote(Date date, String note) {
|
||||
private void logNote(long date, String note) {
|
||||
try {
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date.getTime()) != null)
|
||||
if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
|
||||
return;
|
||||
JSONObject data = new JSONObject();
|
||||
String enteredBy = SP.getString("careportal_enteredby", "");
|
||||
|
|
|
@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.PumpInsight.history;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
|
@ -29,11 +27,11 @@ class HistoryLogAdapter {
|
|||
|
||||
private static final long MAX_TIME_DIFFERENCE = T.secs(61).msecs();
|
||||
|
||||
void createTBRrecord(Date eventDate, int percent, int duration, long record_id) {
|
||||
void createTBRrecord(long eventDate, int percent, int duration, long record_id) {
|
||||
|
||||
TemporaryBasal temporaryBasal = new TemporaryBasal().date(eventDate.getTime());
|
||||
TemporaryBasal temporaryBasal = new TemporaryBasal().date(eventDate);
|
||||
|
||||
final TemporaryBasal temporaryBasalFromHistory = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(eventDate.getTime());
|
||||
final TemporaryBasal temporaryBasalFromHistory = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(eventDate);
|
||||
|
||||
if (temporaryBasalFromHistory == null) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
|
@ -41,7 +39,7 @@ class HistoryLogAdapter {
|
|||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Loaded existing TBR record: " + temporaryBasalFromHistory.toString());
|
||||
if (Math.abs(eventDate.getTime() - temporaryBasalFromHistory.date) < MAX_TIME_DIFFERENCE) {
|
||||
if (Math.abs(eventDate - temporaryBasalFromHistory.date) < MAX_TIME_DIFFERENCE) {
|
||||
if (temporaryBasalFromHistory.source != Source.PUMP) {
|
||||
if (temporaryBasalFromHistory.percentRate == percent) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
|
@ -64,7 +62,7 @@ class HistoryLogAdapter {
|
|||
}
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Time difference too big! : " + (eventDate.getTime() - temporaryBasalFromHistory.date));
|
||||
log.debug("Time difference too big! : " + (eventDate - temporaryBasalFromHistory.date));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,9 +74,9 @@ class HistoryLogAdapter {
|
|||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
|
||||
}
|
||||
|
||||
void createExtendedBolusRecord(Date eventDate, double insulin, int durationInMinutes, long record_id) {
|
||||
void createExtendedBolusRecord(long eventDate, double insulin, int durationInMinutes, long record_id) {
|
||||
|
||||
final ExtendedBolus extendedBolusFromHistory = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(eventDate.getTime());
|
||||
final ExtendedBolus extendedBolusFromHistory = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(eventDate);
|
||||
|
||||
if (extendedBolusFromHistory == null) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
|
@ -86,10 +84,10 @@ class HistoryLogAdapter {
|
|||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Loaded existing EB record: " + extendedBolusFromHistory.toString());
|
||||
if (Math.abs(eventDate.getTime() - extendedBolusFromHistory.date) < MAX_TIME_DIFFERENCE) {
|
||||
if (Math.abs(eventDate - extendedBolusFromHistory.date) < MAX_TIME_DIFFERENCE) {
|
||||
if (extendedBolusFromHistory.source != Source.PUMP) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Date seem to match: " + DateUtil.dateAndTimeFullString(eventDate.getTime()));
|
||||
log.debug("Date seem to match: " + DateUtil.dateAndTimeFullString(eventDate));
|
||||
String _id = extendedBolusFromHistory._id;
|
||||
if (NSUpload.isIdValid(_id)) {
|
||||
NSUpload.removeCareportalEntryFromNS(_id);
|
||||
|
@ -103,7 +101,7 @@ class HistoryLogAdapter {
|
|||
}
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Time difference too big! : " + (eventDate.getTime() - extendedBolusFromHistory.date));
|
||||
log.debug("Time difference too big! : " + (eventDate - extendedBolusFromHistory.date));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +110,7 @@ class HistoryLogAdapter {
|
|||
// TODO (mike) find and remove ending record with Source.USER
|
||||
|
||||
ExtendedBolus extendedBolus = new ExtendedBolus()
|
||||
.date(eventDate.getTime())
|
||||
.date(eventDate)
|
||||
.insulin(insulin)
|
||||
.durationInMinutes(durationInMinutes)
|
||||
.source(Source.PUMP)
|
||||
|
@ -122,14 +120,14 @@ class HistoryLogAdapter {
|
|||
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
||||
}
|
||||
|
||||
void createStandardBolusRecord(Date eventDate, double insulin, long record_id) {
|
||||
void createStandardBolusRecord(long eventDate, double insulin, long record_id) {
|
||||
|
||||
//DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(eventDate.getTime());
|
||||
|
||||
// TODO do we need to do the same delete + insert that we are doing for temporary basals here too?
|
||||
|
||||
final DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.date = eventDate.getTime();
|
||||
detailedBolusInfo.date = eventDate;
|
||||
detailedBolusInfo.source = Source.PUMP;
|
||||
detailedBolusInfo.pumpId = record_id;
|
||||
detailedBolusInfo.insulin = insulin;
|
||||
|
|
Loading…
Reference in a new issue