centralize quit() functionality in GBApplication
This commit is contained in:
parent
9215233344
commit
f54163faeb
|
@ -77,20 +77,13 @@ public class GBApplication extends Application {
|
|||
}
|
||||
};
|
||||
private static DeviceManager deviceManager;
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case ACTION_QUIT:
|
||||
quit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void quit() {
|
||||
GB.removeAllNotifications(this);
|
||||
public static void quit() {
|
||||
GB.log("Quitting Gadgetbridge...", GB.INFO, null);
|
||||
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
||||
GBApplication.deviceService().quit();
|
||||
GB.removeAllNotifications(context);
|
||||
}
|
||||
|
||||
public GBApplication() {
|
||||
|
@ -130,10 +123,6 @@ public class GBApplication extends Application {
|
|||
// mActivityDatabaseHandler = new ActivityDatabaseHandler(context);
|
||||
loadBlackList();
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
if (isRunningMarshmallowOrLater()) {
|
||||
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
|
|
@ -311,10 +311,7 @@ public class ControlCenter extends GBActivity {
|
|||
startActivity(debugIntent);
|
||||
return true;
|
||||
case R.id.action_quit:
|
||||
GBApplication.deviceService().quit();
|
||||
|
||||
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
||||
GBApplication.quit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
|||
|
||||
GBApplication.deviceService().connect();
|
||||
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
||||
GBApplication.deviceService().quit();
|
||||
|
||||
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
||||
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
||||
GBApplication.quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue