NSOffline remove from queue as well
This commit is contained in:
parent
b98c321cbc
commit
fa4e80444d
8 changed files with 37 additions and 10 deletions
|
@ -96,6 +96,8 @@ public class UploadQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeID(final String action, final String _id) {
|
public static void removeID(final String action, final String _id) {
|
||||||
|
if (_id == null || _id.equals(""))
|
||||||
|
return;
|
||||||
startService();
|
startService();
|
||||||
if (NSClientService.handler != null) {
|
if (NSClientService.handler != null) {
|
||||||
NSClientService.handler.post(new Runnable() {
|
NSClientService.handler.post(new Runnable() {
|
||||||
|
|
|
@ -87,6 +87,9 @@ public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
UploadQueue.add(dbr);
|
UploadQueue.add(dbr);
|
||||||
} else {
|
} else {
|
||||||
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
|
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
|
||||||
|
// this is not used as mongo _id but only for searching in UploadQueue database
|
||||||
|
// if record has to be removed from queue before upload
|
||||||
|
dbr._id = nsclientid.toString();
|
||||||
UploadQueue.add(dbr);
|
UploadQueue.add(dbr);
|
||||||
if (collection.equals("treatments"))
|
if (collection.equals("treatments"))
|
||||||
genereateTreatmentOfflineBroadcast(dbr);
|
genereateTreatmentOfflineBroadcast(dbr);
|
||||||
|
|
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
@ -82,7 +83,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
||||||
holder.mealOrCorrection.setText(t.mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
holder.mealOrCorrection.setText(t.mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
||||||
holder.ph.setVisibility(t.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(t.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(t._id != null ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(t._id) ? View.VISIBLE : View.GONE);
|
||||||
holder.invalid.setVisibility(t.isValid ? View.GONE : View.VISIBLE);
|
holder.invalid.setVisibility(t.isValid ? View.GONE : View.VISIBLE);
|
||||||
if (iob.iobContrib != 0)
|
if (iob.iobContrib != 0)
|
||||||
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
|
||||||
|
@ -146,8 +147,10 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
|
||||||
treatment.isValid = false;
|
treatment.isValid = false;
|
||||||
MainApp.getDbHelper().update(treatment);
|
MainApp.getDbHelper().update(treatment);
|
||||||
} else {
|
} else {
|
||||||
if (_id != null && !_id.equals("")) {
|
if (NSUpload.isIdValid(_id)) {
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(treatment);
|
MainApp.getDbHelper().delete(treatment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -63,7 +64,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
|
||||||
public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) {
|
public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) {
|
||||||
ExtendedBolus extendedBolus = extendedBolusList.getReversed(position);
|
ExtendedBolus extendedBolus = extendedBolusList.getReversed(position);
|
||||||
holder.ph.setVisibility(extendedBolus.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(extendedBolus.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(extendedBolus._id != null ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(extendedBolus._id) ? View.VISIBLE : View.GONE);
|
||||||
if (extendedBolus.isEndingEvent()) {
|
if (extendedBolus.isEndingEvent()) {
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
|
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
|
||||||
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
|
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
|
||||||
|
@ -148,8 +149,10 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final String _id = extendedBolus._id;
|
final String _id = extendedBolus._id;
|
||||||
if (_id != null && !_id.equals("")) {
|
if (NSUpload.isIdValid(_id)) {
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(extendedBolus);
|
MainApp.getDbHelper().delete(extendedBolus);
|
||||||
Answers.getInstance().logCustom(new CustomEvent("RemoveExtendedBolus"));
|
Answers.getInstance().logCustom(new CustomEvent("RemoveExtendedBolus"));
|
||||||
|
|
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -66,7 +67,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
|
||||||
if (profile == null) return;
|
if (profile == null) return;
|
||||||
ProfileSwitch profileSwitch = profileSwitchList.getReversed(position);
|
ProfileSwitch profileSwitch = profileSwitchList.getReversed(position);
|
||||||
holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(profileSwitch._id != null ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(profileSwitch._id) ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date));
|
holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date));
|
||||||
if (!profileSwitch.isEndingEvent()) {
|
if (!profileSwitch.isEndingEvent()) {
|
||||||
|
@ -131,8 +132,10 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final String _id = profileSwitch._id;
|
final String _id = profileSwitch._id;
|
||||||
if (_id != null && !_id.equals("")) {
|
if (NSUpload.isIdValid(_id)) {
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(profileSwitch);
|
MainApp.getDbHelper().delete(profileSwitch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.events.EventTempTargetChange;
|
import info.nightscout.androidaps.events.EventTempTargetChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -67,7 +68,7 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements
|
||||||
String units = MainApp.getConfigBuilder().getProfileUnits();
|
String units = MainApp.getConfigBuilder().getProfileUnits();
|
||||||
TempTarget tempTarget = tempTargetList.getReversed(position);
|
TempTarget tempTarget = tempTargetList.getReversed(position);
|
||||||
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(tempTarget._id != null ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE);
|
||||||
if (!tempTarget.isEndingEvent()) {
|
if (!tempTarget.isEndingEvent()) {
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd()));
|
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd()));
|
||||||
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
|
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
|
||||||
|
@ -149,8 +150,10 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final String _id = tempTarget._id;
|
final String _id = tempTarget._id;
|
||||||
if (_id != null && !_id.equals("")) {
|
if (NSUpload.isIdValid(_id)) {
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(tempTarget);
|
MainApp.getDbHelper().delete(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -65,7 +66,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
|
||||||
public void onBindViewHolder(TempBasalsViewHolder holder, int position) {
|
public void onBindViewHolder(TempBasalsViewHolder holder, int position) {
|
||||||
TemporaryBasal tempBasal = tempBasalList.getReversed(position);
|
TemporaryBasal tempBasal = tempBasalList.getReversed(position);
|
||||||
holder.ph.setVisibility(tempBasal.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
holder.ph.setVisibility(tempBasal.source == Source.PUMP ? View.VISIBLE : View.GONE);
|
||||||
holder.ns.setVisibility(tempBasal._id != null ? View.VISIBLE : View.GONE);
|
holder.ns.setVisibility(NSUpload.isIdValid(tempBasal._id) ? View.VISIBLE : View.GONE);
|
||||||
if (tempBasal.isEndingEvent()) {
|
if (tempBasal.isEndingEvent()) {
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(tempBasal.date));
|
holder.date.setText(DateUtil.dateAndTimeString(tempBasal.date));
|
||||||
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
|
holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
|
||||||
|
@ -165,8 +166,10 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final String _id = tempBasal._id;
|
final String _id = tempBasal._id;
|
||||||
if (_id != null && !_id.equals("")) {
|
if (NSUpload.isIdValid(_id)) {
|
||||||
NSUpload.removeCareportalEntryFromNS(_id);
|
NSUpload.removeCareportalEntryFromNS(_id);
|
||||||
|
} else {
|
||||||
|
UploadQueue.removeID("dbAdd", _id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(tempBasal);
|
MainApp.getDbHelper().delete(tempBasal);
|
||||||
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
||||||
|
|
|
@ -449,4 +449,11 @@ public class NSUpload {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isIdValid(String _id) {
|
||||||
|
if (_id == null)
|
||||||
|
return false;
|
||||||
|
if (_id.length() == 24)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue