From d1e5018cc2eccdd0659136e2ad304abbbcd9b62d Mon Sep 17 00:00:00 2001
From: "jgwashburn@gmail.com" <jgwashburn@gmail.com>
Date: Sun, 26 Feb 2017 18:10:39 -0800
Subject: [PATCH] fabric key back in

---
 app/gradle.properties                         |   1 -
 app/src/main/AndroidManifest.xml              |   8 +-
 .../model/medtronicNg/StatusEvent.java        | 301 ------------------
 .../upload/nightscout/NightScoutUpload.java   |  14 +-
 .../NightscoutUploadIntentService.java        |  19 +-
 .../serializer/EntriesSerializer.java         |   3 +-
 .../nightscout/NightScoutUploadTest.java      |  79 -----
 7 files changed, 15 insertions(+), 410 deletions(-)
 delete mode 100644 app/src/main/java/info/nightscout/android/model/medtronicNg/StatusEvent.java
 delete mode 100644 app/src/testDebug/java/info/nightscout/android/upload/nightscout/NightScoutUploadTest.java

diff --git a/app/gradle.properties b/app/gradle.properties
index 94ae5a2..1dd0e26 100644
--- a/app/gradle.properties
+++ b/app/gradle.properties
@@ -1,2 +1 @@
-#version=0.5.0-SNAPSHOT
 version=0.5.0-SNAPSHOT
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index da0d7ae..6dfc77d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -88,9 +88,11 @@
 
 
         <receiver android:name=".medtronic.service.MedtronicCnlAlarmReceiver"></receiver>
