mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 17:45:50 +01:00
On Quit, remove all pending notifications
At least the notifications from #141 don't stay there forever, then.
This commit is contained in:
parent
8b87e97f51
commit
159c187e5e
@ -1,11 +1,16 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.app.Application;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Build.VERSION;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -20,6 +25,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
@ -38,6 +44,24 @@ public class GBApplication extends Application {
|
||||
private static DeviceService deviceService;
|
||||
private static SharedPreferences sharedPrefs;
|
||||
|
||||
public static final String ACTION_QUIT
|
||||
= "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit";
|
||||
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 GBApplication() {
|
||||
context = this;
|
||||
// don't do anything here, add it to onCreate instead
|
||||
@ -68,6 +92,11 @@ public class GBApplication extends Application {
|
||||
GB.environment = GBEnvironment.createDeviceEnvironment();
|
||||
mActivityDatabaseHandler = new ActivityDatabaseHandler(context);
|
||||
loadBlackList();
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
// for testing DB stuff
|
||||
// SQLiteDatabase db = mActivityDatabaseHandler.getWritableDatabase();
|
||||
// db.close();
|
||||
|
@ -39,7 +39,7 @@ public class AppBlacklistActivity extends Activity {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ControlCenter.ACTION_QUIT)) {
|
||||
if (action.equals(GBApplication.ACTION_QUIT)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ public class AppBlacklistActivity extends Activity {
|
||||
});
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(GBApplication.ACTION_QUIT);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class AppManagerActivity extends Activity {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ControlCenter.ACTION_QUIT)) {
|
||||
if (action.equals(GBApplication.ACTION_QUIT)) {
|
||||
finish();
|
||||
} else if (action.equals(ACTION_REFRESH_APPLIST)) {
|
||||
appList.clear();
|
||||
@ -139,7 +139,7 @@ public class AppManagerActivity extends Activity {
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(GBApplication.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH_APPLIST);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
|
@ -45,9 +45,6 @@ public class ControlCenter extends Activity {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ControlCenter.class);
|
||||
|
||||
public static final String ACTION_QUIT
|
||||
= "nodomain.freeyourgadget.gadgetbridge.controlcenter.action.quit";
|
||||
|
||||
public static final String ACTION_REFRESH_DEVICELIST
|
||||
= "nodomain.freeyourgadget.gadgetbridge.controlcenter.action.set_version";
|
||||
|
||||
@ -63,7 +60,7 @@ public class ControlCenter extends Activity {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case ACTION_QUIT:
|
||||
case GBApplication.ACTION_QUIT:
|
||||
finish();
|
||||
break;
|
||||
case ACTION_REFRESH_DEVICELIST:
|
||||
@ -155,7 +152,7 @@ public class ControlCenter extends Activity {
|
||||
registerForContextMenu(deviceListView);
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ACTION_QUIT);
|
||||
filterLocal.addAction(GBApplication.ACTION_QUIT);
|
||||
filterLocal.addAction(ACTION_REFRESH_DEVICELIST);
|
||||
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||
filterLocal.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
|
||||
@ -316,7 +313,7 @@ public class ControlCenter extends Activity {
|
||||
case R.id.action_quit:
|
||||
GBApplication.deviceService().quit();
|
||||
|
||||
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
|
||||
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
|
||||
return true;
|
||||
case R.id.action_discover:
|
||||
|
@ -53,7 +53,7 @@ public class DebugActivity extends Activity {
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ControlCenter.ACTION_QUIT)) {
|
||||
if (intent.getAction().equals(GBApplication.ACTION_QUIT)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class DebugActivity extends Activity {
|
||||
setContentView(R.layout.activity_debug);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
registerReceiver(mReceiver, new IntentFilter(ControlCenter.ACTION_QUIT));
|
||||
registerReceiver(mReceiver, new IntentFilter(GBApplication.ACTION_QUIT));
|
||||
|
||||
editContent = (EditText) findViewById(R.id.editContent);
|
||||
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
||||
|
@ -49,7 +49,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ControlCenter.ACTION_QUIT)) {
|
||||
if (action.equals(GBApplication.ACTION_QUIT)) {
|
||||
finish();
|
||||
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
||||
device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
@ -116,7 +116,7 @@ public class FwAppInstallerActivity extends Activity implements InstallActivity
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.installProgressBar);
|
||||
setInstallEnabled(false);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(GBApplication.ACTION_QUIT);
|
||||
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
||||
|
||||
|
@ -32,7 +32,6 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
@ -85,7 +84,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case ControlCenter.ACTION_QUIT:
|
||||
case GBApplication.ACTION_QUIT:
|
||||
finish();
|
||||
break;
|
||||
case GBDevice.ACTION_DEVICE_CHANGED:
|
||||
@ -119,7 +118,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
initDates();
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ControlCenter.ACTION_QUIT);
|
||||
filterLocal.addAction(GBApplication.ACTION_QUIT);
|
||||
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class BluetoothStateChangeReceiver extends BroadcastReceiver {
|
||||
} else if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
|
||||
GBApplication.deviceService().quit();
|
||||
|
||||
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
|
||||
Intent quitIntent = new Intent(GBApplication.ACTION_QUIT);
|
||||
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(quitIntent);
|
||||
}
|
||||
|
@ -266,6 +266,12 @@ public class GB {
|
||||
return nb.build();
|
||||
}
|
||||
|
||||
public static void removeAllNotifications(Context context) {
|
||||
removeNotification(NOTIFICATION_ID_TRANSFER, context);
|
||||
removeNotification(NOTIFICATION_ID_INSTALL, context);
|
||||
removeNotification(NOTIFICATION_ID_LOW_BATTERY, context);
|
||||
}
|
||||
|
||||
public static void updateTransferNotification(String text, boolean ongoing, int percentage, Context context) {
|
||||
if (percentage == 100) {
|
||||
removeNotification(NOTIFICATION_ID_TRANSFER, context);
|
||||
|
Loading…
Reference in New Issue
Block a user