Merge branch 'nsoffline' into bgsource
This commit is contained in:
commit
a05c1f947e
10 changed files with 133 additions and 98 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() {
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
|
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.TransactionTooLargeException;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -19,9 +16,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.Services.Intents;
|
import info.nightscout.androidaps.Services.Intents;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 20.02.2016.
|
* Created by mike on 20.02.2016.
|
||||||
|
@ -29,10 +24,10 @@ import info.nightscout.utils.ToastUtils;
|
||||||
public class BroadcastTreatment {
|
public class BroadcastTreatment {
|
||||||
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
|
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
|
||||||
|
|
||||||
public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
|
public static void handleNewTreatment(JSONObject treatment, boolean isDelta) {
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("treatment", treatment.getData().toString());
|
bundle.putString("treatment", treatment.toString());
|
||||||
bundle.putBoolean("delta", isDelta);
|
bundle.putBoolean("delta", isDelta);
|
||||||
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
|
@ -41,16 +36,16 @@ public class BroadcastTreatment {
|
||||||
|
|
||||||
if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
|
||||||
bundle = new Bundle();
|
bundle = new Bundle();
|
||||||
bundle.putString("treatment", treatment.getData().toString());
|
bundle.putString("treatment", treatment.toString());
|
||||||
bundle.putBoolean("delta", isDelta);
|
bundle.putBoolean("delta", isDelta);
|
||||||
intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
|
public static void handleNewTreatment(JSONArray treatments, boolean isDelta) {
|
||||||
|
|
||||||
List<JSONArray> splitted = splitArray(treatments);
|
List<JSONArray> splitted = splitArray(treatments);
|
||||||
for (JSONArray part : splitted) {
|
for (JSONArray part : splitted) {
|
||||||
|
@ -72,12 +67,12 @@ public class BroadcastTreatment {
|
||||||
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) {
|
public void handleChangedTreatment(JSONObject treatment, boolean isDelta) {
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("treatment", treatment.toString());
|
bundle.putString("treatment", treatment.toString());
|
||||||
|
@ -95,11 +90,11 @@ public class BroadcastTreatment {
|
||||||
intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
|
intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
|
public static void handleChangedTreatment(JSONArray treatments, boolean isDelta) {
|
||||||
|
|
||||||
List<JSONArray> splitted = splitArray(treatments);
|
List<JSONArray> splitted = splitArray(treatments);
|
||||||
for (JSONArray part : splitted) {
|
for (JSONArray part : splitted) {
|
||||||
|
@ -121,12 +116,12 @@ public class BroadcastTreatment {
|
||||||
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
|
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
|
public static void handleRemovedTreatment(JSONObject treatment, boolean isDelta) {
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("treatment", treatment.toString());
|
bundle.putString("treatment", treatment.toString());
|
||||||
|
@ -144,11 +139,11 @@ public class BroadcastTreatment {
|
||||||
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
|
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
|
public static void handleRemovedTreatment(JSONArray treatments, boolean isDelta) {
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("treatments", treatments.toString());
|
bundle.putString("treatments", treatments.toString());
|
||||||
|
@ -166,7 +161,7 @@ public class BroadcastTreatment {
|
||||||
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
|
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
|
||||||
intent.putExtras(bundle);
|
intent.putExtras(bundle);
|
||||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
context.sendBroadcast(intent);
|
MainApp.instance().getApplicationContext().sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,14 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.DbRequest;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
|
||||||
import info.nightscout.androidaps.db.DbRequest;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
public class DBAccessReceiver extends BroadcastReceiver {
|
public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
|
@ -89,7 +87,12 @@ 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"))
|
||||||
|
genereateTreatmentOfflineBroadcast(dbr);
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -98,6 +101,19 @@ public class DBAccessReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void genereateTreatmentOfflineBroadcast(DbRequest request) {
|
||||||
|
if (request.action.equals("dbAdd")) {
|
||||||
|
try {
|
||||||
|
JSONObject data = new JSONObject(request.data);
|
||||||
|
data.put("mills", DateUtil.fromISODateString(data.getString("created_at")).getTime());
|
||||||
|
data.put("_id", data.get("NSCLIENT_ID")); // this is only fake id
|
||||||
|
BroadcastTreatment.handleNewTreatment(data, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Unhadled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isAllowedCollection(String collection) {
|
private boolean isAllowedCollection(String collection) {
|
||||||
// "treatments" || "entries" || "devicestatus" || "profile" || "food"
|
// "treatments" || "entries" || "devicestatus" || "profile" || "food"
|
||||||
if (collection.equals("treatments")) return true;
|
if (collection.equals("treatments")) return true;
|
||||||
|
|
|
@ -52,15 +52,15 @@ import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastS
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
|
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import io.socket.client.IO;
|
import io.socket.client.IO;
|
||||||
|
@ -524,13 +524,13 @@ public class NSClientService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (removedTreatments.length() > 0) {
|
if (removedTreatments.length() > 0) {
|
||||||
BroadcastTreatment.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastTreatment.handleRemovedTreatment(removedTreatments, isDelta);
|
||||||
}
|
}
|
||||||
if (updatedTreatments.length() > 0) {
|
if (updatedTreatments.length() > 0) {
|
||||||
BroadcastTreatment.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastTreatment.handleChangedTreatment(updatedTreatments, isDelta);
|
||||||
}
|
}
|
||||||
if (addedTreatments.length() > 0) {
|
if (addedTreatments.length() > 0) {
|
||||||
BroadcastTreatment.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastTreatment.handleNewTreatment(addedTreatments, isDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.has("devicestatus")) {
|
if (data.has("devicestatus")) {
|
||||||
|
|
|
@ -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"));
|
||||||
|
|
|
@ -493,4 +493,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