Skip to content

Commit 763be9e

Browse files
committed
2 parents fa77acd + 340dce4 commit 763be9e

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/PhoneKeypadInputActivity.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.widget.LinearLayout;
1414
import android.widget.TextView;
1515

16+
import com.eveningoutpost.dexdrip.models.JoH;
1617
import com.eveningoutpost.dexdrip.utilitymodels.PersistentStore;
1718
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
1819
import com.eveningoutpost.dexdrip.insulin.Insulin;
@@ -370,29 +371,32 @@ private void submitAll() {
370371

371372
// The green tick is clickable even when it's hidden, so we might get here
372373
// without valid data. Ignore the click if input is incomplete
373-
if(!nonzeroBloodValue && !nonzeroCarbsValue && !nonzeroInsulin1Value && !nonzeroInsulin2Value && !nonzeroInsulin3Value) {
374+
if (!nonzeroBloodValue && !nonzeroCarbsValue && !nonzeroInsulin1Value && !nonzeroInsulin2Value && !nonzeroInsulin3Value) {
374375
Log.d(TAG, "All zero values in tabs - not processing button click");
375376
return;
376377
}
377378

378379
if (isInvalidTime()) {
379-
Log.d(TAG,"Time value is invalid - not processing button click");
380+
Log.d(TAG, "Time value is invalid - not processing button click");
380381
return;
381382
}
382383

383384

384385
// Add the dot to the time if it is missing
385386
String timeValue = getValue("time");
386387
if (timeValue.length() > 2 && !timeValue.contains(".")) {
387-
timeValue = timeValue.substring(0, timeValue.length()-2) + "." + timeValue.substring(timeValue.length()-2);
388+
timeValue = timeValue.substring(0, timeValue.length() - 2) + "." + timeValue.substring(timeValue.length() - 2);
388389
}
389390

390391
String mystring = "";
391392
double units = 0;
392393
final DecimalFormat df = new DecimalFormat("0.0#", new DecimalFormatSymbols(Locale.ENGLISH));
393394
if (timeValue.length() > 0) mystring += timeValue + " time ";
394395
if (nonzeroBloodValue) mystring += getValue("bloodtest") + " blood ";
395-
if (nonzeroCarbsValue) mystring += getValue("carbs") + " g carbs ";
396+
if (nonzeroCarbsValue) {
397+
String carbValue = String.valueOf(JoH.roundDouble(JoH.tolerantParseDouble(getValue("carbs")), 2)); // Let's round the entered carb value to 2 decimal points
398+
mystring += carbValue + " g carbs ";
399+
}
396400
if (nonzeroInsulin1Value && (insulinProfile1 != null))
397401
{
398402
double d = Double.parseDouble(getValue("insulin-1"));

app/src/main/java/com/eveningoutpost/dexdrip/models/Treatments.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.activeandroid.util.SQLiteUtils;
1919
import com.eveningoutpost.dexdrip.GcmActivity;
2020
import com.eveningoutpost.dexdrip.Home;
21+
import com.eveningoutpost.dexdrip.g5model.DexSessionKeeper;
2122
import com.eveningoutpost.dexdrip.models.UserError.Log;
2223
import com.eveningoutpost.dexdrip.R;
2324
import com.eveningoutpost.dexdrip.services.SyncService;
@@ -58,7 +59,6 @@
5859
import static com.eveningoutpost.dexdrip.models.JoH.msSince;
5960
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.HOUR_IN_MS;
6061
import static com.eveningoutpost.dexdrip.utilitymodels.Constants.MINUTE_IN_MS;
61-
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
6262
import static java.lang.StrictMath.abs;
6363
import static com.eveningoutpost.dexdrip.models.JoH.emptyString;
6464

@@ -449,6 +449,15 @@ public static void sensorStartIfNeeded() {
449449
}
450450
}
451451

452+
public static void sensorUpdateStartTimeIfNeeded() {
453+
val lastSensorStart = Treatments.lastEventTypeFromXdrip(Treatments.SENSOR_START_EVENT_TYPE);
454+
long localStartedAt = lastSensorStart.timestamp; // When the xDrip local session started
455+
long dexStartedAt = DexSessionKeeper.getStart(); // When the current session on the transmitter started
456+
if (dexStartedAt > 0 && !(dexStartedAt - localStartedAt < MINUTE_IN_MS * 5)) { // If the start time of the local session is more than 5 minutes older than the one on the transmitter
457+
Treatments.sensorStart(dexStartedAt, "Start time updated");
458+
}
459+
}
460+
452461
private static void pushTreatmentSync(Treatments treatment) {
453462
pushTreatmentSync(treatment, true, null); // new entry by default
454463
}

app/src/main/java/com/eveningoutpost/dexdrip/services/Ob1G5CollectionService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,10 @@ public static void processCalibrationState(final CalibrationState state) {
19981998
updateG5State(needs_calibration, was_needing_calibration, NEEDING_CALIBRATION);
19991999
updateG5State(is_started, was_started, IS_STARTED);
20002000
updateG5State(is_failed, was_failed, IS_FAILED);
2001+
2002+
if (is_started && shortTxId() && JoH.pratelimit("update_alternate_dex_session_start_time", 60 * 60)) { // Once an hour if there is a local session
2003+
Treatments.sensorUpdateStartTimeIfNeeded();
2004+
}
20012005
}
20022006

20032007

0 commit comments

Comments
 (0)