diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java
index 24d367610..985bc8a79 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/AlarmReceiver.java
@@ -22,7 +22,6 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.os.Build;
import net.e175.klaus.solarpositioning.DeltaT;
import net.e175.klaus.solarpositioning.SPA;
@@ -61,10 +60,6 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- if (!GBApplication.getPrefs().getBoolean("send_sunrise_sunset", false)) {
- LOG.info("won't send sunrise and sunset events (disabled in preferences)");
- return;
- }
LOG.info("will resend sunrise and sunset events");
final GregorianCalendar dateTimeTomorrow = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
index 5e70dd55a..8810c4d47 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java
@@ -22,8 +22,6 @@
along with this program. If not, see . */
package nodomain.freeyourgadget.gadgetbridge.service;
-import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.*;
-
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
@@ -113,6 +111,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.language.LanguageUtils;
import nodomain.freeyourgadget.gadgetbridge.util.language.Transliterator;
+import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.*;
+
public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
public static class DeviceStruct{
private GBDevice device;
@@ -1310,19 +1310,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
}
}
}
- if (mAlarmReceiver == null) {
- mAlarmReceiver = new AlarmReceiver();
- ContextCompat.registerReceiver(this, mAlarmReceiver, new IntentFilter("DAILY_ALARM"), ContextCompat.RECEIVER_EXPORTED);
- }
} else {
for (CalendarReceiver registeredReceiver: mCalendarReceiver){
unregisterReceiver(registeredReceiver);
}
mCalendarReceiver.clear();
- if (mAlarmReceiver != null) {
- unregisterReceiver(mAlarmReceiver);
- mAlarmReceiver = null;
- }
}
if (enable) {
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java
index 17763af74..12bda9777 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleSupport.java
@@ -18,9 +18,12 @@
along with this program. If not, see . */
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
+import android.content.IntentFilter;
import android.net.Uri;
import android.util.Pair;
+import androidx.core.content.ContextCompat;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -34,6 +37,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
+import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
@@ -47,10 +51,36 @@ import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
public class PebbleSupport extends AbstractSerialDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(PebbleSupport.class);
+ private AlarmReceiver mAlarmReceiver = null;
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ unregisterSunriseSunsetAlarmReceiver();
+ }
+
+ private void registerSunriseSunsetAlarmReceiver() {
+ if (!getDevicePrefs().getBoolean("send_sunrise_sunset", false)) {
+ LOG.info("won't register sunrise and sunset receiver (disabled in preferences)");
+ return;
+ }
+ unregisterSunriseSunsetAlarmReceiver();
+ LOG.info("registering sunrise and sunset receiver");
+ this.mAlarmReceiver = new AlarmReceiver();
+ ContextCompat.registerReceiver(GBApplication.getContext(), mAlarmReceiver, new IntentFilter("DAILY_ALARM"), ContextCompat.RECEIVER_EXPORTED);
+ }
+
+ private void unregisterSunriseSunsetAlarmReceiver() {
+ if (mAlarmReceiver != null) {
+ GBApplication.getContext().unregisterReceiver(mAlarmReceiver);
+ mAlarmReceiver = null;
+ }
+ }
@Override
public boolean connect() {
getDeviceIOThread().start();
+ registerSunriseSunsetAlarmReceiver();
return true;
}
diff --git a/app/src/main/res/xml/devicesettings_pebble_preferences.xml b/app/src/main/res/xml/devicesettings_pebble_preferences.xml
index d335cfaf1..a06cef6e0 100644
--- a/app/src/main/res/xml/devicesettings_pebble_preferences.xml
+++ b/app/src/main/res/xml/devicesettings_pebble_preferences.xml
@@ -30,7 +30,6 @@
android:title="@string/pref_title_enable_outgoing_call"
app:iconSpaceReserved="false" />
-
diff --git a/app/src/main/res/xml/pebble_preferences.xml b/app/src/main/res/xml/pebble_preferences.xml
index 9299ad9da..1924911c6 100644
--- a/app/src/main/res/xml/pebble_preferences.xml
+++ b/app/src/main/res/xml/pebble_preferences.xml
@@ -13,16 +13,6 @@
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
-
-
-