Clean DO_NOT_DISTURB* constants

This commit is contained in:
Damien Gaignon 2022-03-06 23:48:47 +01:00 committed by Gitea
parent 66b8fb004e
commit 3b75a1701a
15 changed files with 48 additions and 62 deletions

View File

@ -79,6 +79,13 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DO_NOT_DISTURB_NOAUTO = "do_not_disturb_no_auto";
public static final String PREF_DO_NOT_DISTURB_NOAUTO_START = "do_not_disturb_no_auto_start";
public static final String PREF_DO_NOT_DISTURB_NOAUTO_END = "do_not_disturb_no_auto_end";
public static final String PREF_DO_NOT_DISTURB = "do_not_disturb";
public static final String PREF_DO_NOT_DISTURB_START = "do_not_disturb_start";
public static final String PREF_DO_NOT_DISTURB_END = "do_not_disturb_end";
public static final String PREF_DO_NOT_DISTURB_LIFT_WRIST = "do_not_disturb_lift_wrist";
public static final String PREF_DO_NOT_DISTURB_OFF = "off";
public static final String PREF_DO_NOT_DISTURB_AUTOMATIC = "automatic";
public static final String PREF_DO_NOT_DISTURB_SCHEDULED = "scheduled";
public static final String PREF_FIND_PHONE_ENABLED = "prefs_find_phone";
public static final String PREF_AUTOLIGHT = "autolight";

View File

@ -76,12 +76,6 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS_SORTABLE;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_LIFT_WRIST;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE;
@ -298,7 +292,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
}
String doNotDisturbState = prefs.getString(MiBandConst.PREF_DO_NOT_DISTURB, PREF_DO_NOT_DISTURB_OFF);
String doNotDisturbState = prefs.getString(PREF_DO_NOT_DISTURB, PREF_DO_NOT_DISTURB_OFF);
boolean doNotDisturbScheduled = doNotDisturbState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
final Preference doNotDisturbStart = findPreference(PREF_DO_NOT_DISTURB_START);
@ -383,6 +377,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO_START);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_NOAUTO_END);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_START);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_END);
addPreferenceHandlerFor(PREF_DO_NOT_DISTURB_LIFT_WRIST);
addPreferenceHandlerFor(PREF_FIND_PHONE_ENABLED);
addPreferenceHandlerFor(PREF_AUTOLIGHT);

View File

@ -239,11 +239,11 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
}
public static Date getDoNotDisturbStart(String deviceAddress) {
return getTimePreference(MiBandConst.PREF_DO_NOT_DISTURB_START, "01:00", deviceAddress);
return getTimePreference(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START, "01:00", deviceAddress);
}
public static Date getDoNotDisturbEnd(String deviceAddress) {
return getTimePreference(MiBandConst.PREF_DO_NOT_DISTURB_END, "06:00", deviceAddress);
return getTimePreference(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END, "06:00", deviceAddress);
}
public static boolean getBandScreenUnlock(String deviceAddress) {
@ -298,11 +298,11 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
public static DoNotDisturb getDoNotDisturb(String deviceAddress) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
String pref = prefs.getString(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_OFF);
String pref = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB, DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_OFF);
if (MiBandConst.PREF_DO_NOT_DISTURB_AUTOMATIC.equals(pref)) {
if (DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_AUTOMATIC.equals(pref)) {
return DoNotDisturb.AUTOMATIC;
} else if (MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED.equals(pref)) {
} else if (DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_SCHEDULED.equals(pref)) {
return DoNotDisturb.SCHEDULED;
}
@ -312,7 +312,7 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
public static boolean getDoNotDisturbLiftWrist(String deviceAddress) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
return prefs.getBoolean(MiBandConst.PREF_DO_NOT_DISTURB_LIFT_WRIST, false);
return prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_LIFT_WRIST, false);
}
@Override

View File

@ -46,10 +46,6 @@ public final class WatchXPlusConstants extends LenovoWatchConstants {
public static final String PREF_BP_CAL_LOW = "pref_sensors_bp_calibration_low";
public static final String PREF_BP_CAL_HIGH = "pref_sensors_bp_calibration_high";
public static final String PREF_DO_NOT_DISTURB = "do_not_disturb_no_auto";
public static final String PREF_DO_NOT_DISTURB_START = "do_not_disturb_no_auto_start";
public static final String PREF_DO_NOT_DISTURB_END = "do_not_disturb_no_auto_end";
public static final String PREF_LONGSIT_START = "pref_longsit_start";
public static final String PREF_LONGSIT_END = "pref_longsit_end";
public static final String PREF_SHOW_RAW_GRAPH = "show_raw_graph";

View File

@ -241,7 +241,7 @@ public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator {
*/
public static boolean getDNDHours(String deviceAddress, Calendar startOut, Calendar endOut) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
String doNotDisturb = prefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off));
String doNotDisturb = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO, getContext().getString(R.string.p_off));
assert doNotDisturb != null;
if (doNotDisturb.equals(getContext().getString(R.string.p_off))) {
@ -249,8 +249,8 @@ public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator {
return false;
} else {
String start = prefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB_START, "01:00");
String end = prefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB_END, "06:00");
String start = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_START, "01:00");
String end = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_END, "06:00");
DateFormat df = new SimpleDateFormat("HH:mm");

View File

@ -24,9 +24,6 @@ public final class MakibesHR3Constants {
// TODO: breaking someone else's device support.
public static final String PREF_HEADS_UP_SCREEN = "activate_display_on_lift_wrist";
public static final String PREF_LOST_REMINDER = "disconnect_notification";
public static final String PREF_DO_NOT_DISTURB = "do_not_disturb_no_auto";
public static final String PREF_DO_NOT_DISTURB_START = "do_not_disturb_no_auto_start";
public static final String PREF_DO_NOT_DISTURB_END = "do_not_disturb_no_auto_end";
public static final String PREF_FIND_PHONE = "prefs_find_phone";
public static final String PREF_FIND_PHONE_DURATION = "prefs_find_phone_duration";

View File

@ -95,13 +95,13 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
* @return True if quite hours are enabled.
*/
public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
String doNotDisturb = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off));
String doNotDisturb = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO, getContext().getString(R.string.p_off));
if (doNotDisturb.equals(getContext().getString(R.string.p_off))) {
return false;
} else {
String start = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB_START, "00:00");
String end = sharedPrefs.getString(MakibesHR3Constants.PREF_DO_NOT_DISTURB_END, "00:00");
String start = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_START, "00:00");
String end = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_END, "00:00");
DateFormat df = new SimpleDateFormat("HH:mm");

View File

@ -36,13 +36,6 @@ public final class MiBandConst {
public static final String PREF_MI2_DISPLAY_ITEM_BATTERY = "battery";
public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "rotate_wrist_to_cycle_info";
public static final String PREF_MI2_ENABLE_TEXT_NOTIFICATIONS = "mi2_enable_text_notifications";
public static final String PREF_DO_NOT_DISTURB = "do_not_disturb";
public static final String PREF_DO_NOT_DISTURB_LIFT_WRIST = "do_not_disturb_lift_wrist";
public static final String PREF_DO_NOT_DISTURB_OFF = "off";
public static final String PREF_DO_NOT_DISTURB_AUTOMATIC = "automatic";
public static final String PREF_DO_NOT_DISTURB_SCHEDULED = "scheduled";
public static final String PREF_DO_NOT_DISTURB_START = "do_not_disturb_start";
public static final String PREF_DO_NOT_DISTURB_END = "do_not_disturb_end";
public static final String PREF_MI2_INACTIVITY_WARNINGS = "mi2_inactivity_warnings";
public static final String PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD = "mi2_inactivity_warnings_threshold";
public static final String PREF_MI2_INACTIVITY_WARNINGS_START = "mi2_inactivity_warnings_start";

View File

@ -135,10 +135,6 @@ public class ZeTimeConstants {
public static final String PREF_ZETIME_MIN_HEARTRATE = "alarm_min_heart_rate";
public static final String PREF_ZETIME_HEARTRATE_INTERVAL = "heartrate_measurement_interval";
public static final String PREF_DO_NOT_DISTURB = "zetime_do_not_disturb";
public static final String PREF_DO_NOT_DISTURB_START = "zetime_do_not_disturb_start";
public static final String PREF_DO_NOT_DISTURB_END = "zetime_do_not_disturb_end";
public static final String PREF_INACTIVITY_KEY = "zetime_inactivity_warning_key";
public static final String PREF_INACTIVITY_ENABLE = "zetime_inactivity_warnings";
public static final String PREF_INACTIVITY_START = "zetime_inactivity_warnings_start";

View File

@ -49,10 +49,6 @@ public class ZeTimePreferenceActivity extends AbstractSettingsActivity {
addPreferenceHandlerFor(ZeTimeConstants.PREF_HANDMOVE_DISPLAY);
addPreferenceHandlerFor(ZeTimeConstants.PREF_DO_NOT_DISTURB);
addPreferenceHandlerFor(ZeTimeConstants.PREF_DO_NOT_DISTURB_START);
addPreferenceHandlerFor(ZeTimeConstants.PREF_DO_NOT_DISTURB_END);
addPreferenceHandlerFor(ZeTimeConstants.PREF_CALORIES_TYPE);
addPreferenceHandlerFor(ZeTimeConstants.PREF_DATE_FORMAT);

View File

@ -150,6 +150,10 @@ import nodomain.freeyourgadget.gadgetbridge.util.Version;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BT_CONNECTED_ADVERTISEMENT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_LIFT_WRIST;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_REMINDERS_CALENDAR;
@ -2232,10 +2236,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case ActivityUser.PREF_USER_STEPS_GOAL:
setFitnessGoal(builder);
break;
case MiBandConst.PREF_DO_NOT_DISTURB:
case MiBandConst.PREF_DO_NOT_DISTURB_START:
case MiBandConst.PREF_DO_NOT_DISTURB_END:
case MiBandConst.PREF_DO_NOT_DISTURB_LIFT_WRIST:
case PREF_DO_NOT_DISTURB:
case PREF_DO_NOT_DISTURB_START:
case PREF_DO_NOT_DISTURB_END:
case PREF_DO_NOT_DISTURB_LIFT_WRIST:
setDoNotDisturb(builder);
break;
case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS:

View File

@ -986,7 +986,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
setLanguageAndTimeFormat(builder);
break;
case WatchXPlusConstants.PREF_DO_NOT_DISTURB:
case DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO:
setDNDHours(builder);
break;
}

View File

@ -559,9 +559,9 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
this.setHeadsUpScreen(transactionBuilder, sharedPreferences);
} else if (key.equals(MakibesHR3Constants.PREF_LOST_REMINDER)) {
this.setLostReminder(transactionBuilder, sharedPreferences);
} else if (key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB) ||
key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB_START) ||
key.equals(MakibesHR3Constants.PREF_DO_NOT_DISTURB_END)) {
} else if (key.equals(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO) ||
key.equals(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_START) ||
key.equals(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_END)) {
this.setQuiteHours(transactionBuilder, sharedPreferences);
} else if (key.equals(MakibesHR3Constants.PREF_FIND_PHONE) ||
key.equals(MakibesHR3Constants.PREF_FIND_PHONE_DURATION)) {

View File

@ -169,9 +169,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
case ZeTimeConstants.PREF_HANDMOVE_DISPLAY:
setDisplayOnMovement(builder);
break;
case ZeTimeConstants.PREF_DO_NOT_DISTURB:
case ZeTimeConstants.PREF_DO_NOT_DISTURB_START:
case ZeTimeConstants.PREF_DO_NOT_DISTURB_END:
case DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB:
case DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START:
case DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END:
setDoNotDisturb(builder);
break;
case ZeTimeConstants.PREF_CALORIES_TYPE:
@ -1713,10 +1713,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
private void setDoNotDisturb(TransactionBuilder builder) {
Prefs prefs = GBApplication.getPrefs();
String scheduled = prefs.getString(ZeTimeConstants.PREF_DO_NOT_DISTURB, "off");
String scheduled = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB, "off");
String dndScheduled = getContext().getString(R.string.p_scheduled);
String start = prefs.getString(ZeTimeConstants.PREF_DO_NOT_DISTURB_START, "22:00");
String end = prefs.getString(ZeTimeConstants.PREF_DO_NOT_DISTURB_END, "07:00");
String start = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START, "22:00");
String end = prefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END, "07:00");
DateFormat df_start = new SimpleDateFormat("HH:mm");
DateFormat df_end = new SimpleDateFormat("HH:mm");
Calendar calendar = GregorianCalendar.getInstance();
@ -2086,12 +2086,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
String endtime = String.format("%02d:%02d", msg[8], msg[9]);
if (0x1 == msg[5]) {
prefs.putString(ZeTimeConstants.PREF_DO_NOT_DISTURB, "scheduled");
prefs.putString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB, "scheduled");
} else {
prefs.putString(ZeTimeConstants.PREF_DO_NOT_DISTURB, "off");
prefs.putString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB, "off");
}
prefs.putString(ZeTimeConstants.PREF_DO_NOT_DISTURB_START, starttime);
prefs.putString(ZeTimeConstants.PREF_DO_NOT_DISTURB_END, endtime);
prefs.putString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START, starttime);
prefs.putString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END, endtime);
prefs.apply();
}

View File

@ -173,18 +173,18 @@
android:defaultValue="@string/p_off"
android:entries="@array/zetime_do_not_disturb"
android:entryValues="@array/zetime_do_not_disturb_values"
android:key="zetime_do_not_disturb"
android:key="do_not_disturb"
android:title="@string/mi2_prefs_do_not_disturb"
android:summary="%s" />
<nodomain.freeyourgadget.gadgetbridge.util.TimePreference
android:defaultValue="22:00"
android:key="zetime_do_not_disturb_start"
android:key="do_not_disturb_start"
android:title="@string/mi2_prefs_do_not_disturb_start" />
<nodomain.freeyourgadget.gadgetbridge.util.TimePreference
android:defaultValue="07:00"
android:key="zetime_do_not_disturb_end"
android:key="do_not_disturb_end"
android:title="@string/mi2_prefs_do_not_disturb_end" />
</PreferenceScreen>