diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java
index 9b90d2d..118b154 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/client/CareLinkClient.java
@@ -1,5 +1,6 @@
package com.eveningoutpost.dexdrip.cgm.carelinkfollow.client;
+import com.eveningoutpost.dexdrip.Models.JoH;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
@@ -119,50 +120,63 @@ public RecentData getRecentData() {
public RecentData getRecentData(String patientUsername) {
// Force login to get basic info
- if (getAuthorizationToken() != null) {
- // M2M
- if (this.sessionM2MEnabled)
- // Care Partner
- if(this.sessionUser.isCarePartner())
- return this.getM2MPatientData(patientUsername);
- // Patient
- else
- // 7xxG
- if(sessionMonitorData.isBle())
- return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(),
- sessionCountrySettings.blePereodicDataEndpoint);
- // Standalone CGM
- else
- return this.getLast24Hours();
- // Non M2M (old logic)
- else if (sessionMonitorData.isBle())
- return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(),
- sessionCountrySettings.blePereodicDataEndpoint);
- else
- return this.getLast24Hours();
- } else {
+ if (getAuthorizationToken() == null)
return null;
- }
+
+ // 7xxG
+ if (this.isBleDevice(patientUsername))
+ return this.getConnectDisplayMessage(this.sessionProfile.username, this.sessionUser.getUserRole(), patientUsername,
+ sessionCountrySettings.blePereodicDataEndpoint);
+ // Guardian + multi
+ else if (this.sessionM2MEnabled)
+ return this.getM2MPatientData(patientUsername);
+ // Guardian + single
+ else
+ return this.getLast24Hours();
}
public String getDefaultPatientUsername() {
+
// Force login to get basic info
- if (getAuthorizationToken() != null) {
- if (this.sessionUser != null)
- if (this.sessionUser.isCarePartner())
- if (this.sessionPatients != null && this.sessionPatients.length > 0)
- return this.sessionPatients[0].username;
- else
- return null;
- else
- return this.sessionProfile.username;
+ if (getAuthorizationToken() == null)
+ return null;
+
+ // Care Partner + multi follow => first patient
+ if (this.sessionUser.isCarePartner() && this.sessionM2MEnabled)
+ if (this.sessionPatients != null && this.sessionPatients.length > 0)
+ return this.sessionPatients[0].username;
else
return null;
- } else
+ // Not care partner or no multi follow => username from session profile
+ else if (this.sessionProfile.username != null)
+ return this.sessionProfile.username;
+ else
return null;
}
+ public boolean isBleDevice(String patientUsername){
+
+
+ // Force login to get basic info
+ if(getAuthorizationToken() == null)
+ return false;
+
+ if(this.sessionM2MEnabled && this.sessionUser.isCarePartner())
+ if(patientUsername == null || this.sessionPatients == null)
+ return false;
+ else {
+ for (int i = 0; i < this.sessionPatients.length; i++) {
+ if (sessionPatients[i].username.equals(patientUsername))
+ return sessionPatients[i].isBle();
+ }
+ return false;
+ }
+ else
+ return this.sessionMonitorData.isBle();
+
+ }
+
// Get CareLink server address
protected String careLinkServer() {
if (CountryUtils.isUS(carelinkCountry))
@@ -206,10 +220,10 @@ protected boolean executeLoginProcedure() {
this.sessionProfile = this.getMyProfile();
this.sessionCountrySettings = this.getMyCountrySettings();
this.sessionM2MEnabled = this.getM2MEnabled().value;
- //Care Partner + multi follow => patients
- if(this.sessionUser.isCarePartner() && this.sessionM2MEnabled)
+ // Multi follow + Care Partner => patients
+ if(this.sessionM2MEnabled && this.sessionUser.isCarePartner())
this.sessionPatients = this.getM2MPatients();
- //Patient or Care Partner & not multi follow => monitor data
+ // Single follow and/or Patient => monitor data
else
this.sessionMonitorData = this.getMonitorData();
@@ -221,8 +235,9 @@ protected boolean executeLoginProcedure() {
}
// Set login success if everything was ok:
- if(this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && this.sessionM2MEnabled != null
- && ((this.sessionM2MEnabled && this.sessionUser.isCarePartner() && this.sessionPatients != null) || this.sessionMonitorData != null))
+ if(this.sessionUser != null && this.sessionProfile != null && this.sessionCountrySettings != null && this.sessionM2MEnabled != null &&
+ (((!this.sessionM2MEnabled || !this.sessionUser.isCarePartner()) && this.sessionMonitorData != null) ||
+ (this.sessionM2MEnabled && this.sessionUser.isCarePartner() && this.sessionPatients != null)))
lastLoginSuccess = true;
//Clear cookies, session infos if error occured during login process
else {
@@ -408,7 +423,7 @@ public RecentData getLast24Hours() {
}
// Periodic data from CareLink Cloud
- public RecentData getConnectDisplayMessage(String username, String role, String endpointUrl) {
+ public RecentData getConnectDisplayMessage(String username, String role, String patientUsername, String endpointUrl) {
RequestBody requestBody = null;
Gson gson = null;
@@ -419,6 +434,8 @@ public RecentData getConnectDisplayMessage(String username, String role, String
userJson = new JsonObject();
userJson.addProperty("username", username);
userJson.addProperty("role", role);
+ if(!JoH.emptyString(patientUsername))
+ userJson.addProperty("patientId", patientUsername);
gson = new GsonBuilder().create();
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java
index 256fa6d..b80ac5e 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/cgm/carelinkfollow/message/Patient.java
@@ -11,4 +11,8 @@ public class Patient {
public String lastDeviceFamily;
public boolean patientUsesConnect;
+ public boolean isBle() {
+ return lastDeviceFamily.contains("BLE");
+ }
+
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 342f639..bb1b2e9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1329,7 +1329,7 @@
CareLink login password
CareLink Country
CareLink country code
- CareLink Patient Username
+ CareLink Patient
CareLink patient username
CareLink Language
CareLink language code