Treatments tab: add button (if applicable) to delete future treatments.
This commit is contained in:
parent
5292e09535
commit
6002c747e6
|
@ -43,6 +43,8 @@ import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static info.nightscout.utils.DateUtil.now;
|
||||||
|
|
||||||
public class TreatmentsBolusFragment extends SubscriberFragment implements View.OnClickListener {
|
public class TreatmentsBolusFragment extends SubscriberFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
|
||||||
|
|
||||||
|
@ -52,6 +54,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
TextView iobTotal;
|
TextView iobTotal;
|
||||||
TextView activityTotal;
|
TextView activityTotal;
|
||||||
Button refreshFromNS;
|
Button refreshFromNS;
|
||||||
|
Button deleteFutureTreatments;
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
|
@ -89,7 +92,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
||||||
else
|
else
|
||||||
holder.iob.setTextColor(holder.carbs.getCurrentTextColor());
|
holder.iob.setTextColor(holder.carbs.getCurrentTextColor());
|
||||||
if (t.date > DateUtil.now())
|
if (t.date > now())
|
||||||
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorScheduled));
|
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorScheduled));
|
||||||
else
|
else
|
||||||
holder.date.setTextColor(holder.carbs.getCurrentTextColor());
|
holder.date.setTextColor(holder.carbs.getCurrentTextColor());
|
||||||
|
@ -189,6 +192,9 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
|
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
|
||||||
refreshFromNS.setOnClickListener(this);
|
refreshFromNS.setOnClickListener(this);
|
||||||
|
|
||||||
|
deleteFutureTreatments = (Button) view.findViewById(R.id.treatments_delete_future_treatments);
|
||||||
|
deleteFutureTreatments.setOnClickListener(this);
|
||||||
|
|
||||||
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
|
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
|
||||||
if (nsUploadOnly)
|
if (nsUploadOnly)
|
||||||
refreshFromNS.setVisibility(View.GONE);
|
refreshFromNS.setVisibility(View.GONE);
|
||||||
|
@ -201,17 +207,37 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
AlertDialog.Builder builder;
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.treatments_reshreshfromnightscout:
|
case R.id.treatments_reshreshfromnightscout:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
|
builder = new AlertDialog.Builder(this.getContext());
|
||||||
builder.setTitle(MainApp.gs(R.string.confirmation));
|
builder.setTitle(MainApp.gs(R.string.confirmation));
|
||||||
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
|
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
|
||||||
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) {
|
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
||||||
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
});
|
||||||
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
|
builder.show();
|
||||||
|
break;
|
||||||
|
case R.id.treatments_delete_future_treatments:
|
||||||
|
builder = new AlertDialog.Builder(this.getContext());
|
||||||
|
builder.setTitle(MainApp.gs(R.string.confirmation));
|
||||||
|
builder.setMessage(MainApp.gs(R.string.deletefuturetreatmets) + "?");
|
||||||
|
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
|
||||||
|
final List<Treatment> futureTreatments = TreatmentsPlugin.getPlugin().getService()
|
||||||
|
.getTreatmentDataFromTime(now() + 1000, true);
|
||||||
|
for (Treatment treatment : futureTreatments) {
|
||||||
|
final String _id = treatment._id;
|
||||||
|
if (NSUpload.isIdValid(_id)) {
|
||||||
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
|
}
|
||||||
|
TreatmentsPlugin.getPlugin().getService().delete(treatment);
|
||||||
}
|
}
|
||||||
|
updateGUI();
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
@ -233,14 +259,16 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
protected void updateGUI() {
|
protected void updateGUI() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(() -> {
|
||||||
@Override
|
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory()), false);
|
||||||
public void run() {
|
if (TreatmentsPlugin.getPlugin().getLastCalculationTreatments() != null) {
|
||||||
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory()), false);
|
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().iob) + " " + MainApp.gs(R.string.insulin_unit_shortname));
|
||||||
if (TreatmentsPlugin.getPlugin().getLastCalculationTreatments() != null) {
|
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().activity) + " " + MainApp.gs(R.string.insulin_unit_shortname));
|
||||||
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().iob) + " U");
|
}
|
||||||
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().activity) + " U");
|
if (!TreatmentsPlugin.getPlugin().getService().getTreatmentDataFromTime(now() + 1000, true).isEmpty()) {
|
||||||
}
|
deleteFutureTreatments.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
deleteFutureTreatments.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,13 +50,28 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<LinearLayout
|
||||||
android:id="@+id/treatments_reshreshfromnightscout"
|
android:layout_width="match_parent"
|
||||||
style="?android:attr/buttonStyle"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:orientation="vertical">
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_horizontal"
|
<Button
|
||||||
android:text="@string/nav_refreshtreatments" />
|
android:id="@+id/treatments_reshreshfromnightscout"
|
||||||
|
style="?android:attr/buttonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/nav_refreshtreatments"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/treatments_delete_future_treatments"
|
||||||
|
style="?android:attr/buttonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/nav_deletefuturetreatments" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/treatments_recyclerview"
|
android:id="@+id/treatments_recyclerview"
|
||||||
|
|
|
@ -437,6 +437,7 @@
|
||||||
<string name="openapsma_scriptdebugdata_label">Script debug</string>
|
<string name="openapsma_scriptdebugdata_label">Script debug</string>
|
||||||
<string name="openapsama_useautosens">Use AMA autosens feature</string>
|
<string name="openapsama_useautosens">Use AMA autosens feature</string>
|
||||||
<string name="refresheventsfromnightscout">Refresh events from NS</string>
|
<string name="refresheventsfromnightscout">Refresh events from NS</string>
|
||||||
|
<string name="deletefuturetreatmets">Delete treatments in the future</string>
|
||||||
<string name="eatingsoon">Eating Soon</string>
|
<string name="eatingsoon">Eating Soon</string>
|
||||||
<string name="hypo">Hypo</string>
|
<string name="hypo">Hypo</string>
|
||||||
<string name="activity">Activity</string>
|
<string name="activity">Activity</string>
|
||||||
|
@ -1163,6 +1164,7 @@
|
||||||
<string name="poctech">Poctech</string>
|
<string name="poctech">Poctech</string>
|
||||||
<string name="description_source_poctech">Receive BG values from Poctech app</string>
|
<string name="description_source_poctech">Receive BG values from Poctech app</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="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="nav_deletefuturetreatments">Delete treatments in the future</string>
|
||||||
|
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%d day</item>
|
<item quantity="one">%d day</item>
|
||||||
|
|
Loading…
Reference in a new issue