TimeDateReceiver cleanup
This commit is contained in:
parent
2aea486409
commit
51d363d467
2 changed files with 21 additions and 33 deletions
|
@ -114,9 +114,6 @@ public class MainApp extends DaggerApplication {
|
||||||
|
|
||||||
static DatabaseHelper sDatabaseHelper = null;
|
static DatabaseHelper sDatabaseHelper = null;
|
||||||
|
|
||||||
DataReceiver dataReceiver = new DataReceiver();
|
|
||||||
TimeDateOrTZChangeReceiver timeDateOrTZChangeReceiver;
|
|
||||||
|
|
||||||
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
|
private String CHANNEL_ID = "AndroidAPS-Ongoing"; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
|
private int ONGOING_NOTIFICATION_ID = 4711; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
private Notification notification; // TODO: move to OngoingNotificationProvider (and dagger)
|
||||||
|
@ -330,23 +327,28 @@ public class MainApp extends DaggerApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerLocalBroadcastReceiver() {
|
private void registerLocalBroadcastReceiver() {
|
||||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
|
IntentFilter filter = new IntentFilter();
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
filter.addAction(Intents.ACTION_NEW_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
|
filter.addAction(Intents.ACTION_CHANGED_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
|
filter.addAction(Intents.ACTION_REMOVED_TREATMENT);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
|
filter.addAction(Intents.ACTION_NEW_SGV);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
|
filter.addAction(Intents.ACTION_NEW_PROFILE);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
|
filter.addAction(Intents.ACTION_NEW_MBG);
|
||||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
|
filter.addAction(Intents.ACTION_NEW_CAL);
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(new DataReceiver(), filter);
|
||||||
|
|
||||||
this.timeDateOrTZChangeReceiver = new TimeDateOrTZChangeReceiver();
|
filter = new IntentFilter();
|
||||||
this.timeDateOrTZChangeReceiver.registerBroadcasts(this);
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_DATE_CHANGED);
|
||||||
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||||
|
registerReceiver(new TimeDateOrTZChangeReceiver(), filter);
|
||||||
|
|
||||||
|
filter = new IntentFilter();
|
||||||
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
|
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
|
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||||
|
registerReceiver(new NetworkChangeReceiver(), filter);
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
|
||||||
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
||||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
||||||
registerReceiver(new NetworkChangeReceiver(), intentFilter);
|
|
||||||
registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
registerReceiver(new ChargingStateReceiver(), new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,11 +423,7 @@ public class MainApp extends DaggerApplication {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTerminate() {
|
public void onTerminate() {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.CORE, "onTerminate");
|
aapsLogger.debug(LTag.CORE, "onTerminate");
|
||||||
|
|
||||||
if (timeDateOrTZChangeReceiver != null)
|
|
||||||
unregisterReceiver(timeDateOrTZChangeReceiver);
|
|
||||||
unregisterActivityLifecycleCallbacks(activityMonitor);
|
unregisterActivityLifecycleCallbacks(activityMonitor);
|
||||||
keepAliveManager.cancelAlarm(this);
|
keepAliveManager.cancelAlarm(this);
|
||||||
super.onTerminate();
|
super.onTerminate();
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package info.nightscout.androidaps.receivers
|
package info.nightscout.androidaps.receivers
|
||||||
|
|
||||||
import android.content.BroadcastReceiver
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.IntentFilter
|
|
||||||
import dagger.android.DaggerBroadcastReceiver
|
import dagger.android.DaggerBroadcastReceiver
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface
|
import info.nightscout.androidaps.interfaces.PumpInterface
|
||||||
|
@ -18,19 +16,11 @@ class TimeDateOrTZChangeReceiver : DaggerBroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
super.onReceive(context, intent)
|
super.onReceive(context, intent)
|
||||||
val action = intent.action
|
val action = intent.action
|
||||||
val activePump: PumpInterface = activePlugin.getActivePump()
|
val activePump: PumpInterface = activePlugin.activePump
|
||||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
|
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed.")
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
|
aapsLogger.debug(LTag.PUMP, "Date, Time and/or TimeZone changed. Notifying pump driver.")
|
||||||
activePump.timeDateOrTimeZoneChanged()
|
activePump.timeDateOrTimeZoneChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerBroadcasts(context: Context) {
|
|
||||||
val filter = IntentFilter()
|
|
||||||
filter.addAction(Intent.ACTION_TIME_CHANGED)
|
|
||||||
filter.addAction(Intent.ACTION_DATE_CHANGED)
|
|
||||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED)
|
|
||||||
context.registerReceiver(this, filter)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue