Browse Source

depuplicate code in the same fashion as in ZeTime preferences

tags/0.34.0
Andreas Shimokawa 4 months 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 {
}

private void setChangeListener() {
final Preference displayItems = findPreference("display_items");
if (displayItems != null) {
displayItems.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(HuamiConst.PREF_DISPLAY_ITEMS);
}
});
return true;
}
});
}

Prefs prefs = new Prefs(getPreferenceManager().getSharedPreferences());
String disconnectNotificationState = prefs.getString(PREF_DISCONNECT_NOTIFICATION, PREF_DO_NOT_DISTURB_OFF);
boolean disconnectNotificationScheduled = disconnectNotificationState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
@@ -282,36 +266,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
});
}

final Preference swipeUnlock = findPreference(PREF_SWIPE_UNLOCK);
if (swipeUnlock != null) {
swipeUnlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_SWIPE_UNLOCK);
}
});
return true;
}
});
}
final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT);
if (setDateFormat != null) {
setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT);
}
});
return true;
}
});
}
addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
addPreferenceHandlerFor(HuamiConst.PREF_DISPLAY_ITEMS);
}

static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings) {
@@ -335,4 +292,21 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
super.onDisplayPreferenceDialog(preference);
}
}

private void addPreferenceHandlerFor(final String preferenceKey) {
Preference pref = findPreference(preferenceKey);
if (pref != null) {
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(preferenceKey);
}
});
return true;
}
});
}
}
}

Loading…
Cancel
Save