-        <meta-data
-            android:name="io.fabric.ApiKey"
-            android:value="aa26e770bd4f7480eed7cabb63a84363ecd12009" />
+
+                <meta-data
+                    android:name="io.fabric.ApiKey"
+                    android:value="aa26e770bd4f7480eed7cabb63a84363ecd12009" />
+
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/android/model/medtronicNg/StatusEvent.java b/app/src/main/java/info/nightscout/android/model/medtronicNg/StatusEvent.java
deleted file mode 100644
index 7a99616..0000000
--- a/app/src/main/java/info/nightscout/android/model/medtronicNg/StatusEvent.java
+++ /dev/null
@@ -1,301 +0,0 @@
-package info.nightscout.android.model.medtronicNg;
-
-import java.util.Date;
-
-// Pump Data without Realm
-// So that we can unit test the upload code in a modular fashion,
-// without the Realm and Android Context dependencies.
-
-public class StatusEvent {
-
-    public StatusEvent(PumpStatusEvent pumpStatusEvent) {
-        eventDate = pumpStatusEvent.getEventDate();
-        pumpDate = pumpStatusEvent.getPumpDate();
-        deviceName = pumpStatusEvent.getDeviceName();
-        suspended = pumpStatusEvent.isSuspended();
-        bolusing = pumpStatusEvent.isBolusing();
-        deliveringInsulin = pumpStatusEvent.isDeliveringInsulin();
-        tempBasalActive = pumpStatusEvent.isTempBasalActive();
-        cgmActive = pumpStatusEvent.isCgmActive();
-        activeBasalPattern = pumpStatusEvent.getActiveBasalPattern();
-        basalRate = pumpStatusEvent.getBasalRate();
-        tempBasalRate = pumpStatusEvent.getTempBasalRate();
-        tempBasalPercentage = pumpStatusEvent.getTempBasalPercentage();
-        tempBasalMinutesRemaining = pumpStatusEvent.getTempBasalMinutesRemaining();
-        basalUnitsDeliveredToday = pumpStatusEvent.getBasalUnitsDeliveredToday();
-        batteryPercentage = pumpStatusEvent.getBatteryPercentage();
-        reservoirAmount = pumpStatusEvent.getReservoirAmount();
-        minutesOfInsulinRemaining = pumpStatusEvent.getMinutesOfInsulinRemaining();
-        activeInsulin = pumpStatusEvent.getActiveInsulin();
-        sgv = pumpStatusEvent.getSgv();
-        sgvDate = pumpStatusEvent.getSgvDate();
-        lowSuspendActive = pumpStatusEvent.isLowSuspendActive();
-        cgmTrend = pumpStatusEvent.getCgmTrendString();
-    }
-
-    public StatusEvent() {
-    }
-
-
-    private Date eventDate; // The actual time of the event (assume the capture device eventDate/time is accurate)
-    private Date pumpDate; // The eventDate/time on the pump at the time of the event
-    private String deviceName;
-
-    // Data from the Medtronic Pump Status message
-    private boolean suspended;
-    private boolean bolusing;
-    private boolean deliveringInsulin;
-    private boolean tempBasalActive;
-    private boolean cgmActive;
-    private byte activeBasalPattern;
-    private float basalRate;
-    private float tempBasalRate;
-    private byte tempBasalPercentage;
-    private short tempBasalMinutesRemaining;
-    private float basalUnitsDeliveredToday;
-    private short batteryPercentage;
-    private float reservoirAmount;
-    private short minutesOfInsulinRemaining; // 25h == "more than 1 day"
-    private float activeInsulin;
-    private int sgv;
-    private Date sgvDate;
-    private boolean lowSuspendActive;
-    private String cgmTrend;
-
-    private boolean recentBolusWizard; // Whether a bolus wizard has been run recently
-    private int bolusWizardBGL; // in mg/dL. 0 means no recent bolus wizard reading.
-
-    private long pumpTimeOffset; // millis the pump is ahead
-
-    private boolean uploaded = false;
-
-    public Date getEventDate() {
-        return eventDate;
-    }
-
-    public void setEventDate(Date eventDate) {
-        this.eventDate = eventDate;
-    }
-
-    public Date getPumpDate() {
-        return pumpDate;
-    }
-
-    public void setPumpDate(Date pumpDate) {
-        this.pumpDate = pumpDate;
-    }
-
-    public String getDeviceName() {
-        return deviceName;
-    }
-
-    public void setDeviceName(String deviceName) {
-        this.deviceName = deviceName;
-    }
-
-    public int getSgv() {
-        return sgv;
-    }
-
-    public void setSgv(int sgv) {
-        this.sgv = sgv;
-    }
-
-    public CGM_TREND getCgmTrend() {
-        return CGM_TREND.valueOf(cgmTrend);
-    }
-
-    public void setCgmTrend(CGM_TREND cgmTrend) {
-        this.cgmTrend = cgmTrend.name();
-    }
-
-    public void setCgmTrend(String cgmTrend) {
-        this.cgmTrend = cgmTrend;
-    }
-
-    public float getActiveInsulin() {
-        return activeInsulin;
-    }
-
-    public void setActiveInsulin(float activeInsulin) {
-        this.activeInsulin = activeInsulin;
-    }
-
-    public short getBatteryPercentage() {
-        return batteryPercentage;
-    }
-
-    public void setBatteryPercentage(short batteryPercentage) {
-        this.batteryPercentage = batteryPercentage;
-    }
-
-    public float getReservoirAmount() {
-        return reservoirAmount;
-    }
-
-    public void setReservoirAmount(float reservoirAmount) {
-        this.reservoirAmount = reservoirAmount;
-    }
-
-    public boolean hasRecentBolusWizard() {
-        return recentBolusWizard;
-    }
-
-    public int getBolusWizardBGL() {
-        return bolusWizardBGL;
-    }
-
-    public void setBolusWizardBGL(int bolusWizardBGL) {
-        this.bolusWizardBGL = bolusWizardBGL;
-    }
-
-    public boolean isUploaded() {
-        return uploaded;
-    }
-
-    public void setUploaded(boolean uploaded) {
-        this.uploaded = uploaded;
-    }
-
-    public boolean isSuspended() {
-        return suspended;
-    }
-
-    public void setSuspended(boolean suspended) {
-        this.suspended = suspended;
-    }
-
-    public boolean isBolusing() {
-        return bolusing;
-    }
-
-    public void setBolusing(boolean bolusing) {
-        this.bolusing = bolusing;
-    }
-
-    public boolean isDeliveringInsulin() {
-        return deliveringInsulin;
-    }
-
-    public void setDeliveringInsulin(boolean deliveringInsulin) {
-        this.deliveringInsulin = deliveringInsulin;
-    }
-
-    public boolean isTempBasalActive() {
-        return tempBasalActive;
-    }
-
-    public void setTempBasalActive(boolean tempBasalActive) {
-        this.tempBasalActive = tempBasalActive;
-    }
-
-    public boolean isCgmActive() {
-        return cgmActive;
-    }
-
-    public void setCgmActive(boolean cgmActive) {
-        this.cgmActive = cgmActive;
-    }
-
-    public byte getActiveBasalPattern() {
-        return activeBasalPattern;
-    }
-
-    public void setActiveBasalPattern(byte activeBasalPattern) {
-        this.activeBasalPattern = activeBasalPattern;
-    }
-
-    public float getBasalRate() {
-        return basalRate;
-    }
-
-    public void setBasalRate(float basalRate) {
-        this.basalRate = basalRate;
-    }
-
-    public float getTempBasalRate() {
-        return tempBasalRate;
-    }
-
-    public void setTempBasalRate(float tempBasalRate) {
-        this.tempBasalRate = tempBasalRate;
-    }
-
-    public byte getTempBasalPercentage() {
-        return tempBasalPercentage;
-    }
-
-    public void setTempBasalPercentage(byte tempBasalPercentage) {
-        this.tempBasalPercentage = tempBasalPercentage;
-    }
-
-    public short getTempBasalMinutesRemaining() {
-        return tempBasalMinutesRemaining;
-    }
-
-    public void setTempBasalMinutesRemaining(short tempBasalMinutesRemaining) {
-        this.tempBasalMinutesRemaining = tempBasalMinutesRemaining;
-    }
-
-    public float getBasalUnitsDeliveredToday() {
-        return basalUnitsDeliveredToday;
-    }
-
-    public void setBasalUnitsDeliveredToday(float basalUnitsDeliveredToday) {
-        this.basalUnitsDeliveredToday = basalUnitsDeliveredToday;
-    }
-
-    public short getMinutesOfInsulinRemaining() {
-        return minutesOfInsulinRemaining;
-    }
-
-    public void setMinutesOfInsulinRemaining(short minutesOfInsulinRemaining) {
-        this.minutesOfInsulinRemaining = minutesOfInsulinRemaining;
-    }
-
-    public Date getSgvDate() {
-        return sgvDate;
-    }
-
-    public void setSgvDate(Date sgvDate) {
-        this.sgvDate = sgvDate;
-    }
-
-    public boolean isLowSuspendActive() {
-        return lowSuspendActive;
-    }
-
-    public void setLowSuspendActive(boolean lowSuspendActive) {
-        this.lowSuspendActive = lowSuspendActive;
-    }
-
-    public boolean isRecentBolusWizard() {
-        return recentBolusWizard;
-    }
-
-    public void setRecentBolusWizard(boolean recentBolusWizard) {
-        this.recentBolusWizard = recentBolusWizard;
-    }
-
-    public long getPumpTimeOffset() {
-        return pumpTimeOffset;
-    }
-
-    public void setPumpTimeOffset(long pumpTimeOffset) {
-        this.pumpTimeOffset = pumpTimeOffset;
-    }
-
-    public enum CGM_TREND {
-            NONE,
-            DOUBLE_UP,
-            SINGLE_UP,
-            FOURTY_FIVE_UP,
-            FLAT,
-            FOURTY_FIVE_DOWN,
-            SINGLE_DOWN,
-            DOUBLE_DOWN,
-            NOT_COMPUTABLE,
-            RATE_OUT_OF_RANGE,
-            NOT_SET
-    }
-}
diff --git a/app/src/main/java/info/nightscout/android/upload/nightscout/NightScoutUpload.java b/app/src/main/java/info/nightscout/android/upload/nightscout/NightScoutUpload.java
index f5e2754..55a2120 100644
--- a/app/src/main/java/info/nightscout/android/upload/nightscout/NightScoutUpload.java
+++ b/app/src/main/java/info/nightscout/android/upload/nightscout/NightScoutUpload.java
@@ -11,7 +11,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
-import info.nightscout.android.model.medtronicNg.StatusEvent;
+import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
 import info.nightscout.android.upload.nightscout.serializer.EntriesSerializer;
 
 import android.support.annotation.NonNull;
