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

Move "activate display on lift wrist" and "rotate wrist to switch info" to per-device settings

"activate display on lift wrist" for Mi Band 2/3, Cor, Bip
"rotate wrist" only for Mi Band 2
tags/0.34.0
Andreas Shimokawa 1 month ago
parent
commit
d779310962

+ 23
- 11
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java View File

@@ -193,9 +193,9 @@ public class GBApplication extends Application {
193 193
         if (isRunningMarshmallowOrLater()) {
194 194
             notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
195 195
             //the following will ensure the notification manager is kept alive
196
-            if(isRunningOreoOrLater()) {
196
+            if (isRunningOreoOrLater()) {
197 197
                 NotificationChannel channel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
198
-                if(channel == null) {
198
+                if (channel == null) {
199 199
                     channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
200 200
                             getString(R.string.notification_channel_name),
201 201
                             NotificationManager.IMPORTANCE_LOW);
@@ -238,7 +238,7 @@ public class GBApplication extends Application {
238 238
         logging.setupLogging(enabled);
239 239
     }
240 240
 
241
-    public static String getLogPath(){
241
+    public static String getLogPath() {
242 242
         return logging.getLogPath();
243 243
     }
244 244
 
@@ -326,11 +326,12 @@ public class GBApplication extends Application {
326 326
     public static boolean isRunningMarshmallowOrLater() {
327 327
         return VERSION.SDK_INT >= Build.VERSION_CODES.M;
328 328
     }
329
+
329 330
     public static boolean isRunningNougatOrLater() {
330 331
         return VERSION.SDK_INT >= Build.VERSION_CODES.N;
331 332
     }
332 333
 
333
-    public static boolean isRunningOreoOrLater(){
334
+    public static boolean isRunningOreoOrLater() {
334 335
         return VERSION.SDK_INT >= Build.VERSION_CODES.O;
335 336
     }
336 337
 
@@ -491,14 +492,14 @@ public class GBApplication extends Application {
491 492
         saveAppsPebbleBlackList();
492 493
     }
493 494
 
494
-public static String packageNameToPebbleMsgSender(String packageName) {
495
-    if ("eu.siacs.conversations".equals(packageName)){
496
-        return("Conversations");
497
-    } else if ("net.osmand.plus".equals(packageName)) {
498
-        return("OsmAnd");
495
+    public static String packageNameToPebbleMsgSender(String packageName) {
496
+        if ("eu.siacs.conversations".equals(packageName)) {
497
+            return ("Conversations");
498
+        } else if ("net.osmand.plus".equals(packageName)) {
499
+            return ("OsmAnd");
500
+        }
501
+        return packageName;
499 502
     }
500
-    return packageName;
501
-}
502 503
 
503 504
     private static HashSet<String> calendars_blacklist = null;
504 505
 
@@ -668,6 +669,11 @@ public static String packageNameToPebbleMsgSender(String packageName) {
668 669
                             deviceSharedPrefsEdit.putString("do_not_disturb_start", prefs.getString("mi2_do_not_disturb_start", "1:00"));
669 670
                             deviceSharedPrefsEdit.putString("do_not_disturb_end", prefs.getString("mi2_do_not_disturb_end", "6:00"));
670 671
                         }
672
+                        if (dbDevice.getManufacturer().equals("Huami")) {
673
+                            deviceSharedPrefsEdit.putString("activate_display_on_lift_wrist", prefs.getString("activate_display_on_lift_wrist", "off"));
674
+                            deviceSharedPrefsEdit.putString("display_on_lift_start", prefs.getString("display_on_lift_start", "0:00"));
675
+                            deviceSharedPrefsEdit.putString("display_on_lift_end", prefs.getString("display_on_lift_end", "0:00"));
676
+                        }
671 677
                         switch (deviceType) {
672 678
                             case MIBAND:
673 679
                                 deviceSharedPrefsEdit.putBoolean("low_latency_fw_update", prefs.getBoolean("mi_low_latency_fw_update", true));
@@ -683,6 +689,7 @@ public static String packageNameToPebbleMsgSender(String packageName) {
683 689
                                 displayItems = prefs.getStringSet("mi2_display_items", null);
684 690
                                 deviceSharedPrefsEdit.putBoolean("mi2_enable_text_notifications", prefs.getBoolean("mi2_enable_text_notifications", true));
685 691
                                 deviceSharedPrefsEdit.putString("mi2_dateformat", prefs.getString("mi2_dateformat", "dateformat_time"));
692
+                                deviceSharedPrefsEdit.putBoolean("rotate_wrist_to_cycle_info", prefs.getBoolean("mi2_rotate_wrist_to_switch_info", false));
686 693
                                 break;
687 694
                             case MIBAND3:
688 695
                                 newLanguage = prefs.getString("miband3_language", "auto");
@@ -709,6 +716,10 @@ public static String packageNameToPebbleMsgSender(String packageName) {
709 716
                 editor.remove("disconnect_notification");
710 717
                 editor.remove("disconnect_notification_start");
711 718
                 editor.remove("disconnect_notification_end");
719
+                editor.remove("activate_display_on_lift_wrist");
720
+                editor.remove("display_on_lift_start");
721
+                editor.remove("display_on_lift_end");
722
+
712 723
                 editor.remove("mi_low_latency_fw_update");
713 724
                 editor.remove("mi_device_time_offset_hours");
714 725
                 editor.remove("mi2_do_not_disturb");
@@ -716,6 +727,7 @@ public static String packageNameToPebbleMsgSender(String packageName) {
716 727
                 editor.remove("mi2_do_not_disturb_end");
717 728
                 editor.remove("mi2_dateformat");
718 729
                 editor.remove("mi2_display_items");
730
+                editor.remove("mi2_rotate_wrist_to_switch_info");
719 731
                 editor.remove("mi2_enable_text_notifications");
720 732
                 editor.remove("mi3_band_screen_unlock");
721 733
                 editor.remove("mi3_night_mode");

+ 97
- 8
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java View File

@@ -10,6 +10,11 @@ import androidx.preference.EditTextPreference;
10 10
 import androidx.preference.Preference;
11 11
 import androidx.preference.PreferenceFragmentCompat;
12 12
 
13
+import org.slf4j.Logger;
14
+import org.slf4j.LoggerFactory;
15
+
16
+import java.util.Objects;
17
+
13 18
 import nodomain.freeyourgadget.gadgetbridge.GBApplication;
14 19
 import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
15 20
 import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
@@ -17,15 +22,19 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
17 22
 import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference;
18 23
 import nodomain.freeyourgadget.gadgetbridge.util.XTimePreferenceFragment;
19 24
 
25
+import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT;
20 26
 import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION;
21 27
 import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END;
22 28
 import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_START;
29
+import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
30
+import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
23 31
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
24 32
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
25 33
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
26 34
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED;
27 35
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_START;
28 36
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
37
+import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
29 38
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE;
30 39
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_END;
31 40
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_OFF;
@@ -35,6 +44,8 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
35 44
 
36 45
 public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
37 46
 
47
+    private static final Logger LOG = LoggerFactory.getLogger(DeviceSpecificSettingsFragment.class);
48
+
38 49
     static final String FRAGMENT_TAG = "DEVICE_SPECIFIC_SETTINGS_FRAGMENT";
39 50
 
40 51
     private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings) {
@@ -137,8 +148,8 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
137 148
                 public boolean onPreferenceChange(Preference preference, Object newVal) {
138 149
                     final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
139 150
 
140
-                    disconnectNotificationStart.setEnabled(scheduled);
141
-                    disconnectNotificationEnd.setEnabled(scheduled);
151
+                    Objects.requireNonNull(disconnectNotificationStart).setEnabled(scheduled);
152
+                    Objects.requireNonNull(disconnectNotificationEnd).setEnabled(scheduled);
142 153
                     invokeLater(new Runnable() {
143 154
                         @Override
144 155
                         public void run() {
@@ -196,8 +207,8 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
196 207
                 public boolean onPreferenceChange(Preference preference, Object newVal) {
197 208
                     final boolean scheduled = PREF_NIGHT_MODE_SCHEDULED.equals(newVal.toString());
198 209
 
199
-                    nightModeStart.setEnabled(scheduled);
200
-                    nightModeEnd.setEnabled(scheduled);
210
+                    Objects.requireNonNull(nightModeStart).setEnabled(scheduled);
211
+                    Objects.requireNonNull(nightModeEnd).setEnabled(scheduled);
201 212
 
202 213
                     invokeLater(new Runnable() {
203 214
                         @Override
@@ -255,8 +266,8 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
255 266
                 public boolean onPreferenceChange(Preference preference, Object newVal) {
256 267
                     final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
257 268
 
258
-                    doNotDisturbStart.setEnabled(scheduled);
259
-                    doNotDisturbEnd.setEnabled(scheduled);
269
+                    Objects.requireNonNull(doNotDisturbStart).setEnabled(scheduled);
270
+                    Objects.requireNonNull(doNotDisturbEnd).setEnabled(scheduled);
260 271
 
261 272
                     invokeLater(new Runnable() {
262 273
                         @Override
@@ -273,6 +284,82 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
273 284
         addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
274 285
         addPreferenceHandlerFor(HuamiConst.PREF_DISPLAY_ITEMS);
275 286
 
287
+        String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
288
+        boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
289
+
290
+        final Preference rotateWristCycleInfo = findPreference(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
291
+        if (rotateWristCycleInfo != null) {
292
+            rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(displayOnLiftState));
293
+            rotateWristCycleInfo.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
294
+                @Override
295
+                public boolean onPreferenceChange(Preference preference, Object newVal) {
296
+                    invokeLater(new Runnable() {
297
+                        @Override
298
+                        public void run() {
299
+                            GBApplication.deviceService().onSendConfiguration(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
300
+                        }
301
+                    });
302
+                    return true;
303
+                }
304
+            });
305
+        }
306
+
307
+        final Preference displayOnLiftStart = findPreference(PREF_DISPLAY_ON_LIFT_START);
308
+        if (displayOnLiftStart != null) {
309
+            displayOnLiftStart.setEnabled(displayOnLiftScheduled);
310
+            displayOnLiftStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
311
+                @Override
312
+                public boolean onPreferenceChange(Preference preference, Object newVal) {
313
+                    invokeLater(new Runnable() {
314
+                        @Override
315
+                        public void run() {
316
+                            GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_START);
317
+                        }
318
+                    });
319
+                    return true;
320
+                }
321
+            });
322
+        }
323
+
324
+        final Preference displayOnLiftEnd = findPreference(PREF_DISPLAY_ON_LIFT_END);
325
+        if (displayOnLiftEnd != null) {
326
+            displayOnLiftEnd.setEnabled(displayOnLiftScheduled);
327
+            displayOnLiftEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
328
+                @Override
329
+                public boolean onPreferenceChange(Preference preference, Object newVal) {
330
+                    invokeLater(new Runnable() {
331
+                        @Override
332
+                        public void run() {
333
+                            GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_END);
334
+                        }
335
+                    });
336
+                    return true;
337
+                }
338
+            });
339
+        }
340
+
341
+        final Preference displayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
342
+        if (displayOnLift != null) {
343
+            displayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
344
+                @Override
345
+                public boolean onPreferenceChange(Preference preference, Object newVal) {
346
+                    final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
347
+                    Objects.requireNonNull(displayOnLiftStart).setEnabled(scheduled);
348
+                    Objects.requireNonNull(displayOnLiftEnd).setEnabled(scheduled);
349
+                    if (rotateWristCycleInfo != null) {
350
+                        rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(newVal.toString()));
351
+                    }
352
+                    invokeLater(new Runnable() {
353
+                        @Override
354
+                        public void run() {
355
+                            GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
356
+                        }
357
+                    });
358
+                    return true;
359
+                }
360
+            });
361
+        }
362
+
276 363
         EditTextPreference pref = findPreference(MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS);
277 364
         if (pref != null) {
278 365
             pref.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@@ -293,14 +380,16 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
293 380
 
294 381
     @Override
295 382
     public void onDisplayPreferenceDialog(Preference preference) {
296
-        DialogFragment dialogFragment = null;
383
+        DialogFragment dialogFragment;
297 384
         if (preference instanceof XTimePreference) {
298 385
             dialogFragment = new XTimePreferenceFragment();
299 386
             Bundle bundle = new Bundle(1);
300 387
             bundle.putString("key", preference.getKey());
301 388
             dialogFragment.setArguments(bundle);
302 389
             dialogFragment.setTargetFragment(this, 0);
303
-            dialogFragment.show(getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
390
+            if (getFragmentManager() != null) {
391
+                dialogFragment.show(getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
392
+            }
304 393
         } else {
305 394
             super.onDisplayPreferenceDialog(preference);
306 395
         }

+ 8
- 8
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java View File

@@ -140,8 +140,8 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
140 140
         return DateTimeDisplay.DATE_TIME;
141 141
     }
142 142
 
143
-    public static ActivateDisplayOnLift getActivateDisplayOnLiftWrist(Context context) {
144
-        Prefs prefs = GBApplication.getPrefs();
143
+    public static ActivateDisplayOnLift getActivateDisplayOnLiftWrist(Context context, String deviceAddress) {
144
+        SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
145 145
 
146 146
         String liftOff = context.getString(R.string.p_off);
147 147
         String liftOn = context.getString(R.string.p_on);
@@ -158,12 +158,12 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
158 158
         return ActivateDisplayOnLift.OFF;
159 159
     }
160 160
 
161
-    public static Date getDisplayOnLiftStart() {
162
-        return getTimePreference(HuamiConst.PREF_DISPLAY_ON_LIFT_START, "00:00");
161
+    public static Date getDisplayOnLiftStart(String deviceAddress) {
162
+        return getTimePreference(HuamiConst.PREF_DISPLAY_ON_LIFT_START, "00:00", deviceAddress);
163 163
     }
164 164
 
165
-    public static Date getDisplayOnLiftEnd() {
166
-        return getTimePreference(HuamiConst.PREF_DISPLAY_ON_LIFT_END, "00:00");
165
+    public static Date getDisplayOnLiftEnd(String deviceAddress) {
166
+        return getTimePreference(HuamiConst.PREF_DISPLAY_ON_LIFT_END, "00:00", deviceAddress);
167 167
     }
168 168
 
169 169
     public static DisconnectNotificationSetting getDisconnectNotificationSetting(Context context, String deviceAddress) {
@@ -202,8 +202,8 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
202 202
         return prefs.getBoolean(MiBandConst.PREF_MI2_GOAL_NOTIFICATION, false);
203 203
     }
204 204
 
205
-    public static boolean getRotateWristToSwitchInfo() {
206
-        Prefs prefs = GBApplication.getPrefs();
205
+    public static boolean getRotateWristToSwitchInfo(String deviceAddress) {
206
+        SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
207 207
         return prefs.getBoolean(MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO, false);
208 208
     }
209 209
 

+ 1
- 0
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitbip/AmazfitBipCoordinator.java View File

@@ -81,6 +81,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
81 81
     public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
82 82
         return new int[]{
83 83
                 R.xml.devicesettings_amazfitbip,
84
+                R.xml.devicesettings_liftwrist_display,
84 85
                 R.xml.devicesettings_disconnectnotification,
85 86
                 R.xml.devicesettings_pairingkey
86 87
         };

+ 1
- 0
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitcor/AmazfitCorCoordinator.java View File

@@ -84,6 +84,7 @@ public class AmazfitCorCoordinator extends HuamiCoordinator {
84 84
     public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
85 85
         return new int[]{
86 86
                 R.xml.devicesettings_amazfitcor,
87
+                R.xml.devicesettings_liftwrist_display,
87 88
                 R.xml.devicesettings_disconnectnotification,
88 89
                 R.xml.devicesettings_pairingkey};
89 90
     }

+ 2
- 0
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband2/MiBand2Coordinator.java View File

@@ -85,6 +85,8 @@ public class MiBand2Coordinator extends HuamiCoordinator {
85 85
         return new int[]{
86 86
                 R.xml.devicesettings_miband2,
87 87
                 R.xml.devicesettings_donotdisturb_withauto,
88
+                R.xml.devicesettings_liftwrist_display,
89
+                R.xml.devicesettings_rotatewrist_cycleinfo,
88 90
                 R.xml.devicesettings_pairingkey
89 91
         };
90 92
     }

+ 1
- 0
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/miband3/MiBand3Coordinator.java View File

@@ -105,6 +105,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
105 105
                 R.xml.devicesettings_miband3,
106 106
                 R.xml.devicesettings_nightmode,
107 107
                 R.xml.devicesettings_donotdisturb_withauto,
108
+                R.xml.devicesettings_liftwrist_display,
108 109
                 R.xml.devicesettings_swipeunlock,
109 110
                 R.xml.devicesettings_pairingkey
110 111
         };

+ 1
- 1
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java View File

@@ -48,7 +48,7 @@ public final class MiBandConst {
48 48
 	public static final String PREF_MI2_DISPLAY_ITEM_CALORIES = "calories";
49 49
 	public static final String PREF_MI2_DISPLAY_ITEM_HEART_RATE = "heart_rate";
50 50
 	public static final String PREF_MI2_DISPLAY_ITEM_BATTERY = "battery";
51
-    public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "mi2_rotate_wrist_to_switch_info";
51
+    public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "rotate_wrist_to_cycle_info";
52 52
 	public static final String PREF_MI2_ENABLE_TEXT_NOTIFICATIONS = "mi2_enable_text_notifications";
53 53
     public static final String PREF_DO_NOT_DISTURB = "do_not_disturb";
54 54
     public static final String PREF_DO_NOT_DISTURB_OFF = "off";

+ 0
- 86
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java View File

@@ -41,11 +41,8 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
41 41
 import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
42 42
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_ALARM_CLOCK;
43 43
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL;
44
-import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
45
-import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
46 44
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
47 45
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED;
48
-import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_START;
49 46
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_GOAL_NOTIFICATION;
50 47
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS;
51 48
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND;
@@ -56,7 +53,6 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
56 53
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD;
57 54
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
58 55
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
59
-import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS;
60 56
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR;
61 57
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
62 58
 import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
@@ -106,37 +102,6 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
106 102
             }
107 103
         });
108 104
 
109
-        final Preference activateDisplayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
110
-        activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
111
-            @Override
112
-            public boolean onPreferenceChange(Preference preference, Object newVal) {
113
-                invokeLater(new Runnable() {
114
-                    @Override
115
-                    public void run() {
116
-                        GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
117
-                    }
118
-                });
119
-                return true;
120
-            }
121
-        });
122
-
123
-        String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
124
-        boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
125
-
126
-        final Preference rotateWristCycleInfo = findPreference(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
127
-        rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(displayOnLiftState));
128
-        rotateWristCycleInfo.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
129
-            @Override
130
-            public boolean onPreferenceChange(Preference preference, Object newVal) {
131
-                invokeLater(new Runnable() {
132
-                    @Override
133
-                    public void run() {
134
-                        GBApplication.deviceService().onSendConfiguration(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
135
-                    }
136
-                });
137
-                return true;
138
-            }
139
-        });
140 105
 
141 106
         final Preference inactivityWarnings = findPreference(PREF_MI2_INACTIVITY_WARNINGS);
142 107
         inactivityWarnings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -236,56 +201,6 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
236 201
             }
237 202
         });
238 203
 
239
-        final Preference displayOnLiftStart = findPreference(PREF_DISPLAY_ON_LIFT_START);
240
-        displayOnLiftStart.setEnabled(displayOnLiftScheduled);
241
-        displayOnLiftStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
242
-            @Override
243
-            public boolean onPreferenceChange(Preference preference, Object newVal) {
244
-                invokeLater(new Runnable() {
245
-                    @Override
246
-                    public void run() {
247
-                        GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_START);
248
-                    }
249
-                });
250
-                return true;
251
-            }
252
-        });
253
-
254
-
255
-        final Preference displayOnLiftEnd = findPreference(PREF_DISPLAY_ON_LIFT_END);
256
-        displayOnLiftEnd.setEnabled(displayOnLiftScheduled);
257
-        displayOnLiftEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
258
-            @Override
259
-            public boolean onPreferenceChange(Preference preference, Object newVal) {
260
-                invokeLater(new Runnable() {
261
-                    @Override
262
-                    public void run() {
263
-                        GBApplication.deviceService().onSendConfiguration(PREF_DISPLAY_ON_LIFT_END);
264
-                    }
265
-                });
266
-                return true;
267
-            }
268
-        });
269
-
270
-
271
-        final Preference displayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
272
-        displayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
273
-            @Override
274
-            public boolean onPreferenceChange(Preference preference, Object newVal) {
275
-                final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
276
-
277
-                displayOnLiftStart.setEnabled(scheduled);
278
-                displayOnLiftEnd.setEnabled(scheduled);
279
-                rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(newVal.toString()));
280
-                invokeLater(new Runnable() {
281
-                    @Override
282
-                    public void run() {
283
-                        GBApplication.deviceService().onSendConfiguration(PREF_ACTIVATE_DISPLAY_ON_LIFT);
284
-                    }
285
-                });
286
-                return true;
287
-            }
288
-        });
289 204
 
290 205
         final Preference fitnessGoal = findPreference(ActivityUser.PREF_USER_STEPS_GOAL);
291 206
         fitnessGoal.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -356,7 +271,6 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
356 271
         prefKeys.add(PREF_MIBAND_ADDRESS);
357 272
         prefKeys.add(ActivityUser.PREF_USER_STEPS_GOAL);
358 273
         prefKeys.add(PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR);
359
-        prefKeys.add(PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS);
360 274
         prefKeys.add(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD);
361 275
         prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_ALARM_CLOCK));
362 276
         prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL));

