@@ -35,7 +39,7 @@ import java.net.InetAddress;
*
*/
public class SntpClient {
- private static final String TAG = "SntpClient";
+ private static Logger log = LoggerFactory.getLogger(L.CORE);
//private static final int REFERENCE_TIME_OFFSET = 16;
private static final int ORIGINATE_TIME_OFFSET = 24;
@@ -76,8 +80,10 @@ public class SntpClient {
}
static void doNtpTime(final Callback callback) {
+ log.debug("Time detection started");
callback.success = requestTime("time.google.com", 5000);
callback.time = getNtpTime() + SystemClock.elapsedRealtime() - getNtpTimeReference();
+ log.debug("Time detection ended: " + callback.success + " " + DateUtil.dateAndTimeString(getNtpTime()));
callback.run();
}
@@ -138,7 +144,7 @@ public class SntpClient {
mNtpTimeReference = responseTicks;
mRoundTripTime = roundTripTime;
} catch (Exception e) {
- Log.d(TAG, "request time failed: " + e);
+ log.debug("request time failed: " + e);
return false;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TIR.kt b/app/src/main/java/info/nightscout/androidaps/utils/TIR.kt
new file mode 100644
index 0000000000..5f2ea9bbaf
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/TIR.kt
@@ -0,0 +1,26 @@
+package info.nightscout.androidaps.utils
+
+import info.nightscout.androidaps.MainApp
+import info.nightscout.androidaps.R
+import kotlin.math.roundToInt
+
+class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
+ internal var below = 0
+ internal var inRange = 0
+ internal var above = 0
+ internal var error = 0
+ internal var count = 0
+
+ fun error() = run { error++ }
+ fun below() = run { below++; count++ }
+ fun inRange() = run { inRange++; count++ }
+ fun above() = run { above++; count++ }
+
+ fun belowPct() = if (count > 0) (below.toDouble() / count * 100.0).roundToInt() else 0
+ fun inRangePct() = if (count > 0) (inRange.toDouble() / count * 100.0).roundToInt() else 0
+ fun abovePct() = if (count > 0) (above.toDouble() / count * 100.0).roundToInt() else 0
+
+ fun toText(): String = MainApp.gs(R.string.tirformat, DateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())
+
+ fun toText(days: Int): String = MainApp.gs(R.string.tirformat, "%02d".format(days) + " " + MainApp.gs(R.string.days), belowPct(), inRangePct(), abovePct())
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt
new file mode 100644
index 0000000000..0210247eb3
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt
@@ -0,0 +1,81 @@
+package info.nightscout.androidaps.utils
+
+import android.text.Spanned
+import android.util.LongSparseArray
+import info.nightscout.androidaps.MainApp
+import info.nightscout.androidaps.R
+import info.nightscout.androidaps.db.TDD
+import info.nightscout.androidaps.logging.L
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
+import org.slf4j.LoggerFactory
+
+object TddCalculator : TreatmentsPlugin() {
+ private val log = LoggerFactory.getLogger(L.DATATREATMENTS)
+
+ fun calculate(days: Long): LongSparseArray
" +
+ toText(tdds) +
+ "" + MainApp.gs(R.string.average) + ":
" +
+ averageTdd.toText(tdds.size())
+ )
+ }
+
+ fun toText(tdds: LongSparseArray
"
+ }
+ return t
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java
index be8b89dff4..0143377bb2 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java
+++ b/app/src/main/java/info/nightscout/androidaps/utils/TimeListEdit.java
@@ -50,6 +50,7 @@ public class TimeListEdit {
private Context context;
private View view;
private int resLayoutId;
+ private String tagPrefix;
private String label;
private JSONArray data1;
private JSONArray data2;
@@ -63,10 +64,11 @@ public class TimeListEdit {
private int inflatedUntil = -1;
- public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) {
+ public TimeListEdit(Context context, View view, int resLayoutId, String tagPrefix, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) {
this.context = context;
this.view = view;
this.resLayoutId = resLayoutId;
+ this.tagPrefix = tagPrefix;
this.label = label;
this.data1 = data1;
this.data2 = data2;
@@ -84,11 +86,11 @@ public class TimeListEdit {
textlabel = new TextView(context);
textlabel.setText(label);
- textlabel.setGravity(Gravity.START);
+ textlabel.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
- llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
+ llp.setMargins(0, 5, 0, 5);
textlabel.setLayoutParams(llp);
- textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
+ //textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
layout.addView(textlabel);
@@ -119,7 +121,8 @@ public class TimeListEdit {
private void inflateRow(final int position) {
LayoutInflater inflater = LayoutInflater.from(context);
- View childView = intervals[position] = inflater.inflate(R.layout.timelistedit_element, layout, false);
+ int resource = data2 == null ? R.layout.timelistedit_element : R.layout.timelistedit_element_vertical;
+ View childView = intervals[position] = inflater.inflate(resource, layout, false);
spinners[position] = new SpinnerHelper(childView.findViewById(R.id.timelistedit_time));
numberPickers1[position] = childView.findViewById(R.id.timelistedit_edit1);
numberPickers2[position] = childView.findViewById(R.id.timelistedit_edit2);
@@ -184,7 +187,7 @@ public class TimeListEdit {
int before, int count) {
}
});
-
+ numberPickers1[position].setTag(tagPrefix +"-1-" + position);
numberPickers2[position].setTextWatcher(new TextWatcher() {
@Override
@@ -204,6 +207,7 @@ public class TimeListEdit {
int before, int count) {
}
});
+ numberPickers2[position].setTag(tagPrefix +"-2-" + position);
layout.addView(childView);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt
new file mode 100644
index 0000000000..4e41f9a331
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt
@@ -0,0 +1,85 @@
+package info.nightscout.androidaps.utils
+
+import android.text.Spanned
+import android.util.LongSparseArray
+import info.nightscout.androidaps.Constants
+import info.nightscout.androidaps.MainApp
+import info.nightscout.androidaps.R
+import info.nightscout.androidaps.data.Profile
+
+object TirCalculator {
+ fun calculate(days: Long, lowMgdl: Double, highMgdl: Double): LongSparseArray
" + MainApp.gs(R.string.tir) + ":
" +
+ toText(tir7) +
+ "
" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):
" +
+ averageTir7.toText(tir7.size()) + "
" +
+ averageTir30.toText(tir30.size()) +
+ "
" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):
" +
+ averageTit7.toText(tit7.size()) + "
" +
+ averageTit30.toText(tit30.size())
+ )
+ }
+
+ fun toText(tirs: LongSparseArray
"
+ }
+ return t
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/UIUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/UIUtils.kt
new file mode 100644
index 0000000000..99c4a4af31
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/UIUtils.kt
@@ -0,0 +1,10 @@
+package info.nightscout.androidaps.utils
+
+import android.view.View
+
+/**
+ * Created by adrian on 2019-12-20.
+ */
+
+fun Boolean.toVisibility() = if (this) View.VISIBLE else View.GONE
+
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java
index f7b8761823..4354ccd528 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java
+++ b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java
@@ -1,11 +1,9 @@
package info.nightscout.androidaps.utils;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
-import androidx.appcompat.app.AlertDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -25,20 +23,10 @@ import info.nightscout.androidaps.services.Intents;
public class XdripCalibrations {
private static Logger log = LoggerFactory.getLogger(XdripCalibrations.class);
- public static void confirmAndSendCalibration(final Double bg, Context parentContext) {
+ public static void confirmAndSendCalibration(final Double bg, final Context parentContext) {
if (parentContext != null) {
String confirmMessage = String.format(MainApp.gs(R.string.send_calibration), bg);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
- builder.setTitle(MainApp.gs(R.string.confirmation));
- builder.setMessage(confirmMessage);
- builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- sendIntent(bg);
- }
- });
- builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
- builder.show();
+ OKDialog.showConfirmation(parentContext, confirmMessage, () -> sendIntent(bg));
}
}
@@ -46,7 +34,7 @@ public class XdripCalibrations {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putDouble("glucose_number", bg);
- bundle.putString("units", ProfileFunctions.getInstance().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
+ bundle.putString("units", ProfileFunctions.getSystemUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
bundle.putLong("timestamp", System.currentTimeMillis());
Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
intent.putExtras(bundle);
diff --git a/app/src/main/res/drawable/clone.png b/app/src/main/res/drawable/clone.png
new file mode 100644
index 0000000000..82fd90cca8
Binary files /dev/null and b/app/src/main/res/drawable/clone.png differ
diff --git a/app/src/main/res/drawable/ic_action_orange_48dp.xml b/app/src/main/res/drawable/ic_action_orange_48dp.xml
new file mode 100644
index 0000000000..07e8c306a8
--- /dev/null
+++ b/app/src/main/res/drawable/ic_action_orange_48dp.xml
@@ -0,0 +1,5 @@
+