Free as in Freedom: Codeberg.org. Create your repos!
Browse Source

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

Fixes #1541
tags/0.34.1
Andreas Shimokawa 4 weeks 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;
78 78
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITBIP;
79 79
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR;
80 80
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR2;
81
+import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND;
81 82
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2;
82 83
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3;
83 84
 import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
@@ -98,7 +99,7 @@ public class GBApplication extends Application {
98 99
     private static SharedPreferences sharedPrefs;
99 100
     private static final String PREFS_VERSION = "shared_preferences_version";
100 101
     //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
101
-    private static final int CURRENT_PREFS_VERSION = 3;
102
+    private static final int CURRENT_PREFS_VERSION = 4;
102 103
     private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
103 104
     private static Prefs prefs;
104 105
     private static GBPrefs gbPrefs;
@@ -739,6 +740,26 @@ public class GBApplication extends Application {
739 740
                 Log.w(TAG, "error acquiring DB lock");
740 741
             }
741 742
         }
743
+        if (oldVersion < 4) {
744
+            try (DBHandler db = acquireDB()) {
745
+                DaoSession daoSession = db.getDaoSession();
746
+                List<Device> activeDevices = DBHelper.getActiveDevices(daoSession);
747
+                for (Device dbDevice : activeDevices) {
748
+                    SharedPreferences deviceSharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(dbDevice.getIdentifier());
749
+                    SharedPreferences.Editor deviceSharedPrefsEdit = deviceSharedPrefs.edit();
750
+                    DeviceType deviceType = fromKey(dbDevice.getType());
751
+
752
+                    if (deviceType == MIBAND) {
753
+                        int deviceTimeOffsetHours = deviceSharedPrefs.getInt("device_time_offset_hours",0);
754
+                        deviceSharedPrefsEdit.putString("device_time_offset_hours", Integer.toString(deviceTimeOffsetHours) );
755
+                    }
756
+
757
+                    deviceSharedPrefsEdit.apply();
758
+                }
759
+            } catch (Exception e) {
760
+                Log.w(TAG, "error acquiring DB lock");
761
+            }
762
+        }
742 763
         editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
743 764
         editor.apply();
744 765
     }

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

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

Loading…
Cancel
Save