diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 84abf74ef2..29b70eb1e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -377,7 +377,6 @@ public class DataService extends IntentService { } Treatment stored = null; - trJson = new JSONObject(trstring); String _id = trJson.getString("_id"); if (trJson.has("timeIndex")) { @@ -405,6 +404,11 @@ public class DataService extends IntentService { treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0; treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d; treatment.created_at = new Date(trJson.getLong("mills")); + if (trJson.has("eventType")) { + treatment.mealBolus = true; + if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false; + if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false; + } treatment.setTimeIndex(treatment.getTimeIndex()); try { MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment); @@ -450,6 +454,11 @@ public class DataService extends IntentService { treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d; //treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at")); treatment.created_at = new Date(trJson.getLong("mills")); + if (trJson.has("eventType")) { + treatment.mealBolus = true; + if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false; + if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false; + } treatment.setTimeIndex(treatment.getTimeIndex()); try { Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().getDaoTreatments().createOrUpdate(treatment); diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 0f2115c239..e929cb56e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -40,7 +40,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static final String DATABASE_TREATMENTS = "Treatments"; public static final String DATABASE_DANARHISTORY = "DanaRHistory"; - private static final int DATABASE_VERSION = 3; + private static final int DATABASE_VERSION = 4; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java index 1bfaa37aeb..3c08789f80 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -47,11 +47,15 @@ public class Treatment implements DataPointWithLabelInterface { @DatabaseField public Double carbs = 0d; + @DatabaseField + public boolean mealBolus = true; // true for meal bolus , false for correction bolus + public void copyFrom(Treatment t) { this._id = t._id; this.created_at = t.created_at; this.insulin = t.insulin; this.carbs = t.carbs; + this.mealBolus = t.mealBolus; } public Iob iobCalc(Date time, Double dia) { @@ -90,6 +94,7 @@ public class Treatment implements DataPointWithLabelInterface { ", _id: " + _id + ", insulin: " + insulin + ", carbs: " + carbs + + ", mealBolus: " + mealBolus + ", created_at: " + "}"; } @@ -112,7 +117,8 @@ public class Treatment implements DataPointWithLabelInterface { public String getLabel() { String label = ""; if (insulin > 0) label += DecimalFormatter.to2Decimal(insulin) + "U"; - if (carbs > 0) label += (label.equals("") ? "" : " ") + DecimalFormatter.to0Decimal(carbs) + "g"; + if (carbs > 0) + label += (label.equals("") ? "" : " ") + DecimalFormatter.to0Decimal(carbs) + "g"; return label; } @@ -130,7 +136,10 @@ public class Treatment implements DataPointWithLabelInterface { public void sendToNSClient() { JSONObject data = new JSONObject(); try { - data.put("eventType", "Meal Bolus"); + if (mealBolus) + data.put("eventType", "Meal Bolus"); + else + data.put("eventType", "Correction Bolus"); if (insulin != 0d) data.put("insulin", insulin); if (carbs != 0d) data.put("carbs", carbs.intValue()); data.put("created_at", DateUtil.toISOString(created_at)); @@ -141,4 +150,4 @@ public class Treatment implements DataPointWithLabelInterface { ConfigBuilderPlugin.uploadCareportalEntryToNS(data); } - } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 21471bc332..d052d80d02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -372,6 +372,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (carbTime == 0) t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout t.created_at = new Date(); + t.mealBolus = result.carbsDelivered > 0; try { MainApp.getDbHelper().getDaoTreatments().create(t); } catch (SQLException e) { @@ -419,6 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain t.insulin = result.bolusDelivered; t.carbs = (double) result.carbsDelivered; t.created_at = new Date(); + t.mealBolus = t.carbs > 0; try { MainApp.getDbHelper().getDaoTreatments().create(t); } catch (SQLException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index 591ddc56e8..8021b40a1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -80,6 +80,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener Iob iob = treatments.get(position).iobCalc(new Date(), profile.getDia()); holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U"); holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U"); + holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous)); if (iob.iobContrib != 0) holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorAffectingIOB)); else @@ -103,6 +104,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener TextView carbs; TextView iob; TextView activity; + TextView mealOrCorrection; LinearLayout dateLinearLayout; TreatmentsViewHolder(View itemView) { @@ -113,6 +115,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener carbs = (TextView) itemView.findViewById(R.id.treatments_carbs); iob = (TextView) itemView.findViewById(R.id.treatments_iob); activity = (TextView) itemView.findViewById(R.id.treatments_activity); + mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection); dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout); } } @@ -184,6 +187,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener public void updateGUI() { Activity activity = getActivity(); + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + if (profile == null) + return; if (activity != null && recyclerView != null) activity.runOnUiThread(new Runnable() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index f88dd870a2..369ce9ddbb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -158,7 +158,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { if (treatment.carbs >= 1) { result.carbs += treatment.carbs; } - if (treatment.insulin >= 0.1) { + if (treatment.insulin >= 0.1 && treatment.mealBolus) { result.boluses += treatment.insulin; } } diff --git a/app/src/main/res/layout/treatments_item.xml b/app/src/main/res/layout/treatments_item.xml index 6e1dd28702..662069a5e3 100644 --- a/app/src/main/res/layout/treatments_item.xml +++ b/app/src/main/res/layout/treatments_item.xml @@ -37,11 +37,21 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="5dp" - android:text="1.1.2000 18:00" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/cardItemLabel" android:textStyle="bold" /> + + @@ -65,7 +75,6 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="30dp" - android:text="1.1 U" android:textStyle="bold" /> @@ -107,7 +115,6 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="30dp" - android:text="0.12 U" android:textStyle="bold" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65c0f728c5..0c749cfde3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -328,5 +328,7 @@ Add Edit Remove + Meal + Corr