removing treatments
This commit is contained in:
parent
554fb51a75
commit
d313df0d19
|
@ -421,6 +421,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
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) {
|
||||
try {
|
||||
Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets();
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.TempBasals;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -13,6 +17,8 @@ import android.view.ViewGroup;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.crashlytics.android.answers.Answers;
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -44,7 +50,9 @@ public class TempBasalsFragment extends Fragment {
|
|||
|
||||
TextView tempBasalTotalView;
|
||||
|
||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> {
|
||||
Context context;
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> {
|
||||
|
||||
List<TempBasal> tempBasalList;
|
||||
|
||||
|
@ -55,8 +63,7 @@ public class TempBasalsFragment extends Fragment {
|
|||
@Override
|
||||
public TempBasalsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.tempbasals_item, viewGroup, false);
|
||||
TempBasalsViewHolder tempBasalsViewHolder = new TempBasalsViewHolder(v);
|
||||
return tempBasalsViewHolder;
|
||||
return new TempBasalsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,6 +96,7 @@ public class TempBasalsFragment extends Fragment {
|
|||
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorAffectingIOB));
|
||||
else
|
||||
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground));
|
||||
holder.remove.setTag(tempBasal);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,7 +109,7 @@ public class TempBasalsFragment extends Fragment {
|
|||
super.onAttachedToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
public static class TempBasalsViewHolder extends RecyclerView.ViewHolder {
|
||||
public class TempBasalsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
CardView cv;
|
||||
TextView date;
|
||||
TextView duration;
|
||||
|
@ -113,6 +121,7 @@ public class TempBasalsFragment extends Fragment {
|
|||
TextView iob;
|
||||
TextView extendedFlag;
|
||||
LinearLayout dateLinearLayout;
|
||||
TextView remove;
|
||||
|
||||
TempBasalsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -127,6 +136,36 @@ public class TempBasalsFragment extends Fragment {
|
|||
iob = (TextView) itemView.findViewById(R.id.tempbasals_iob);
|
||||
extendedFlag = (TextView) itemView.findViewById(R.id.tempbasals_extendedflag);
|
||||
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);
|
||||
|
||||
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
|
||||
|
||||
context = getContext();
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
|
|||
return PluginBase.TEMPBASAL;
|
||||
}
|
||||
|
||||
private void initializeData() {
|
||||
public void initializeData() {
|
||||
double dia = 3;
|
||||
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
|
||||
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
|
||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.androidaps.data.Iob;
|
|||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
@ -73,16 +74,15 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
@Override
|
||||
public TreatmentsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.treatments_item, viewGroup, false);
|
||||
TreatmentsViewHolder treatmentsViewHolder = new TreatmentsViewHolder(v);
|
||||
return treatmentsViewHolder;
|
||||
return new TreatmentsViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||
if (profile == null || insulinInterface == null)
|
||||
return;
|
||||
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
|
||||
|
@ -138,7 +138,6 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
final Treatment treatment = (Treatment) v.getTag();
|
||||
final Context finalContext = context;
|
||||
switch (v.getId()) {
|
||||
case R.id.treatments_remove:
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
@ -153,7 +152,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
MainApp.getDbHelper().delete(treatment);
|
||||
treatmentsPlugin.initializeData();
|
||||
updateGUI();
|
||||
Answers.getInstance().logCustom(new CustomEvent("RefreshTreatments"));
|
||||
Answers.getInstance().logCustom(new CustomEvent("RemoveTreatment"));
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
|
||||
|
|
|
@ -168,6 +168,15 @@
|
|||
android:text="0.12 U"
|
||||
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>
|
||||
|
|
|
@ -135,10 +135,11 @@
|
|||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/overview_quickwizard_item_remove_button"
|
||||
android:id="@+id/treatments_remove"
|
||||
android:layout_width="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:textColor="@android:color/holo_orange_light" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue