diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index 31e4e3e9e..94a980ce5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -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 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(); } diff --git a/app/src/main/res/xml/devicesettings_fake_timeoffset.xml b/app/src/main/res/xml/devicesettings_fake_timeoffset.xml index 319f146f8..7f603d6f5 100644 --- a/app/src/main/res/xml/devicesettings_fake_timeoffset.xml +++ b/app/src/main/res/xml/devicesettings_fake_timeoffset.xml @@ -2,6 +2,7 @@