Browse Source

Fix crash when entering Mi Band 1 per-device settings menu

Fixes #1541
tags/0.34.1
Andreas Shimokawa 3 months ago
parent
commit
8fce521e99

+ 22
- 1
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java View File

@@ -78,6 +78,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.MIBAND;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
@@ -98,7 +99,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 = 3;
private static final int CURRENT_PREFS_VERSION = 4;
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
private static Prefs prefs;
private static GBPrefs gbPrefs;
@@ -739,6 +740,26 @@ public class GBApplication extends Application {
Log.w(TAG, "error acquiring DB lock");
}
}
if (oldVersion < 4) {
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 == MIBAND) {
int deviceTimeOffsetHours = deviceSharedPrefs.getInt("device_time_offset_hours",0);
deviceSharedPrefsEdit.putString("device_time_offset_hours", Integer.toString(deviceTimeOffsetHours) );
}

deviceSharedPrefsEdit.apply();
}
} catch (Exception e) {
Log.w(TAG, "error acquiring DB lock");
}
}
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
editor.apply();
}

+ 1
- 0
app/src/main/res/xml/devicesettings_fake_timeoffset.xml View File

@@ -2,6 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:defaultValue="0"
android:inputType="number"
android:key="device_time_offset_hours"
android:maxLength="2"
android:title="@string/miband_prefs_device_time_offset_hours" />

Loading…
Cancel
Save