refresh treatments confirm dialog

This commit is contained in:
Milos Kozak 2016-06-06 12:30:20 +02:00
parent bd47fb8624
commit 04f1b37c51

View file

@ -1,9 +1,11 @@
package info.nightscout.androidaps.plugins.Treatments; package info.nightscout.androidaps.plugins.Treatments;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -76,7 +78,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
private void updateTotalIOB() { private void updateTotalIOB() {
Iob total = new Iob(); Iob total = new Iob();
for (Integer pos = 0; pos < treatments.size(); pos++ ) { for (Integer pos = 0; pos < treatments.size(); pos++) {
Treatment t = treatments.get(pos); Treatment t = treatments.get(pos);
total.plus(t.iobCalc(new Date())); total.plus(t.iobCalc(new Date()));
} }
@ -185,10 +187,20 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.treatments_reshreshfromnightscout: case R.id.treatments_reshreshfromnightscout:
MainApp.getDbHelper().resetTreatments(); AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
initializeData(); builder.setTitle("Dialog");
Intent restartNSClient = new Intent(Intents.ACTION_RESTART); builder.setMessage("Do you want to refresh treatments from Nightscout");
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetTreatments();
initializeData();
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
break; break;
} }
} }
@ -243,7 +255,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
* fragment to allow an interaction in this fragment to be communicated * fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that * to the activity and potentially other fragments contained in that
* activity. * activity.
* <p/> * <p>
* See the Android Training lesson <a href= * See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html" * "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information. * >Communicating with Other Fragments</a> for more information.