+ 4
- 4
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java View File

@@ -1616,7 +1616,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
1616 1616
     }
1617 1617
 
1618 1618
     private HuamiSupport setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
1619
-        ActivateDisplayOnLift displayOnLift = HuamiCoordinator.getActivateDisplayOnLiftWrist(getContext());
1619
+        ActivateDisplayOnLift displayOnLift = HuamiCoordinator.getActivateDisplayOnLiftWrist(getContext(), gbDevice.getAddress());
1620 1620
         LOG.info("Setting activate display on lift wrist to " + displayOnLift);
1621 1621
 
1622 1622
         switch (displayOnLift) {
@@ -1631,12 +1631,12 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
1631 1631
 
1632 1632
                 Calendar calendar = GregorianCalendar.getInstance();
1633 1633
 
1634
-                Date start = HuamiCoordinator.getDisplayOnLiftStart();
1634
+                Date start = HuamiCoordinator.getDisplayOnLiftStart(gbDevice.getAddress());
1635 1635
                 calendar.setTime(start);
1636 1636
                 cmd[4] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
1637 1637
                 cmd[5] = (byte) calendar.get(Calendar.MINUTE);
1638 1638
 
1639
-                Date end = HuamiCoordinator.getDisplayOnLiftEnd();
1639
+                Date end = HuamiCoordinator.getDisplayOnLiftEnd(gbDevice.getAddress());
1640 1640
                 calendar.setTime(end);
1641 1641
                 cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
1642 1642
                 cmd[7] = (byte) calendar.get(Calendar.MINUTE);
@@ -1675,7 +1675,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
1675 1675
     }