@@ -39,7 +39,7 @@ public class NightScoutUpload {
     public Boolean doRESTUpload(String url,
                                 String secret,
                                 int uploaderBatteryLevel,
-                                List<StatusEvent> records) {
+                                List<PumpStatusEvent> records) {
         Boolean success = false;
         try {
             success = isUploaded(records, url, secret, uploaderBatteryLevel);
@@ -50,7 +50,7 @@ public class NightScoutUpload {
     }
 
 
-    private boolean isUploaded(List<StatusEvent> records,
+    private boolean isUploaded(List<PumpStatusEvent> records,
                                  String baseURL,
                                  String secret,
                                  int uploaderBatteryLevel) throws Exception {
@@ -69,13 +69,13 @@ public class NightScoutUpload {
 
     private boolean uploadEvents(GlucoseEndpoints glucoseEndpoints,
                                  BolusEndpoints bolusEndpoints,
-                                 List<StatusEvent> records ) throws Exception {
+                                 List<PumpStatusEvent> records ) throws Exception {
 
 
         List<GlucoseEntry> glucoseEntries = new ArrayList<>();
         List<BolusEntry> bolusEntries = new ArrayList<>();
 
-        for (StatusEvent record : records) {
+        for (PumpStatusEvent record : records) {
 
             GlucoseEntry  glucoseEntry = new GlucoseEntry();
 
@@ -110,11 +110,11 @@ public class NightScoutUpload {
 
     private boolean uploadDeviceStatus(DeviceEndpoints deviceEndpoints,
                                        int uploaderBatteryLevel,
-                                       List<StatusEvent> records) throws Exception {
+                                       List<PumpStatusEvent> records) throws Exception {
 
 
         List<DeviceStatus> deviceEntries = new ArrayList<>();
-        for (StatusEvent record : records) {
+        for (PumpStatusEvent record : records) {
 
             Iob iob = new Iob(record.getPumpDate(), record.getActiveInsulin());
             Battery battery = new Battery(record.getBatteryPercentage());
diff --git a/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java b/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java
index df4429a..51174e3 100644
--- a/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java
+++ b/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java
@@ -10,13 +10,9 @@ import android.preference.PreferenceManager;
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import info.nightscout.android.R;
 import info.nightscout.android.medtronic.MainActivity;
 import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
-import info.nightscout.android.model.medtronicNg.StatusEvent;
 import io.realm.Realm;
 import io.realm.RealmResults;
 
@@ -71,9 +67,9 @@ public class NightscoutUploadIntentService extends IntentService {
                     Log.i(TAG, String.format("Starting upload of %s record using a REST API", records.size()));
                     String urlSetting = prefs.getString(mContext.getString(R.string.preference_nightscout_url), "");
                     String secretSetting = prefs.getString(mContext.getString(R.string.preference_api_secret), "YOURAPISECRET");
-                    List<StatusEvent> statusEvents = getStatusEvents(records);
                     int uploaderBatteryLevel = MainActivity.batLevel;
-                    Boolean uploadSuccess = mNightScoutUpload.doRESTUpload(urlSetting, secretSetting, uploaderBatteryLevel, statusEvents);
+                    Boolean uploadSuccess = mNightScoutUpload.doRESTUpload(urlSetting,
+                            secretSetting, uploaderBatteryLevel, records);
                     if (uploadSuccess) {
                         mRealm.beginTransaction();
                         for (PumpStatusEvent updateRecord : records) {
@@ -94,17 +90,6 @@ public class NightscoutUploadIntentService extends IntentService {
         NightscoutUploadReceiver.completeWakefulIntent(intent);
     }
 
-    private List<StatusEvent> getStatusEvents(RealmResults<PumpStatusEvent> records) {
-        List<StatusEvent> statusEvents = new ArrayList<>();
-        for (PumpStatusEvent record : records) {
-            StatusEvent event = new StatusEvent(record);
-            statusEvents.add(event);
-        }
-
-        return statusEvents;
-    }
-
-
     private boolean isOnline() {
         ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         NetworkInfo netInfo = cm.getActiveNetworkInfo();
diff --git a/app/src/main/java/info/nightscout/android/upload/nightscout/serializer/EntriesSerializer.java b/app/src/main/java/info/nightscout/android/upload/nightscout/serializer/EntriesSerializer.java
index 61785e9..ce79ab7 100644
--- a/app/src/main/java/info/nightscout/android/upload/nightscout/serializer/EntriesSerializer.java
+++ b/app/src/main/java/info/nightscout/android/upload/nightscout/serializer/EntriesSerializer.java
@@ -8,7 +8,6 @@ import com.google.gson.JsonSerializer;
 import java.lang.reflect.Type;
 
 import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
-import info.nightscout.android.model.medtronicNg.StatusEvent;
 
 /**
  * Created by lgoedhart on 26/06/2016.
@@ -43,7 +42,7 @@ public class EntriesSerializer implements JsonSerializer<PumpStatusEvent> {
         }
     }
 
-    public static String getDirectionStringStatus(StatusEvent.CGM_TREND trend) {
+    public static String getDirectionStringStatus(PumpStatusEvent.CGM_TREND trend) {
         switch( trend ) {
             case NONE:
                 return "NONE";
diff --git a/app/src/testDebug/java/info/nightscout/android/upload/nightscout/NightScoutUploadTest.java b/app/src/testDebug/java/info/nightscout/android/upload/nightscout/NightScoutUploadTest.java
deleted file mode 100644
index b46150a..0000000
--- a/app/src/testDebug/java/info/nightscout/android/upload/nightscout/NightScoutUploadTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package info.nightscout.android.upload.nightscout;
-
-import android.util.Log;
-
-import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
-import info.nightscout.android.model.medtronicNg.StatusEvent;
-
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({Log.class})
-public class NightScoutUploadTest {
-
-    NightScoutUpload mUploader;
-    List<StatusEvent> mEvents;
-
-    @Before
-    public void doSetup() {
-
-        mUploader = new NightScoutUpload();
-
-        mEvents = new ArrayList<StatusEvent>();
-
-        StatusEvent event1 = new StatusEvent();
-        Date date = new Date();
-        event1.setEventDate(date);
-        event1.setPumpDate(date);
-        event1.setDeviceName("MyDevice");
-        event1.setSgv(100);
-        event1.setCgmTrend(StatusEvent.CGM_TREND.FLAT);
-        event1.setActiveInsulin(5.0f);
-        event1.setBatteryPercentage((short)100);
-        event1.setReservoirAmount(50.0f);
-        event1.setRecentBolusWizard(false);
-        event1.setBolusWizardBGL(100);
-        event1.setUploaded(false);
-        event1.setSuspended(false);
-        event1.setDeliveringInsulin(false);
-        event1.setTempBasalActive(false);
-        event1.setCgmActive(false);
-        event1.setActiveBasalPattern((byte)42);
-        event1.setBasalRate(1.0f);
-        event1.setTempBasalPercentage((byte)80);
-        event1.setTempBasalMinutesRemaining((short)30);
-        event1.setBasalUnitsDeliveredToday(30.0f);
-        event1.setMinutesOfInsulinRemaining((short)45);
-        event1.setSgvDate(date);
-        event1.setLowSuspendActive(false);
-        event1.setPumpTimeOffset(100000);
-
-        mEvents.add(event1);
-
-    }
-
-    @Test
-    public void doTest() {
-        PowerMockito.mockStatic(Log.class);
-        String url =  "https://my.azurewebsites.net";
-        String secret = "SECRET";
-        int uploaderBatteryLevel = 50;
-
-        Boolean success = mUploader.doRESTUpload(url, secret, uploaderBatteryLevel, mEvents);
-        assertEquals(success, true);
-    }
-
-}
\ No newline at end of file
-- 
GitLab