From b23b5d04f651c821a31b9edd3c830437bfe23012 Mon Sep 17 00:00:00 2001
From: Klaus3d3 <31705095+Klaus3d3@users.noreply.github.com>
Date: Thu, 26 Jul 2018 21:23:07 +0200
Subject: [PATCH] alarm canceling bugfix
---
.../dexdrip/Models/BgReading.java | 3 ++
.../eveningoutpost/dexdrip/Models/JoH.java | 2 ++
.../dexdrip/NewDataObserver.java | 6 ++--
.../SnoozeOnNotificationDismissService.java | 6 ++++
.../dexdrip/UtilityModels/AlertPlayer.java | 10 +++---
.../wearintegration/Amazfitservice.java | 34 +++++++------------
.../main/res/xml/pref_advanced_settings.xml | 6 ++--
7 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java b/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java
index 2269744352..bc9d7f5999 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java
@@ -13,6 +13,7 @@
import com.activeandroid.query.Delete;
import com.activeandroid.query.Select;
import com.activeandroid.util.SQLiteUtils;
+import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.BestGlucose;
import com.eveningoutpost.dexdrip.GcmActivity;
import com.eveningoutpost.dexdrip.Home;
@@ -663,6 +664,7 @@ public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new)
SyncService.startSyncService(3000); // sync in 3 seconds
}
}
+
}
public String displaySlopeArrow() {
@@ -1111,6 +1113,7 @@ public static void notifyAndSync(final BgReading bgr) {
//bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
}
BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), Home.get_follower(), !recent); // pebble and widget and follower
+
}
public static BgReading bgReadingInsertFromJson(String json, boolean do_notification) {
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java b/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java
index d59ab8de48..eb3c587704 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java
@@ -56,6 +56,7 @@
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.UtilityModels.Constants;
+import com.eveningoutpost.dexdrip.UtilityModels.Notifications;
import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore;
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.UtilityModels.XdripNotificationCompat;
@@ -1171,6 +1172,7 @@ public static void scheduleNotification(Context context, String title, String bo
public static void cancelNotification(int notificationId) {
final NotificationManager mNotifyMgr = (NotificationManager) xdrip.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.cancel(notificationId);
+
}
public static void showNotification(String title, String content, PendingIntent intent, int notificationId, boolean sound, boolean vibrate, boolean onetime) {
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java b/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java
index 2315fce45d..32932a60cc 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/NewDataObserver.java
@@ -11,6 +11,7 @@
import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil;
import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync;
import com.eveningoutpost.dexdrip.utils.BgToSpeech;
+
import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService;
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;
@@ -41,6 +42,7 @@ public static void newBgReading(BgReading bgReading, boolean is_follower) {
sendToWear();
sendToAmazfit();
Notifications.start();
+
uploadToShare(bgReading, is_follower);
textToSpeech(bgReading, null);
LibreBlock.UpdateBgVal(bgReading.timestamp, bgReading.calculated_value);
@@ -60,7 +62,7 @@ public static void newExternalStatus(boolean receivedLocally) {
// send to pebble
sendToPebble();
//send to amazfit
- sendToAmazfit();
+ sendToAmazfit();
// don't send via GCM if received via GCM!
if (receivedLocally) {
@@ -81,10 +83,8 @@ private static void sendToPebble() {
// send data to Amazfit if enabled
private static void sendToAmazfit() {
-
if(Pref.getBoolean("pref_amazfit_enable_key", true)) {
Amazfitservice.start("xDrip_synced_SGV_data");}
-
}
// send to wear
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java
index 710503183e..8211b51c52 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/SnoozeOnNotificationDismissService.java
@@ -17,6 +17,8 @@
import com.eveningoutpost.dexdrip.Models.UserNotification;
import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer;
import com.eveningoutpost.dexdrip.UtilityModels.Constants;
+import com.eveningoutpost.dexdrip.UtilityModels.Pref;
+import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.xdrip;
/**
@@ -88,5 +90,9 @@ private void snoozeOtherAlert(String alertType) {
long snoozeMinutes = MissedReadingService.getOtherAlertSnoozeMinutes(prefs, alertType);
Log.i(TAG, "snoozeOtherAlert calling snooze alert alert = " + alertType + " snoozeMinutes = " + snoozeMinutes);
UserNotification.snoozeAlert(alertType, snoozeMinutes);
+ if (Pref.getBoolean("pref_amazfit_enable_key", false)&&Pref.getBoolean("pref_amazfit_BG_alert_enable_key", false))
+ { Amazfitservice.start("xDrip_AlarmCancel");
+
+ }
}
}
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java
index de7bd16f25..95338bc430 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java
@@ -184,10 +184,7 @@ public synchronized void stopAlert(Context ctx, boolean ClearData, boolean clear
mediaPlayer = null;
}
revertCurrentVolume(ctx);
- if (Pref.getBoolean("pref_amazfit_enable_key", false)&&Pref.getBoolean("pref_amazfit_alarm_enable_key", false))
- { Amazfitservice.start("xDrip_AlarmCancel");
- }
}
@@ -211,6 +208,10 @@ public synchronized void Snooze(Context ctx, int repeatTime) {
if (Pref.getBooleanDefaultFalse("bg_notifications_watch") ) {
startWatchUpdaterService(ctx, WatchUpdaterService.ACTION_SNOOZE_ALERT, TAG, "repeatTime", "" + repeatTime);
}
+ if (Pref.getBoolean("pref_amazfit_enable_key", false)&&Pref.getBoolean("pref_amazfit_BG_alert_enable_key", false))
+ { Amazfitservice.start("xDrip_AlarmCancel");
+
+ }
}
public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) {
@@ -535,6 +536,8 @@ private void VibrateNotifyMakeNoise(Context context, AlertType alert, String bgV
{ Amazfitservice.start("xDrip_Alarm",alert.name,alert.default_snooze);
}
+
+
final NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
mNotifyMgr.notify(Notifications.exportAlertNotificationId, XdripNotificationCompat.build(builder));
@@ -562,7 +565,6 @@ private void notificationDismiss(Context ctx) {
} catch (NullPointerException e) {
UserError.Log.e(TAG,"Got null pointer in notificationDismiss !!");
}
-
}
// True means play the file false means only vibrate.
diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java
index de431dd93e..e08fe860e3 100644
--- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java
+++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/Amazfitservice.java
@@ -23,20 +23,11 @@
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
-
-import android.os.IBinder;
-import android.support.annotation.Nullable;
-
-
import com.eveningoutpost.dexdrip.BestGlucose;
import com.eveningoutpost.dexdrip.Models.HeartRate;
-import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.StepCounter;
-import com.eveningoutpost.dexdrip.Models.UserError;
import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder;
import com.eveningoutpost.dexdrip.UtilityModels.BgSparklineBuilder;
-import com.eveningoutpost.dexdrip.UtilityModels.Notifications;
-
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.utils.PowerStateReceiver;
import com.eveningoutpost.dexdrip.xdrip;
@@ -90,13 +81,7 @@ public void onChannelChanged(boolean ready) {
});
- Transporter.DataSendResultCallback test = new Transporter.DataSendResultCallback() {
- @Override
- public void onResultBack(DataTransportResult dataTransportResult) {
- UserError.Log.e("Amazfitservice", "Result back ");
- }
- };
transporter.addDataListener(new Transporter.DataListener() {
@Override
public void onDataReceived(TransportDataItem item) {
@@ -105,11 +90,11 @@ public void onDataReceived(TransportDataItem item) {
//Confirmation that watch received SGV Data
if (item.getAction().equals("SGVDataConfirmation")) {
DataBundle db = item.getData();
- UserError.Log.e("Amazfitservice", db.getString("reply_message"));
+ //UserError.Log.e("Amazfitservice", db.getString("reply_message"));
}
if (item.getAction().equals("CancelConfirmation")) {
DataBundle db = item.getData();
- UserError.Log.e("Amazfitservice", db.getString("reply_message"));
+ //UserError.Log.e("Amazfitservice", db.getString("reply_message"));
}
// In case of getting a remote Snooze from watch check for an active alert and confirm snooze in case of
@@ -172,6 +157,13 @@ public void onDestroy() {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ Transporter.DataSendResultCallback test = new Transporter.DataSendResultCallback() {
+ @Override
+ public void onResultBack(DataTransportResult dataTransportResult) {
+
+ UserError.Log.e("Amazfitservice", dataTransportResult.toString() );
+ }
+ };
if (!transporter.isTransportServiceConnected()) {
UserError.Log.e("Amazfitservice", "Service not connected - trying to reconnect ");
transporter.connectTransportService();
@@ -184,11 +176,11 @@ public int onStartCommand(Intent intent, int flags, int startId) {
} else {
- transporter.send(getAction(), getDataBundle());
- UserError.Log.e("Amazfitservice", "trying to send Data to watch " + action);
+ transporter.send(getAction(), getDataBundle(),test );
+ //UserError.Log.e("Amazfitservice", "trying to send Data to watch " + action);
}
- return START_NOT_STICKY;
+ return START_STICKY;
}
@@ -282,7 +274,7 @@ public static void start(String action_text,String alert_name, int snooze_time){
default_snooze=snooze_time;
- //JoH.startService(Amazfitservice.class);
+ JoH.startService(Amazfitservice.class);
}
diff --git a/app/src/main/res/xml/pref_advanced_settings.xml b/app/src/main/res/xml/pref_advanced_settings.xml
index 1263051a89..c607f085bf 100644
--- a/app/src/main/res/xml/pref_advanced_settings.xml
+++ b/app/src/main/res/xml/pref_advanced_settings.xml
@@ -217,13 +217,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:title="@string/amazfit_sync_service">
-
-
-