diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 0812bad74..db06324c2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -92,6 +92,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.GALAXY_BUDS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.LEFUN; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2_HRX; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.PEBBLE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.TLW64; @@ -119,7 +120,7 @@ public class GBApplication extends Application { private static SharedPreferences sharedPrefs; private static final String PREFS_VERSION = "shared_preferences_version"; //if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version - private static final int CURRENT_PREFS_VERSION = 21; + private static final int CURRENT_PREFS_VERSION = 22; private static LimitedQueue mIDSenderLookup = new LimitedQueue(16); private static Prefs prefs; @@ -741,7 +742,7 @@ public class GBApplication extends Application { deviceSharedPrefsEdit.putString("disconnect_notification_start", prefs.getString("disconnect_notification_start", "8:00")); deviceSharedPrefsEdit.putString("disconnect_notification_end", prefs.getString("disconnect_notification_end", "22:00")); } - if (deviceType == MIBAND2 || deviceType == MIBAND3) { + if (deviceType == MIBAND2 || deviceType == MIBAND2_HRX || deviceType == MIBAND3) { deviceSharedPrefsEdit.putString("do_not_disturb", prefs.getString("mi2_do_not_disturb", "off")); deviceSharedPrefsEdit.putString("do_not_disturb_start", prefs.getString("mi2_do_not_disturb_start", "1:00")); deviceSharedPrefsEdit.putString("do_not_disturb_end", prefs.getString("mi2_do_not_disturb_end", "6:00")); @@ -763,6 +764,7 @@ public class GBApplication extends Application { displayItems = prefs.getStringSet("bip_display_items", null); break; case MIBAND2: + case MIBAND2_HRX: displayItems = prefs.getStringSet("mi2_display_items", null); deviceSharedPrefsEdit.putBoolean("mi2_enable_text_notifications", prefs.getBoolean("mi2_enable_text_notifications", true)); deviceSharedPrefsEdit.putString("mi2_dateformat", prefs.getString("mi2_dateformat", "dateformat_time")); @@ -854,6 +856,7 @@ public class GBApplication extends Application { case AMAZFITCOR2: case MIBAND: case MIBAND2: + case MIBAND2_HRX: case MIBAND3: case MIBAND4: newWearside = prefs.getString("mi_wearside", "left"); @@ -1269,6 +1272,26 @@ public class GBApplication extends Application { } } + if (oldVersion < 22) { + try (DBHandler db = acquireDB()) { + final DaoSession daoSession = db.getDaoSession(); + final List activeDevices = DBHelper.getActiveDevices(daoSession); + + for (Device dbDevice : activeDevices) { + final DeviceType deviceType = fromKey(dbDevice.getType()); + if (deviceType == MIBAND2) { + final String name = dbDevice.getName(); + if ("Mi Band HRX".equalsIgnoreCase(name) || "Mi Band 2i".equalsIgnoreCase(name)) { + dbDevice.setType(DeviceType.MIBAND2_HRX.getKey()); + daoSession.getDeviceDao().update(dbDevice); + } + } + } + } catch (Exception e) { + Log.w(TAG, "error acquiring DB lock"); + } + } + editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION)); editor.apply(); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2FWInstallHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2FWInstallHandler.java index 2df40f003..7f3074995 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2FWInstallHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2FWInstallHandler.java @@ -117,6 +117,6 @@ public class MiBand2FWInstallHandler extends AbstractMiBandFWInstallHandler { @Override protected boolean isSupportedDeviceType(GBDevice device) { - return device.getType() == DeviceType.MIBAND2; + return device.getType() == DeviceType.MIBAND2 || device.getType() == DeviceType.MIBAND2_HRX; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java index ed2052d2d..79473bf33 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2HRXCoordinator.java @@ -44,7 +44,7 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator { @Override public DeviceType getDeviceType() { - return DeviceType.MIBAND2; + return DeviceType.MIBAND2_HRX; } @NonNull @@ -53,8 +53,8 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator { try { BluetoothDevice device = candidate.getDevice(); String name = device.getName(); - if (name != null && (name.equalsIgnoreCase(HuamiConst.MI_BAND2_NAME_HRX) || name.equalsIgnoreCase("Mi Band 2i"))) { - return DeviceType.MIBAND2; + if (HuamiConst.MI_BAND2_NAME_HRX.equalsIgnoreCase(name) || "Mi Band 2i".equalsIgnoreCase(name)) { + return DeviceType.MIBAND2_HRX; } } catch (Exception ex) { LOG.error("unable to check device support", ex); @@ -62,11 +62,6 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator { return DeviceType.UNKNOWN; } - @Override - public boolean supports(GBDevice device) { - return getDeviceType().equals(device.getType()) && device.getName().equals("Mi Band HRX"); - } - @Override public InstallHandler findInstallHandler(Uri uri, Context context) { return null; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java index 93976d158..ad5691d18 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java @@ -37,6 +37,7 @@ public enum DeviceType { PEBBLE(1, R.drawable.ic_device_pebble, R.drawable.ic_device_pebble_disabled, R.string.devicetype_pebble), MIBAND(10, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled, R.string.devicetype_miband), MIBAND2(11, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_miband2), + MIBAND2_HRX(1001, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_miband2_hrx), AMAZFITBIP(12, R.drawable.ic_device_amazfit_bip, R.drawable.ic_device_amazfit_bip_disabled, R.string.devicetype_amazfit_bip), AMAZFITCOR(13, R.drawable.ic_device_default, R.drawable.ic_device_default_disabled, R.string.devicetype_amazfit_cor), MIBAND3(14, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_miband3), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband2/Mi2FirmwareInfo.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband2/Mi2FirmwareInfo.java index 83b1b71fa..8df70f978 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband2/Mi2FirmwareInfo.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband2/Mi2FirmwareInfo.java @@ -93,7 +93,7 @@ public class Mi2FirmwareInfo extends HuamiFirmwareInfo { } public boolean isGenerallyCompatibleWith(GBDevice device) { - return isHeaderValid() && device.getType() == DeviceType.MIBAND2; + return isHeaderValid() && (device.getType() == DeviceType.MIBAND2 || device.getType() == DeviceType.MIBAND2_HRX); } protected Map getCrcMap() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 20b13e206..669d78f40 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2263,4 +2263,5 @@ \'HR Menu Companion\' probably not installed Menu structure: %s Please rebuild your watchface for custom menu + Mi Band HRX