Skip to content

Commit

Permalink
Add ns-sdk and test receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Feb 20, 2023
1 parent 27b6747 commit fcd8063
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ dependencies {
exclude group: 'androidx.core', module: 'core' // fix INotificationSideChannel // android.support.v4.app
}

api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1"
implementation(name: 'ns-sdk-full-release', ext: 'aar')

//implementation 'androidx.core:core-ktx:1.9.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.21'

Expand Down Expand Up @@ -344,7 +347,9 @@ dependencies {
testImplementation "org.robolectric:robolectric:4.4.1"
testImplementation "com.google.truth:truth:1.1.3"

testImplementation 'org.mockito:mockito-core:2.4.0'
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation 'org.mockito:mockito-core:4.11.0'

testImplementation 'org.powermock:powermock-core:1.7.1'
testImplementation 'org.powermock:powermock-module-junit4:1.7.1'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.7.1'
Expand Down
Binary file added app/libs/ns-sdk-full-release.aar
Binary file not shown.
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:installLocation="internalOnly"
tools:ignore="InnerclassSeparator">

<uses-sdk tools:overrideLibrary="androidx.health.connect.client" />
<uses-sdk tools:overrideLibrary="androidx.health.connect.client, info.nightscout.sdk" />
<!-- To receive data from HAPP. -->
<uses-permission android:name="com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE" /> <!-- To receive data from Aidex -->
<uses-permission android:name="com.microtechmd.cgms.aidex.permissions.RECEIVE_BG_ESTIMATE" />
Expand Down Expand Up @@ -498,6 +498,9 @@
</activity>

<receiver android:name=".NSClientReceiver">
<intent-filter>
<action android:name="info.nightscout.client.NS_BRIDGE" />
</intent-filter>
<intent-filter>
<action android:name="info.nightscout.client.NEW_SGV" />
</intent-filter>
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/eveningoutpost/dexdrip/NSClientReceiver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eveningoutpost.dexdrip;

import static com.eveningoutpost.dexdrip.Models.JoH.emptyString;
import static com.eveningoutpost.dexdrip.xdrip.gs;

import android.content.BroadcastReceiver;
Expand All @@ -18,6 +19,7 @@
import com.eveningoutpost.dexdrip.UtilityModels.Intents;
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.profileeditor.ImportAapsProfile;
import com.google.gson.GsonBuilder;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -26,6 +28,7 @@
import java.util.HashMap;
import java.util.UUID;

import info.nightscout.sdk.localmodel.devicestatus.NSDeviceStatus;
import lombok.val;


Expand Down Expand Up @@ -57,6 +60,27 @@ public void onReceive(Context context, Intent intent) {
if (action == null) return;

switch (action) {
case Intents.ACTION_NS_BRIDGE:
if (bundle == null) break;
if (prefs.getBoolean("accept_nsclient_treatments", true)) {

final String device_status_json = bundle.getString("devicestatus", "");
if (!emptyString(device_status_json)) {
try {
val gson = new GsonBuilder().create(); // TODO optimize
val ds = gson.fromJson(device_status_json, NSDeviceStatus.class);
Log.e(TAG, "DEBUG: got device status: " + ds.toString());
} catch (Exception e) {
Log.e(TAG, "Exception processing device status in NS_BRIDGE action: " + e);
}
} else {
Log.e(TAG, "Empty device status received via NS_BRIDGE action");
}
} else {
Log.e(TAG, "Cannot accept device status as preference setting prevents it");
}
break;

case Intents.ACTION_NEW_SGV:
if (Home.get_follower() && prefs.getBoolean("accept_nsclient_sgv", true)) {
if (bundle == null) break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface Intents {
String ACTION_REMOVED_TREATMENT = "info.nightscout.client.REMOVED_TREATMENT";
String ACTION_NEW_PROFILE = "info.nightscout.client.NEW_PROFILE";
String ACTION_NEW_SGV = "info.nightscout.client.NEW_SGV";
String ACTION_NS_BRIDGE = "info.nightscout.client.NS_BRIDGE";



Expand Down

0 comments on commit fcd8063

Please sign in to comment.