1676 1676
 
1677 1677
     private HuamiSupport setRotateWristToSwitchInfo(TransactionBuilder builder) {
1678
-        boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo();
1678
+        boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo(gbDevice.getAddress());
1679 1679
         LOG.info("Setting rotate wrist to cycle info to " + enable);
1680 1680
         if (enable) {
1681 1681
             builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_ROTATE_WRIST_TO_SWITCH_INFO);

+ 30
- 0
app/src/main/res/xml/devicesettings_liftwrist_display.xml View File

@@ -0,0 +1,30 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
3
+    <PreferenceScreen
4
+        android:key="screen_liftwrist_display"
5
+        android:persistent="false"
6
+        android:title="@string/mi2_prefs_activate_display_on_lift">
7
+
8
+        <!-- workaround for missing toolbar -->
9
+        <PreferenceCategory android:title="@string/mi2_prefs_activate_display_on_lift" />
10
+
11
+        <ListPreference
12
+            android:defaultValue="@string/p_off"
13
+            android:entries="@array/activate_display_on_lift"
14
+            android:entryValues="@array/activate_display_on_lift_values"
15
+            android:key="activate_display_on_lift_wrist"
16
+            android:summary="%s"
17
+            android:title="@string/mi2_prefs_activate_display_on_lift" />
18
+
19
+        <nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
20
+            android:defaultValue="00:00"
21
+            android:key="display_on_lift_start"
22
+            android:title="@string/mi2_prefs_do_not_disturb_start" />
23
+
24
+        <nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
25
+            android:defaultValue="00:00"
26
+            android:key="display_on_lift_end"
27
+            android:title="@string/mi2_prefs_do_not_disturb_end" />
28
+
29
+    </PreferenceScreen>
30
+</androidx.preference.PreferenceScreen>

+ 7
- 0
app/src/main/res/xml/devicesettings_rotatewrist_cycleinfo.xml View File

@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
3
+    <SwitchPreference
4
+        android:defaultValue="false"
5
+        android:key="rotate_wrist_to_cycle_info"
6
+        android:title="@string/mi2_prefs_rotate_wrist_to_switch_info" />
7
+</androidx.preference.PreferenceScreen>

+ 0
- 31
app/src/main/res/xml/miband_preferences.xml View File

@@ -106,37 +106,6 @@
106 106
             android:summary="%s"
107 107
             android:title="@string/prefs_title_heartrate_measurement_interval" />
108 108
 
109
-        <PreferenceScreen
110
-            android:persistent="false"
111
-            android:title="@string/mi2_prefs_activate_display_on_lift">
112
-
113
-            <!-- workaround for missing toolbar -->
114
-            <PreferenceCategory android:title="@string/mi2_prefs_activate_display_on_lift" />
115
-
116
-            <ListPreference
117
-                android:defaultValue="@string/p_off"
118
-                android:entries="@array/activate_display_on_lift"
119
-                android:entryValues="@array/activate_display_on_lift_values"
120
-                android:key="activate_display_on_lift_wrist"
121
-                android:summary="%s"
122
-                android:title="@string/mi2_prefs_activate_display_on_lift" />
123
-
124
-            <nodomain.freeyourgadget.gadgetbridge.util.TimePreference
125
-                android:defaultValue="00:00"
126
-                android:key="display_on_lift_start"
127
-                android:title="@string/mi2_prefs_do_not_disturb_start" />
128
-
129
-            <nodomain.freeyourgadget.gadgetbridge.util.TimePreference
130
-                android:defaultValue="00:00"
131
-                android:key="display_on_lift_end"
132
-                android:title="@string/mi2_prefs_do_not_disturb_end" />
133
-
134
-        </PreferenceScreen>
135
-        <CheckBoxPreference
136
-            android:defaultValue="false"
137
-            android:key="mi2_rotate_wrist_to_switch_info"
138
-            android:title="@string/mi2_prefs_rotate_wrist_to_switch_info" />
139
-
140 109
         <PreferenceScreen
141 110
             android:key="mi2_inactivity_warning_key"
142 111
             android:summary="@string/mi2_prefs_inactivity_warnings_summary"

Loading…
Cancel
Save