diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java index 4fa9cd784e..7e69883a3d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsCareportalFragment.java @@ -107,16 +107,14 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.gs(R.string.confirmation)); builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(careportalEvent.date)); - builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - final String _id = careportalEvent._id; - if (NSUpload.isIdValid(_id)) { - NSUpload.removeCareportalEntryFromNS(_id); - } else { - UploadQueue.removeID("dbAdd", _id); - } - MainApp.getDbHelper().delete(careportalEvent); + builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { + final String _id = careportalEvent._id; + if (NSUpload.isIdValid(_id)) { + NSUpload.removeCareportalEntryFromNS(_id); + } else { + UploadQueue.removeID("dbAdd", _id); } + MainApp.getDbHelper().delete(careportalEvent); }); builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); @@ -142,6 +140,8 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout); refreshFromNS.setOnClickListener(this); + view.findViewById(R.id.careportal_removeandroidapsstartedevents).setOnClickListener(this); + context = getContext(); boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); @@ -169,6 +169,16 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); break; + case R.id.careportal_removeandroidapsstartedevents: + builder = new AlertDialog.Builder(context); + builder.setTitle(MainApp.gs(R.string.confirmation)); + builder.setMessage(MainApp.gs(R.string.careportal_removestartedevents)); + builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { + removeAndroidAPSStatedEvents(); + }); + builder.setNegativeButton(MainApp.gs(R.string.cancel), null); + builder.show(); + break; } } @@ -189,4 +199,20 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements } }); } + + private void removeAndroidAPSStatedEvents() { + List events = MainApp.getDbHelper().getCareportalEvents(false); + for (int i = 0; i < events.size(); i++) { + CareportalEvent careportalEvent = events.get(i); + if (careportalEvent.json.contains(MainApp.gs(R.string.androidaps_start))) { + final String _id = careportalEvent._id; + if (NSUpload.isIdValid(_id)) { + NSUpload.removeCareportalEntryFromNS(_id); + } else { + UploadQueue.removeID("dbAdd", _id); + } + MainApp.getDbHelper().delete(careportalEvent); + } + } + } } diff --git a/app/src/main/res/layout/treatments_careportal_fragment.xml b/app/src/main/res/layout/treatments_careportal_fragment.xml index 710afed7bb..367521d40c 100644 --- a/app/src/main/res/layout/treatments_careportal_fragment.xml +++ b/app/src/main/res/layout/treatments_careportal_fragment.xml @@ -9,13 +9,30 @@ android:layout_height="match_parent" android:orientation="vertical"> -