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

depuplicate code in the same fashion as in ZeTime preferences

tags/0.34.0
Andreas Shimokawa 1 month ago
parent
commit
3aa36324c1

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

@@ -89,22 +89,6 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
89 89
     }
90 90
 
91 91
     private void setChangeListener() {
92
-        final Preference displayItems = findPreference("display_items");
93
-        if (displayItems != null) {
94
-            displayItems.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
95
-                @Override
96
-                public boolean onPreferenceChange(Preference preference, Object newVal) {
97
-                    invokeLater(new Runnable() {
98
-                        @Override
99
-                        public void run() {
100
-                            GBApplication.deviceService().onSendConfiguration(HuamiConst.PREF_DISPLAY_ITEMS);
101
-                        }
102
-                    });
103
-                    return true;
104
-                }
105
-            });
106
-        }
107
-
108 92
         Prefs prefs = new Prefs(getPreferenceManager().getSharedPreferences());
109 93
         String disconnectNotificationState = prefs.getString(PREF_DISCONNECT_NOTIFICATION, PREF_DO_NOT_DISTURB_OFF);
110 94
         boolean disconnectNotificationScheduled = disconnectNotificationState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
@@ -282,36 +266,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
282 266
             });
283 267
         }
284 268
 
285
-        final Preference swipeUnlock = findPreference(PREF_SWIPE_UNLOCK);
286
-        if (swipeUnlock != null) {
287
-            swipeUnlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
288
-                @Override
289
-                public boolean onPreferenceChange(Preference preference, Object newVal) {
290
-                    invokeLater(new Runnable() {
291
-                        @Override
292
-                        public void run() {
293
-                            GBApplication.deviceService().onSendConfiguration(PREF_SWIPE_UNLOCK);
294
-                        }
295
-                    });
296
-                    return true;
297
-                }
298
-            });
299
-        }
300
-        final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT);
301
-        if (setDateFormat != null) {
302
-            setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
303
-                @Override
304
-                public boolean onPreferenceChange(Preference preference, Object newVal) {
305
-                    invokeLater(new Runnable() {
306
-                        @Override
307
-                        public void run() {
308
-                            GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT);
309
-                        }
310
-                    });
311
-                    return true;
312
-                }
313
-            });
314
-        }
269
+        addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
270
+        addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
271
+        addPreferenceHandlerFor(HuamiConst.PREF_DISPLAY_ITEMS);
315 272
     }
316 273
 
317 274
     static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings) {
@@ -335,4 +292,21 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
335 292
             super.onDisplayPreferenceDialog(preference);
336 293
         }
337 294
     }
295
+
296
+    private void addPreferenceHandlerFor(final String preferenceKey) {
297
+        Preference pref = findPreference(preferenceKey);
298
+        if (pref != null) {
299
+            pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
300
+                public boolean onPreferenceChange(Preference preference, Object newVal) {
301
+                    invokeLater(new Runnable() {
302
+                        @Override
303
+                        public void run() {
304
+                            GBApplication.deviceService().onSendConfiguration(preferenceKey);
305
+                        }
306
+                    });
307
+                    return true;
308
+                }
309
+            });
310
+        }
311
+    }
338 312
 }

Loading…
Cancel
Save