allow removing temp target records with null _id

This commit is contained in:
Milos Kozak 2017-01-17 23:43:50 +01:00
parent f9ed2ed4b4
commit 9f4cc28c0f

View file

@ -86,7 +86,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
else else
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground)); holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
holder.remove.setTag(tempTarget); holder.remove.setTag(tempTarget);
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
@ -98,7 +98,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
super.onAttachedToRecyclerView(recyclerView); super.onAttachedToRecyclerView(recyclerView);
} }
public class TempTargetsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public class TempTargetsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv; CardView cv;
TextView date; TextView date;
TextView duration; TextView duration;
@ -128,26 +128,26 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
final Context finalContext = context; final Context finalContext = context;
switch (v.getId()) { switch (v.getId()) {
case R.id.temptargetrange_remove: case R.id.temptargetrange_remove:
final String _id = tempTarget._id; AlertDialog.Builder builder = new AlertDialog.Builder(context);
if (_id != null && !_id.equals("")) { builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempTarget.timeStart));
builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + _id); public void onClick(DialogInterface dialog, int id) {
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { final String _id = tempTarget._id;
public void onClick(DialogInterface dialog, int id) { if (_id != null && !_id.equals("")) {
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id); MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
try {
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
daoTempTargets.delete(tempTarget);
MainApp.bus().post(new EventTempTargetRangeChange());
} catch (SQLException e) {
e.printStackTrace();
}
} }
}); try {
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null); Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
builder.show(); daoTempTargets.delete(tempTarget);
} MainApp.bus().post(new EventTempTargetRangeChange());
} catch (SQLException e) {
e.printStackTrace();
}
}
});
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
builder.show();
break; break;
} }
} }
@ -182,8 +182,8 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
case R.id.temptargetrange_refreshfromnightscout: case R.id.temptargetrange_refreshfromnightscout:
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false); boolean nsUploadOnly = SP.getBoolean("ns_upload_only", false);
if(nsUploadOnly){ if (nsUploadOnly) {
ToastUtils.showToastInUiThread(getContext(),this.getContext().getString(R.string.ns_upload_only_enabled)); ToastUtils.showToastInUiThread(getContext(), this.getContext().getString(R.string.ns_upload_only_enabled));
} else { } else {
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(this.getContext().getString(R.string.confirmation)); builder.setTitle(this.getContext().getString(R.string.confirmation));