Create careportal events with explicit time.

This commit is contained in:
Johannes Mockenhaupt 2018-03-25 15:43:43 +02:00
parent 593174d6d2
commit 7c959ce335
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 24 additions and 2 deletions

View file

@ -186,8 +186,9 @@ public class FillDialog extends DialogFragment implements OnClickListener {
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill"));
}
if (pumpSiteChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.SITECHANGE);
if (insulinCartridgeChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE);
long now = System.currentTimeMillis();
if (pumpSiteChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now);
if (insulinCartridgeChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now + 1000);
});
builder.setNegativeButton(getString(R.string.cancel), null);
builder.show();

View file

@ -475,6 +475,27 @@ public class NSUpload {
}
}
public static void uploadEvent(String careportalEvent, long time) {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putString("action", "dbAdd");
bundle.putString("collection", "treatments");
JSONObject data = new JSONObject();
try {
data.put("eventType", careportalEvent);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
}
public static void removeFoodFromNS(String _id) {
try {
Context context = MainApp.instance().getApplicationContext();