1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Mi Band HRX: added DeviceType for Mi Band HRX

Mi Band HRX: changed DeviceType key for MIBAND_HRX

Mi Band HRX: added migration to MIBAND_HRX

Mi Band HRX: added devicetype string for MIBAND_HRX

Huami HRX: removed redundant null check

Huami HRX: removed redundant supports callback
This commit is contained in:
Daniel Dakhno 2023-08-27 23:47:19 +02:00 committed by José Rebelo
parent b8912976f1
commit 8c48a49d3a
6 changed files with 32 additions and 12 deletions

View File

@ -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.LEFUN;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2; 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.MIBAND3;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.PEBBLE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.PEBBLE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.TLW64; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.TLW64;
@ -119,7 +120,7 @@ public class GBApplication extends Application {
private static SharedPreferences sharedPrefs; private static SharedPreferences sharedPrefs;
private static final String PREFS_VERSION = "shared_preferences_version"; 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 //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 LimitedQueue mIDSenderLookup = new LimitedQueue(16);
private static Prefs prefs; 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_start", prefs.getString("disconnect_notification_start", "8:00"));
deviceSharedPrefsEdit.putString("disconnect_notification_end", prefs.getString("disconnect_notification_end", "22: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", 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_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")); 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); displayItems = prefs.getStringSet("bip_display_items", null);
break; break;
case MIBAND2: case MIBAND2:
case MIBAND2_HRX:
displayItems = prefs.getStringSet("mi2_display_items", null); displayItems = prefs.getStringSet("mi2_display_items", null);
deviceSharedPrefsEdit.putBoolean("mi2_enable_text_notifications", prefs.getBoolean("mi2_enable_text_notifications", true)); deviceSharedPrefsEdit.putBoolean("mi2_enable_text_notifications", prefs.getBoolean("mi2_enable_text_notifications", true));
deviceSharedPrefsEdit.putString("mi2_dateformat", prefs.getString("mi2_dateformat", "dateformat_time")); deviceSharedPrefsEdit.putString("mi2_dateformat", prefs.getString("mi2_dateformat", "dateformat_time"));
@ -854,6 +856,7 @@ public class GBApplication extends Application {
case AMAZFITCOR2: case AMAZFITCOR2:
case MIBAND: case MIBAND:
case MIBAND2: case MIBAND2:
case MIBAND2_HRX:
case MIBAND3: case MIBAND3:
case MIBAND4: case MIBAND4:
newWearside = prefs.getString("mi_wearside", "left"); 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<Device> 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.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
editor.apply(); editor.apply();
} }

View File

@ -117,6 +117,6 @@ public class MiBand2FWInstallHandler extends AbstractMiBandFWInstallHandler {
@Override @Override
protected boolean isSupportedDeviceType(GBDevice device) { protected boolean isSupportedDeviceType(GBDevice device) {
return device.getType() == DeviceType.MIBAND2; return device.getType() == DeviceType.MIBAND2 || device.getType() == DeviceType.MIBAND2_HRX;
} }
} }

View File

@ -44,7 +44,7 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
@Override @Override
public DeviceType getDeviceType() { public DeviceType getDeviceType() {
return DeviceType.MIBAND2; return DeviceType.MIBAND2_HRX;
} }
@NonNull @NonNull
@ -53,8 +53,8 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
try { try {
BluetoothDevice device = candidate.getDevice(); BluetoothDevice device = candidate.getDevice();
String name = device.getName(); String name = device.getName();
if (name != null && (name.equalsIgnoreCase(HuamiConst.MI_BAND2_NAME_HRX) || name.equalsIgnoreCase("Mi Band 2i"))) { if (HuamiConst.MI_BAND2_NAME_HRX.equalsIgnoreCase(name) || "Mi Band 2i".equalsIgnoreCase(name)) {
return DeviceType.MIBAND2; return DeviceType.MIBAND2_HRX;
} }
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("unable to check device support", ex); LOG.error("unable to check device support", ex);
@ -62,11 +62,6 @@ public class MiBand2HRXCoordinator extends HuamiCoordinator {
return DeviceType.UNKNOWN; return DeviceType.UNKNOWN;
} }
@Override
public boolean supports(GBDevice device) {
return getDeviceType().equals(device.getType()) && device.getName().equals("Mi Band HRX");
}
@Override @Override
public InstallHandler findInstallHandler(Uri uri, Context context) { public InstallHandler findInstallHandler(Uri uri, Context context) {
return null; return null;

View File

@ -37,6 +37,7 @@ public enum DeviceType {
PEBBLE(1, R.drawable.ic_device_pebble, R.drawable.ic_device_pebble_disabled, R.string.devicetype_pebble), 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), 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(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), 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), 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), MIBAND3(14, R.drawable.ic_device_miband2, R.drawable.ic_device_miband2_disabled, R.string.devicetype_miband3),

View File

@ -93,7 +93,7 @@ public class Mi2FirmwareInfo extends HuamiFirmwareInfo {
} }
public boolean isGenerallyCompatibleWith(GBDevice device) { public boolean isGenerallyCompatibleWith(GBDevice device) {
return isHeaderValid() && device.getType() == DeviceType.MIBAND2; return isHeaderValid() && (device.getType() == DeviceType.MIBAND2 || device.getType() == DeviceType.MIBAND2_HRX);
} }
protected Map<Integer, String> getCrcMap() { protected Map<Integer, String> getCrcMap() {

View File

@ -2263,4 +2263,5 @@
<string name="error_menu_companion_not_installed">\'HR Menu Companion\' probably not installed</string> <string name="error_menu_companion_not_installed">\'HR Menu Companion\' probably not installed</string>
<string name="info_menu_structure_contents">Menu structure: %s</string> <string name="info_menu_structure_contents">Menu structure: %s</string>
<string name="info_fossil_rebuild_watchface_custom_menu">Please rebuild your watchface for custom menu</string> <string name="info_fossil_rebuild_watchface_custom_menu">Please rebuild your watchface for custom menu</string>
<string name="devicetype_miband2_hrx">Mi Band HRX</string>
</resources> </resources>