From 975b6985646d2a4f11f6511fae2f49345997f9bc Mon Sep 17 00:00:00 2001 From: vanous Date: Wed, 4 Sep 2019 21:29:56 +0200 Subject: [PATCH] remove preference keys when deleting device --- .../devices/AbstractDeviceCoordinator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java index d1466f573..37de052ab 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/AbstractDeviceCoordinator.java @@ -33,11 +33,14 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; +import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; +import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getPrefs; public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceCoordinator.class); @@ -69,6 +72,15 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator { if (gbDevice.isConnected() || gbDevice.isConnecting()) { GBApplication.deviceService().disconnect(); } + Prefs prefs = getPrefs(); + String lastDevice = prefs.getPreferences().getString("last_device_address",""); + if (gbDevice.getAddress() == lastDevice){ + prefs.getPreferences().edit().remove("last_device_address"); + } + String macAddress = prefs.getPreferences().getString(MiBandConst.PREF_MIBAND_ADDRESS,""); + if (gbDevice.getAddress() == macAddress){ + prefs.getPreferences().edit().remove(MiBandConst.PREF_MIBAND_ADDRESS); + } try (DBHandler dbHandler = GBApplication.acquireDB()) { DaoSession session = dbHandler.getDaoSession(); Device device = DBHelper.findDevice(gbDevice, session);