From a490e9f55542b02a6c87aae997dc2423be30e720 Mon Sep 17 00:00:00 2001 From: vanous Date: Sat, 6 Nov 2021 10:07:16 +0100 Subject: [PATCH] Galaxy Buds: migrate ambient volume preference to SeekBar - more unique detection of the original Buds series - always bond --- .../gadgetbridge/GBApplication.java | 24 ++++++++++++++++++- .../GalaxyBudsDeviceCoordinator.java | 7 +++++- .../galaxy_buds/GalaxyBudsProtocol.java | 4 ++-- app/src/main/res/values/arrays.xml | 8 ------- .../res/xml/devicesettings_galaxy_buds.xml | 9 ++++--- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index b5de8a6d1..1b95e6d4d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -58,6 +58,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.DBOpenHelper; @@ -82,6 +83,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITBIP; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR2; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.GALAXY_BUDS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3; @@ -107,7 +109,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 = 9; + private static final int CURRENT_PREFS_VERSION = 10; private static LimitedQueue mIDSenderLookup = new LimitedQueue(16); private static Prefs prefs; @@ -945,7 +947,27 @@ public class GBApplication extends Application { Log.w(TAG, "error acquiring DB lock and migrating prefs"); } } + if (oldVersion < 10) { + //migrate the string version of pref_galaxy_buds_ambient_volume to int due to transition to SeekBarPreference + try (DBHandler db = acquireDB()) { + DaoSession daoSession = db.getDaoSession(); + List activeDevices = DBHelper.getActiveDevices(daoSession); + for (Device dbDevice : activeDevices) { + SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier()); + SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit(); + DeviceType deviceType = fromKey(dbDevice.getType()); + if (deviceType == GALAXY_BUDS) { + GB.log("migrating Galaxy Buds volume", GB.INFO, null); + String volume = deviceSharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME, "1"); + deviceSharedPrefsEdit.putInt(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME, Integer.parseInt(volume)); + } + deviceSharedPrefsEdit.apply(); + } + } 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/galaxy_buds/GalaxyBudsDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java index c3bdefa4e..2149a3d97 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/galaxy_buds/GalaxyBudsDeviceCoordinator.java @@ -29,7 +29,7 @@ public class GalaxyBudsDeviceCoordinator extends AbstractDeviceCoordinator { String name = candidate.getName(); if (name != null && ( - name.startsWith("Galaxy Buds") + name.startsWith("Galaxy Buds (") )) { return DeviceType.GALAXY_BUDS; } @@ -53,6 +53,11 @@ public class GalaxyBudsDeviceCoordinator extends AbstractDeviceCoordinator { return new BatteryConfig[]{battery1, battery2}; } + @Override + public int getBondingStyle() { + return BONDING_STYLE_BOND; + } + @Nullable @Override public Class getPairingActivity() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/galaxy_buds/GalaxyBudsProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/galaxy_buds/GalaxyBudsProtocol.java index 4ea8957a7..8288fa0b8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/galaxy_buds/GalaxyBudsProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/galaxy_buds/GalaxyBudsProtocol.java @@ -178,8 +178,8 @@ public class GalaxyBudsProtocol extends GBDeviceProtocol { byte enable_voice = (byte) (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOICE_FOCUS, false) ? 0x01 : 0x00); return encodeMessage(set_ambient_voice_focus, enable_voice); case DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME: - String ambient_volume = prefs.getString(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME, "1"); - byte ambient_volume_byte = (byte) Integer.parseInt(ambient_volume); + int ambient_volume = prefs.getInt(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_AMBIENT_VOLUME, 0); + byte ambient_volume_byte = (byte) (ambient_volume + 1); //seek bar is 0-4, we need 1-5 return encodeMessage(set_ambient_volume, ambient_volume_byte); case DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_LOCK_TOUCH: byte set_lock = (byte) (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_GALAXY_BUDS_LOCK_TOUCH, false) ? 0x01 : 0x00); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index ac55e397d..b869cdd50 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -1795,14 +1795,6 @@ false - - 1 - 2 - 3 - 4 - 5 - - @string/pref_title_equalizer_bass_boost @string/pref_title_equalizer_soft diff --git a/app/src/main/res/xml/devicesettings_galaxy_buds.xml b/app/src/main/res/xml/devicesettings_galaxy_buds.xml index 6bec0d7ed..a86a87a72 100644 --- a/app/src/main/res/xml/devicesettings_galaxy_buds.xml +++ b/app/src/main/res/xml/devicesettings_galaxy_buds.xml @@ -20,13 +20,12 @@ android:key="pref_galaxy_buds_ambient_voice_focus" android:summary="@string/prefs_ambient_voice_summary" android:title="@string/prefs_ambient_voice_focus" /> -