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