allow to remove treatments from GUI
This commit is contained in:
parent
a75c62be35
commit
dda95dc275
|
@ -230,6 +230,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
scheduleTreatmentChange();
|
||||
}
|
||||
|
||||
public void delete(Treatment treatment) {
|
||||
try {
|
||||
getDaoTreatments().delete(treatment);
|
||||
latestTreatmentChange = treatment.getTimeIndex();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
scheduleTreatmentChange();
|
||||
}
|
||||
|
||||
public int delete(String _id) {
|
||||
Treatment stored = findTreatmentById(_id);
|
||||
int removed = 0;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.Treatments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -55,7 +57,9 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
TextView activityTotal;
|
||||
Button refreshFromNS;
|
||||
|
||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TreatmentsViewHolder> {
|
||||
Context context;
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TreatmentsViewHolder> {
|
||||
|
||||
List<Treatment> treatments;
|
||||
|
||||
|
@ -88,6 +92,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.colorAffectingIOB));
|
||||
else
|
||||
holder.dateLinearLayout.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.cardColorBackground));
|
||||
holder.remove.setTag(treatments.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,7 +105,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
super.onAttachedToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
public static class TreatmentsViewHolder extends RecyclerView.ViewHolder {
|
||||
public class TreatmentsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
CardView cv;
|
||||
TextView date;
|
||||
TextView insulin;
|
||||
|
@ -109,6 +114,7 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
TextView activity;
|
||||
TextView mealOrCorrection;
|
||||
LinearLayout dateLinearLayout;
|
||||
TextView remove;
|
||||
|
||||
TreatmentsViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -120,6 +126,35 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
activity = (TextView) itemView.findViewById(R.id.treatments_activity);
|
||||
mealOrCorrection = (TextView) itemView.findViewById(R.id.treatments_mealorcorrection);
|
||||
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.treatments_datelinearlayout);
|
||||
remove = (TextView) itemView.findViewById(R.id.treatments_remove);
|
||||
remove.setOnClickListener(this);
|
||||
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
}
|
||||
|
||||
@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);
|
||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(treatment.created_at));
|
||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
final String _id = treatment._id;
|
||||
if (_id != null && !_id.equals("")) {
|
||||
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||
}
|
||||
MainApp.getDbHelper().delete(treatment);
|
||||
treatmentsPlugin.initializeData();
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
|
||||
builder.show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +178,8 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
|
||||
refreshFromNS.setOnClickListener(this);
|
||||
|
||||
context = getContext();
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
@ -153,8 +190,8 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
|||
case R.id.treatments_reshreshfromnightscout:
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
|
||||
if(nsUploadOnly){
|
||||
ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled));
|
||||
if (nsUploadOnly) {
|
||||
ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled));
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
|
||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||
|
|
|
@ -134,6 +134,13 @@
|
|||
android:layout_marginRight="30dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:text="@string/overview_quickwizard_item_remove_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/treatments_remove"
|
||||
android:textAlignment="viewEnd"
|
||||
android:textColor="@android:color/holo_orange_light" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue