1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 19:36:50 +01:00

Galaxy Buds: migrate ambient volume preference to SeekBar

- more unique detection of the original Buds series
- always bond
This commit is contained in:
vanous 2021-11-06 10:07:16 +01:00
parent 77cf6f8ba4
commit a490e9f555
5 changed files with 35 additions and 17 deletions

View File

@ -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<Device> 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();
}

View File

@ -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<? extends Activity> getPairingActivity() {

View File

@ -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);

View File

@ -1795,14 +1795,6 @@
<item>false</item>
</string-array>
<string-array name="ambient_volume_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>
<string-array name="galaxy_eqalizer_modes">
<item>@string/pref_title_equalizer_bass_boost</item>
<item>@string/pref_title_equalizer_soft</item>

View File

@ -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" />
<ListPreference
android:dependency="pref_galaxy_buds_ambient_mode"
android:entries="@array/ambient_volume_values"
android:entryValues="@array/ambient_volume_values"
<SeekBarPreference
android:icon="@drawable/ic_volume_up"
android:key="pref_galaxy_buds_ambient_volume"
android:summary="%s"
android:max="4"
android:min="1"
android:title="@string/prefs_ambient_volume" />
</PreferenceCategory>
</PreferenceScreen>