Clean AndroidAPS started button

This commit is contained in:
Milos Kozak 2018-06-23 20:28:20 +02:00
parent 0d48cc8770
commit a4b3b7b2e9
3 changed files with 60 additions and 16 deletions

View file

@ -107,16 +107,14 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.gs(R.string.confirmation)); builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(careportalEvent.date)); builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(careportalEvent.date));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
public void onClick(DialogInterface dialog, int id) { final String _id = careportalEvent._id;
final String _id = careportalEvent._id; if (NSUpload.isIdValid(_id)) {
if (NSUpload.isIdValid(_id)) { NSUpload.removeCareportalEntryFromNS(_id);
NSUpload.removeCareportalEntryFromNS(_id); } else {
} else { UploadQueue.removeID("dbAdd", _id);
UploadQueue.removeID("dbAdd", _id);
}
MainApp.getDbHelper().delete(careportalEvent);
} }
MainApp.getDbHelper().delete(careportalEvent);
}); });
builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show(); builder.show();
@ -142,6 +140,8 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout); refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout);
refreshFromNS.setOnClickListener(this); refreshFromNS.setOnClickListener(this);
view.findViewById(R.id.careportal_removeandroidapsstartedevents).setOnClickListener(this);
context = getContext(); context = getContext();
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false); 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.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show(); builder.show();
break; 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<CareportalEvent> 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);
}
}
}
} }

View file

@ -9,13 +9,30 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<Button <LinearLayout
android:id="@+id/careportal_refreshfromnightscout" android:layout_width="match_parent"
style="?android:attr/buttonStyle" android:layout_height="match_parent"
android:layout_width="wrap_content" android:orientation="horizontal">
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" <Button
android:text="@string/refresheventsfromnightscout" /> android:id="@+id/careportal_refreshfromnightscout"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/refresheventsfromnightscout" />
<Button
android:id="@+id/careportal_removeandroidapsstartedevents"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/careportal_removestartedevents" />
</LinearLayout>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/careportal_recyclerview" android:id="@+id/careportal_recyclerview"

View file

@ -1172,6 +1172,7 @@
<string name="combo_invalid_setup">Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software.</string> <string name="combo_invalid_setup">Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software.</string>
<string name="custom">Custom</string> <string name="custom">Custom</string>
<string name="key_lockscreen" translatable="false">lockscreen</string> <string name="key_lockscreen" translatable="false">lockscreen</string>
<string name="careportal_removestartedevents">Clean AndroidAPS started</string>
<plurals name="objective_days"> <plurals name="objective_days">
<item quantity="one">%d day</item> <item quantity="one">%d day</item>