Skip to content

Commit

Permalink
alarm canceling bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus3d3 committed Jul 26, 2018
1 parent f383a27 commit b23b5d0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -663,6 +664,7 @@ public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new)
SyncService.startSyncService(3000); // sync in 3 seconds
}
}

}

public String displaySlopeArrow() {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}

}

Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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;


}
Expand Down Expand Up @@ -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);
}


Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/xml/pref_advanced_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:title="@string/amazfit_sync_service">
<SwitchPreference
<CheckBoxPreference
android:defaultValue="false"
android:disableDependentsState="false"
android:key="pref_amazfit_enable_key"
android:summary="@string/pref_amazfit_enable_summary"
android:title="@string/pref_amazfit_tile" />
<SwitchPreference
<CheckBoxPreference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:defaultValue="false"
android:dependency="pref_amazfit_enable_key"
android:key="pref_amazfit_BG_alert_enable_key"
android:summary="@string/pref_amazfit_BG_alert_enable_summary"
android:title="@string/pref_amazfit_BG_alert_title" />
<SwitchPreference
<CheckBoxPreference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:defaultValue="false"
Expand Down

0 comments on commit b23b5d0

Please sign in to comment.