removing treatments

This commit is contained in:
Milos Kozak 2017-05-09 20:47:02 +02:00
parent 554fb51a75
commit d313df0d19
6 changed files with 75 additions and 14 deletions

View file

@ -421,6 +421,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<Treatment>(); return new ArrayList<Treatment>();
} }
public void delete(TempBasal tempBasal) {
try {
getDaoTempBasals().delete(tempBasal);
latestTreatmentChange = tempBasal.getTimeIndex();
} catch (SQLException e) {
e.printStackTrace();
}
scheduleTreatmentChange();
}
public List<TempTarget> getTemptargetsDataFromTime(long mills, boolean ascending) { public List<TempTarget> getTemptargetsDataFromTime(long mills, boolean ascending) {
try { try {
Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets(); Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets();

View file

@ -1,9 +1,13 @@
package info.nightscout.androidaps.plugins.TempBasals; package info.nightscout.androidaps.plugins.TempBasals;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
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;
@ -13,6 +17,8 @@ import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -44,7 +50,9 @@ public class TempBasalsFragment extends Fragment {
TextView tempBasalTotalView; TextView tempBasalTotalView;
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> { Context context;
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> {
List<TempBasal> tempBasalList; List<TempBasal> tempBasalList;
@ -55,8 +63,7 @@ public class TempBasalsFragment extends Fragment {
@Override @Override
public TempBasalsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public TempBasalsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tempbasals_item, viewGroup, false); View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tempbasals_item, viewGroup, false);
TempBasalsViewHolder tempBasalsViewHolder = new TempBasalsViewHolder(v); return new TempBasalsViewHolder(v);
return tempBasalsViewHolder;
} }
@Override @Override
@ -89,6 +96,7 @@ public class TempBasalsFragment extends Fragment {
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorAffectingIOB)); holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorAffectingIOB));
else else
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground)); holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground));
holder.remove.setTag(tempBasal);
} }
@Override @Override
@ -101,7 +109,7 @@ public class TempBasalsFragment extends Fragment {
super.onAttachedToRecyclerView(recyclerView); super.onAttachedToRecyclerView(recyclerView);
} }
public static class TempBasalsViewHolder extends RecyclerView.ViewHolder { public class TempBasalsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv; CardView cv;
TextView date; TextView date;
TextView duration; TextView duration;
@ -113,6 +121,7 @@ public class TempBasalsFragment extends Fragment {
TextView iob; TextView iob;
TextView extendedFlag; TextView extendedFlag;
LinearLayout dateLinearLayout; LinearLayout dateLinearLayout;
TextView remove;
TempBasalsViewHolder(View itemView) { TempBasalsViewHolder(View itemView) {
super(itemView); super(itemView);
@ -127,6 +136,36 @@ public class TempBasalsFragment extends Fragment {
iob = (TextView) itemView.findViewById(R.id.tempbasals_iob); iob = (TextView) itemView.findViewById(R.id.tempbasals_iob);
extendedFlag = (TextView) itemView.findViewById(R.id.tempbasals_extendedflag); extendedFlag = (TextView) itemView.findViewById(R.id.tempbasals_extendedflag);
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.tempbasals_datelinearlayout); dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.tempbasals_datelinearlayout);
remove = (TextView) itemView.findViewById(R.id.tempbasals_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final TempBasal tempBasal = (TempBasal) v.getTag();
switch (v.getId()) {
case R.id.tempbasals_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempBasal.timeStart));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// TODO: handle this in NS too
//final String _id = tempBasal._id;
//if (_id != null && !_id.equals("")) {
// MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
//}
MainApp.getDbHelper().delete(tempBasal);
tempBasalsPlugin.initializeData();
updateGUI();
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
}
});
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
builder.show();
break;
}
} }
} }
} }
@ -145,6 +184,9 @@ public class TempBasalsFragment extends Fragment {
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob); tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
context = getContext();
updateGUI(); updateGUI();
return view; return view;
} }

View file

@ -112,7 +112,7 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
return PluginBase.TEMPBASAL; return PluginBase.TEMPBASAL;
} }
private void initializeData() { public void initializeData() {
double dia = 3; double dia = 3;
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null) if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia(); dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();

View file

@ -38,6 +38,7 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -73,16 +74,15 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
@Override @Override
public TreatmentsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public TreatmentsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_item, viewGroup, false); View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_item, viewGroup, false);
TreatmentsViewHolder treatmentsViewHolder = new TreatmentsViewHolder(v); return new TreatmentsViewHolder(v);
return treatmentsViewHolder;
} }
@Override @Override
public void onBindViewHolder(TreatmentsViewHolder holder, int position) { public void onBindViewHolder(TreatmentsViewHolder holder, int position) {
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null) // app not initialized yet if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
return; return;
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin(); InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
if (profile == null || insulinInterface == null) if (profile == null || insulinInterface == null)
return; return;
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at)); holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
@ -138,7 +138,6 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final Treatment treatment = (Treatment) v.getTag(); final Treatment treatment = (Treatment) v.getTag();
final Context finalContext = context;
switch (v.getId()) { switch (v.getId()) {
case R.id.treatments_remove: case R.id.treatments_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
@ -153,7 +152,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
MainApp.getDbHelper().delete(treatment); MainApp.getDbHelper().delete(treatment);
treatmentsPlugin.initializeData(); treatmentsPlugin.initializeData();
updateGUI(); updateGUI();
Answers.getInstance().logCustom(new CustomEvent("RefreshTreatments")); Answers.getInstance().logCustom(new CustomEvent("RemoveTreatment"));
} }
}); });
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null); builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);

View file

@ -168,6 +168,15 @@
android:text="0.12 U" android:text="0.12 U"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView
android:id="@+id/tempbasals_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/overview_quickwizard_item_remove_button"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -135,10 +135,11 @@
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:text="@string/overview_quickwizard_item_remove_button" android:id="@+id/treatments_remove"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/treatments_remove" android:layout_weight="1"
android:text="@string/overview_quickwizard_item_remove_button"
android:textAlignment="viewEnd" android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" /> android:textColor="@android:color/holo_orange_light" />