1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-10-06 13:20:30 +02:00

move some device specific preferences from GBPrefs to DevicePrefs

addresses https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/4049#issuecomment-2270266
This commit is contained in:
Johannes Krude 2024-08-30 15:48:42 +02:00 committed by José Rebelo
parent b64841b48e
commit 80fea5b916
19 changed files with 140 additions and 158 deletions

View File

@ -57,7 +57,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
public class ConfigureReminders extends AbstractGBActivity { public class ConfigureReminders extends AbstractGBActivity {
@ -103,9 +102,7 @@ public class ConfigureReminders extends AbstractGBActivity {
public void onClick(View v) { public void onClick(View v) {
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final GBPrefs prefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); int deviceSlots = coordinator.getReminderSlotCount(gbDevice) - GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice);
int deviceSlots = coordinator.getReminderSlotCount(gbDevice) - prefs.getReservedReminderCalendarSlots(gbDevice);
if (mGBReminderListAdapter.getItemCount() >= deviceSlots) { if (mGBReminderListAdapter.getItemCount() >= deviceSlots) {
// No more free slots // No more free slots

View File

@ -638,9 +638,8 @@ public class DBHelper {
@NonNull @NonNull
public static List<Reminder> getReminders(@NonNull GBDevice gbDevice) { public static List<Reminder> getReminders(@NonNull GBDevice gbDevice) {
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final GBPrefs prefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())));
final int reservedSlots = prefs.getReservedReminderCalendarSlots(gbDevice); final int reservedSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice);
final int reminderSlots = coordinator.getReminderSlotCount(gbDevice); final int reminderSlots = coordinator.getReminderSlotCount(gbDevice);
try (DBHandler db = GBApplication.acquireDB()) { try (DBHandler db = GBApplication.acquireDB()) {

View File

@ -48,7 +48,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext; import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
@ -139,18 +138,6 @@ public class HPlusCoordinator extends AbstractBLEDeviceCoordinator {
} }
} }
public static byte getTimeMode(String deviceAddress) {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress)));
String tmode = gbPrefs.getTimeFormat();
if ("24h".equals(tmode)) {
return HPlusConstants.ARG_TIMEMODE_24H;
} else {
return HPlusConstants.ARG_TIMEMODE_12H;
}
}
public static byte getUnit(String address) { public static byte getUnit(String address) {
String units = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric)); String units = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric));

View File

@ -51,7 +51,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.makibeshr3.MakibesHR3DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.makibeshr3.MakibesHR3DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext; import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
@ -79,18 +78,6 @@ public class MakibesHR3Coordinator extends AbstractBLEDeviceCoordinator {
return !lostReminder.equals(getContext().getString(R.string.p_off)); return !lostReminder.equals(getContext().getString(R.string.p_off));
} }
public static byte getTimeMode(SharedPreferences sharedPrefs) {
GBPrefs gbPrefs = new GBPrefs(new Prefs(sharedPrefs));
String timeMode = gbPrefs.getTimeFormat();
if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) {
return MakibesHR3Constants.ARG_SET_TIMEMODE_24H;
} else {
return MakibesHR3Constants.ARG_SET_TIMEMODE_12H;
}
}
/** /**
* @param startOut out Only hour/minute are used. * @param startOut out Only hour/minute are used.
* @param endOut out Only hour/minute are used. * @param endOut out Only hour/minute are used.

View File

@ -51,7 +51,7 @@ import nodomain.freeyourgadget.gadgetbridge.Logging;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils; import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil; import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil;
@ -734,13 +734,6 @@ public abstract class Casio2C2DSupport extends CasioSupport {
public abstract boolean readValue(byte[] data, SharedPreferences.Editor editor); public abstract boolean readValue(byte[] data, SharedPreferences.Editor editor);
protected Prefs getPrefs() {
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
}
protected GBPrefs getGBPrefs() {
return new GBPrefs(getPrefs());
}
}; };
public abstract Casio2C2DSupport.DevicePreference[] supportedDevicePreferences(); public abstract Casio2C2DSupport.DevicePreference[] supportedDevicePreferences();
@ -774,20 +767,20 @@ public abstract class Casio2C2DSupport extends CasioSupport {
@Override @Override
public void updateValue(byte[] data) { public void updateValue(byte[] data) {
data[index] = (byte) getGBValue(); data[index] = (byte) getDevicePrefsValue();
} }
@Override @Override
public boolean readValue(byte[] data, SharedPreferences.Editor editor) { public boolean readValue(byte[] data, SharedPreferences.Editor editor) {
return setGBValue(editor, data[index] & 0xff); return setDevicePrefsValue(editor, data[index] & 0xff);
} }
public int getGBValue() { public int getDevicePrefsValue() {
return getPrefs().getInt(name, -1); return getDevicePrefs().getInt(name, -1);
} }
public boolean setGBValue(SharedPreferences.Editor editor, int value) { public boolean setDevicePrefsValue(SharedPreferences.Editor editor, int value) {
if (value != getGBValue()) { if (value != getDevicePrefsValue()) {
editor.putString(name, Integer.toString(value)); editor.putString(name, Integer.toString(value));
} }
return false; return false;
@ -800,7 +793,7 @@ public abstract class Casio2C2DSupport extends CasioSupport {
@Override @Override
public void updateValue(byte[] data) { public void updateValue(byte[] data) {
if (getGBValue()) { if (getDevicePrefsValue()) {
data[index] &= ~mask; data[index] &= ~mask;
} else { } else {
data[index] |= mask; data[index] |= mask;
@ -810,18 +803,18 @@ public abstract class Casio2C2DSupport extends CasioSupport {
@Override @Override
public boolean readValue(byte[] data, SharedPreferences.Editor editor) { public boolean readValue(byte[] data, SharedPreferences.Editor editor) {
if ((data[index] & mask) == 0) { if ((data[index] & mask) == 0) {
return setGBValue(editor, true); return setDevicePrefsValue(editor, true);
} else { } else {
return setGBValue(editor, false); return setDevicePrefsValue(editor, false);
} }
} }
public boolean getGBValue() { public boolean getDevicePrefsValue() {
return getPrefs().getBoolean(name, false); return getDevicePrefs().getBoolean(name, false);
} }
public boolean setGBValue(SharedPreferences.Editor editor, boolean value) { public boolean setDevicePrefsValue(SharedPreferences.Editor editor, boolean value) {
if (value != getGBValue()) { if (value != getDevicePrefsValue()) {
editor.putBoolean(name, value); editor.putBoolean(name, value);
} }
return false; return false;
@ -831,7 +824,7 @@ public abstract class Casio2C2DSupport extends CasioSupport {
public class InvertedBoolDevicePreference extends BoolDevicePreference { public class InvertedBoolDevicePreference extends BoolDevicePreference {
@Override @Override
public void updateValue(byte[] data) { public void updateValue(byte[] data) {
if (getGBValue()) { if (getDevicePrefsValue()) {
data[index] |= mask; data[index] |= mask;
} else { } else {
data[index] &= ~mask; data[index] &= ~mask;
@ -841,15 +834,15 @@ public abstract class Casio2C2DSupport extends CasioSupport {
@Override @Override
public boolean readValue(byte[] data, SharedPreferences.Editor editor) { public boolean readValue(byte[] data, SharedPreferences.Editor editor) {
if ((data[index] & mask) == 0) { if ((data[index] & mask) == 0) {
return setGBValue(editor, false); return setDevicePrefsValue(editor, false);
} else { } else {
return setGBValue(editor, true); return setDevicePrefsValue(editor, true);
} }
} }
} }
interface AutoGetter { interface AutoGetter {
public String get(GBPrefs gbPrefs); public String get(DevicePrefs devicePrefs);
} }
public class AutoBoolDevicePreference extends BoolDevicePreference { public class AutoBoolDevicePreference extends BoolDevicePreference {
@ -860,15 +853,15 @@ public abstract class Casio2C2DSupport extends CasioSupport {
String falseValue; String falseValue;
@Override @Override
public boolean getGBValue() { public boolean getDevicePrefsValue() {
return getter.get(getGBPrefs()).equals(trueValue); return getter.get(getDevicePrefs()).equals(trueValue);
} }
@Override @Override
public boolean setGBValue(SharedPreferences.Editor editor, boolean value) { public boolean setDevicePrefsValue(SharedPreferences.Editor editor, boolean value) {
String strValue = value ? trueValue : falseValue; String strValue = value ? trueValue : falseValue;
if (!getter.get(getGBPrefs()).equals(strValue)) { if (!getter.get(getDevicePrefs()).equals(strValue)) {
if (getPrefs().getString(name, autoValue).equals(autoValue)) { if (getDevicePrefs().getString(name, autoValue).equals(autoValue)) {
return true; return true;
} else { } else {
editor.putString(name, strValue); editor.putString(name, strValue);
@ -890,13 +883,13 @@ public abstract class Casio2C2DSupport extends CasioSupport {
{ index = 14; } { index = 14; }
@Override @Override
public int getGBValue() { public int getDevicePrefsValue() {
return getPrefs().getInt(name, -1); return getDevicePrefs().getInt(name, -1);
} }
@Override @Override
public boolean setGBValue(SharedPreferences.Editor editor, int value) { public boolean setDevicePrefsValue(SharedPreferences.Editor editor, int value) {
if (value != getGBValue()) { if (value != getDevicePrefsValue()) {
editor.putString(name, Integer.toString(value)); editor.putString(name, Integer.toString(value));
} }
return false; return false;
@ -955,8 +948,8 @@ public abstract class Casio2C2DSupport extends CasioSupport {
String[] languages = { "en_US", "es_ES", "fr_FR"," de_DE", "it_IT", "ru_RU" }; String[] languages = { "en_US", "es_ES", "fr_FR"," de_DE", "it_IT", "ru_RU" };
@Override @Override
public int getGBValue() { public int getDevicePrefsValue() {
String value = getPrefs().getString(name, PREF_LANGUAGE_AUTO); String value = getDevicePrefs().getString(name, PREF_LANGUAGE_AUTO);
int number = 0; int number = 0;
if (value.equals(PREF_LANGUAGE_AUTO)) { if (value.equals(PREF_LANGUAGE_AUTO)) {
String lang = Locale.getDefault().getLanguage() + "_"; String lang = Locale.getDefault().getLanguage() + "_";
@ -978,9 +971,9 @@ public abstract class Casio2C2DSupport extends CasioSupport {
} }
@Override @Override
public boolean setGBValue(SharedPreferences.Editor editor, int value) { public boolean setDevicePrefsValue(SharedPreferences.Editor editor, int value) {
if (getGBValue() != value) { if (getDevicePrefsValue() != value) {
if (getPrefs().getString(name, PREF_LANGUAGE_AUTO).equals(PREF_LANGUAGE_AUTO)) { if (getDevicePrefs().getString(name, PREF_LANGUAGE_AUTO).equals(PREF_LANGUAGE_AUTO)) {
return true; return true;
} else { } else {
if (value < languages.length) { if (value < languages.length) {

View File

@ -37,7 +37,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.Casio2C2DSuppo
import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gbx100.CasioGBX100DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus;
import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil; import nodomain.freeyourgadget.gadgetbridge.util.BcdUtil;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_AUTOLIGHT; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_AUTOLIGHT;
@ -202,9 +201,8 @@ public class SetConfigurationOperation extends AbstractBTLEOperation<CasioGBX10
return true; return true;
} else if(data[0] == Casio2C2DSupport.FEATURE_SETTING_FOR_BASIC) { } else if(data[0] == Casio2C2DSupport.FEATURE_SETTING_FOR_BASIC) {
SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()); SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress())));
String timeformat = gbPrefs.getTimeFormat(); String timeformat = GBApplication.getDevicePrefs(getDevice().getAddress()).getTimeFormat();
if(timeformat.equals(getContext().getString(R.string.p_timeformat_24h))) { if(timeformat.equals(getContext().getString(R.string.p_timeformat_24h))) {
data[1] |= 0x01; data[1] |= 0x01;

View File

@ -208,8 +208,7 @@ public class CmfPreferences {
} }
private void setTimeFormat() { private void setTimeFormat() {
final GBPrefs gbPrefs = new GBPrefs(mSupport.getDevicePrefs()); final String timeFormat = mSupport.getDevicePrefs().getTimeFormat();
final String timeFormat = gbPrefs.getTimeFormat();
LOG.info("Setting time format to {}", timeFormat); LOG.info("Setting time format to {}", timeFormat);

View File

@ -59,7 +59,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions; import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil; import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils; import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -185,8 +184,7 @@ public class PixooProtocol extends GBDeviceProtocol {
brightness brightness
}); });
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT: case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
final GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()))); final String timeFormat = getDevicePrefs().getTimeFormat();
final String timeFormat = gbPrefs.getTimeFormat();
final boolean is24hour = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H.equals(timeFormat); final boolean is24hour = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H.equals(timeFormat);
return encodeProtocol(new byte[]{ return encodeProtocol(new byte[]{

View File

@ -61,7 +61,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService; import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -393,9 +392,8 @@ public final class HamaFit6900DeviceSupport extends AbstractBTLEDeviceSupport {
} }
private Message.TimeFormat getDevicePrefsTimeFormat() { private Message.TimeFormat getDevicePrefsTimeFormat() {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())));
Message.TimeFormat timeFormat = null; Message.TimeFormat timeFormat = null;
switch (gbPrefs.getTimeFormat()) { switch (getDevicePrefs().getTimeFormat()) {
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H: case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H:
timeFormat = Message.TimeFormat.Format24H; timeFormat = Message.TimeFormat.Format24H;
break; break;

View File

@ -164,13 +164,18 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
return this; return this;
} }
public byte getTimeMode() {
if ("24h".equals(getDevicePrefs().getTimeFormat())) {
return HPlusConstants.ARG_TIMEMODE_24H;
} else {
return HPlusConstants.ARG_TIMEMODE_12H;
}
}
private HPlusSupport setTimeMode(TransactionBuilder transaction) { private HPlusSupport setTimeMode(TransactionBuilder transaction) {
byte value = HPlusCoordinator.getTimeMode(getDevice().getAddress());
transaction.write(ctrlCharacteristic, new byte[]{ transaction.write(ctrlCharacteristic, new byte[]{
HPlusConstants.CMD_SET_TIMEMODE, HPlusConstants.CMD_SET_TIMEMODE,
value getTimeMode()
}); });
return this; return this;
} }

View File

@ -185,7 +185,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSampl
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils; import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils; import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -1029,8 +1028,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
private void sendReminders(final TransactionBuilder builder, final List<? extends Reminder> reminders) { private void sendReminders(final TransactionBuilder builder, final List<? extends Reminder> reminders) {
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final GBPrefs prefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); int reservedSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice);
int reservedSlots = prefs.getReservedReminderCalendarSlots(gbDevice);
LOG.info("On Set Reminders. Reminders: {}, Reserved slots: {}", reminders.size(), reservedSlots); LOG.info("On Set Reminders. Reminders: {}, Reserved slots: {}", reminders.size(), reservedSlots);
// Send the reminders, skipping the reserved slots for calendar events // Send the reminders, skipping the reserved slots for calendar events
@ -2756,8 +2754,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
} }
final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator(); final DeviceCoordinator coordinator = gbDevice.getDeviceCoordinator();
final GBPrefs prefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); int availableSlots = GBApplication.getDevicePrefs(gbDevice.getAddress()).getReservedReminderCalendarSlots(gbDevice);
int availableSlots = prefs.getReservedReminderCalendarSlots(gbDevice);
CalendarManager upcomingEvents = new CalendarManager(getContext(), getDevice().getAddress()); CalendarManager upcomingEvents = new CalendarManager(getContext(), getDevice().getAddress());
List<CalendarEvent> calendarEvents = upcomingEvents.getCalendarEventList(); List<CalendarEvent> calendarEvents = upcomingEvents.getCalendarEventList();
@ -3376,8 +3373,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
} }
protected HuamiSupport setTimeFormat(TransactionBuilder builder) { protected HuamiSupport setTimeFormat(TransactionBuilder builder) {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); String timeFormat = GBApplication.getDevicePrefs(gbDevice.getAddress()).getTimeFormat();
String timeFormat = gbPrefs.getTimeFormat();
LOG.info("Setting time format to " + timeFormat); LOG.info("Setting time format to " + timeFormat);
if (timeFormat.equals(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H)) { if (timeFormat.equals(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H)) {

View File

@ -1047,8 +1047,7 @@ public class ZeppOsSupport extends HuamiSupport implements ZeppOsFileTransferSer
@Override @Override
protected ZeppOsSupport setTimeFormat(final TransactionBuilder builder) { protected ZeppOsSupport setTimeFormat(final TransactionBuilder builder) {
final GBPrefs gbPrefs = new GBPrefs(getDevicePrefs()); final String timeFormat = getDevicePrefs().getTimeFormat();
final String timeFormat = gbPrefs.getTimeFormat();
// FIXME: This "works", but the band does not update when the setting changes, so we don't do anything // FIXME: This "works", but the band does not update when the setting changes, so we don't do anything
//noinspection ConstantValue //noinspection ConstantValue

View File

@ -76,6 +76,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSuppo
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implements SharedPreferences.OnSharedPreferenceChangeListener { public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -430,6 +431,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
this.fetch(true); this.fetch(true);
} }
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
LOG.debug(key + " changed"); LOG.debug(key + " changed");
@ -1000,9 +1002,19 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
return this; return this;
} }
public byte getTimeMode(SharedPreferences sharedPrefs) {
String timeMode = new DevicePrefs(sharedPrefs).getTimeFormat();
if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) {
return MakibesHR3Constants.ARG_SET_TIMEMODE_24H;
} else {
return MakibesHR3Constants.ARG_SET_TIMEMODE_12H;
}
}
private MakibesHR3DeviceSupport setTimeMode(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { private MakibesHR3DeviceSupport setTimeMode(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) {
return this.setTimeMode(transactionBuilder, return this.setTimeMode(transactionBuilder,
MakibesHR3Coordinator.getTimeMode(sharedPreferences)); getTimeMode(sharedPreferences));
} }
private MakibesHR3DeviceSupport setEnableRealTimeHeartRate(TransactionBuilder transaction, boolean enable) { private MakibesHR3DeviceSupport setEnableRealTimeHeartRate(TransactionBuilder transaction, boolean enable) {

View File

@ -107,7 +107,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.comm
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.communication.notification.NotificationProvider; import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.communication.notification.NotificationProvider;
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.communication.notification.NotificationSource; import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.communication.notification.NotificationSource;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -725,10 +724,7 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport {
} }
private short getTimeMode() { private short getTimeMode() {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); if ("24h".equals(getDevicePrefs().getTimeFormat())) {
String tmode = gbPrefs.getTimeFormat();
if ("24h".equals(tmode)) {
return UserUnitConstants.UNIT_24H; return UserUnitConstants.UNIT_24H;
} else { } else {
return UserUnitConstants.UNIT_12H; return UserUnitConstants.UNIT_12H;

View File

@ -59,7 +59,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPrefere
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.CheckSums; import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.SilentMode; import nodomain.freeyourgadget.gadgetbridge.util.SilentMode;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -287,8 +286,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
final Calendar now = GregorianCalendar.getInstance(); final Calendar now = GregorianCalendar.getInstance();
final TimeZone tz = TimeZone.getDefault(); final TimeZone tz = TimeZone.getDefault();
final GBPrefs gbPrefs = new GBPrefs(GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress())); final String timeFormat = getDevicePrefs().getTimeFormat();
final String timeFormat = gbPrefs.getTimeFormat();
final boolean is24hour = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H.equals(timeFormat); final boolean is24hour = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H.equals(timeFormat);
final XiaomiProto.Clock clock = XiaomiProto.Clock.newBuilder() final XiaomiProto.Clock clock = XiaomiProto.Clock.newBuilder()

View File

@ -70,7 +70,6 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateA
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils; import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarManager; import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarManager;
@ -1692,9 +1691,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
} }
private void setTimeFormate(TransactionBuilder builder) { private void setTimeFormate(TransactionBuilder builder) {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); String timeFormat = getDevicePrefs().getTimeFormat();
String timeFormat = gbPrefs.getTimeFormat();
int type = 1; int type = 1;
if ("am/pm".equals(timeFormat)) { if ("am/pm".equals(timeFormat)) {
type = 2; type = 2;

View File

@ -32,7 +32,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.Reminder; import nodomain.freeyourgadget.gadgetbridge.model.Reminder;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WorldClock; import nodomain.freeyourgadget.gadgetbridge.model.WorldClock;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.preferences.DevicePrefs;
public abstract class GBDeviceProtocol { public abstract class GBDeviceProtocol {
@ -181,7 +181,7 @@ public abstract class GBDeviceProtocol {
return null; return null;
} }
protected Prefs getDevicePrefs() { protected DevicePrefs getDevicePrefs() {
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress())); return GBApplication.getDevicePrefs(getDevice().getAddress());
} }
} }

View File

@ -1,6 +1,6 @@
/* Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer, /* Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin
Maurer, José Rebelo, Petr Vaněk, Johannes Krude Maurer, José Rebelo, Petr Vaněk
This file is part of Gadgetbridge. This file is part of Gadgetbridge.
@ -25,7 +25,6 @@ import android.content.pm.PackageManager;
import android.location.Criteria; import android.location.Criteria;
import android.location.Location; import android.location.Location;
import android.location.LocationManager; import android.location.LocationManager;
import android.text.format.DateFormat;
import android.util.Log; import android.util.Log;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
@ -33,7 +32,6 @@ import androidx.core.app.ActivityCompat;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Date; import java.util.Date;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
@ -117,42 +115,6 @@ public class GBPrefs extends Prefs {
return 0; return 0;
} }
public String getTimeFormat() {
String timeFormat = getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO);
if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(timeFormat)) {
if (DateFormat.is24HourFormat(GBApplication.getContext())) {
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H;
} else {
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_12H;
}
}
return timeFormat;
}
public String getDateFormatDayMonthOrder() {
String dateFormat = getString(DeviceSettingsPreferenceConst.PREF_DATEFORMAT, DeviceSettingsPreferenceConst.PREF_DATEFORMAT_AUTO);
if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(dateFormat)) {
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dM");
boolean quoted = false;
for (char c: pattern.toCharArray()) {
if (c == '\'') {
quoted = !quoted;
continue;
}
if (quoted)
continue;
if (c == 'd')
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
if (c == 'M' || c == 'L')
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_MONTH_DAY;
}
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
}
return dateFormat;
}
public float[] getLongLat(Context context) { public float[] getLongLat(Context context) {
float latitude = getFloat("location_latitude", 0); float latitude = getFloat("location_latitude", 0);
float longitude = getFloat("location_longitude", 0); float longitude = getFloat("location_longitude", 0);
@ -187,14 +149,6 @@ public class GBPrefs extends Prefs {
return getLocalTime("notification_times_end", "22:00"); return getLocalTime("notification_times_end", "22:00");
} }
public int getReservedReminderCalendarSlots(GBDevice gbDevice) {
if (!gbDevice.getDeviceCoordinator().getReserveReminderSlotsForCalendar())
return 0;
if (!getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false))
return 0;
return getInt(DeviceSettingsPreferenceConst.PREF_RESERVE_REMINDERS_CALENDAR, 9);
}
public boolean isMetricUnits() { public boolean isMetricUnits() {
return getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, "metric").equals("metric"); return getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, "metric").equals("metric");
} }

View File

@ -1,11 +1,35 @@
/* Copyright (C) 2016-2024 Andreas Shimokawa, Anemograph, Carsten Pfeiffer,
Daniel Dakhno, Daniele Gobbetti, Davis Mosenkovs, Dikay900, Felix Konstantin
Maurer, José Rebelo, Petr Vaněk, Johannes Krude
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util.preferences; package nodomain.freeyourgadget.gadgetbridge.util.preferences;
import java.util.Locale;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.*; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.*;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.text.format.DateFormat;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig; import nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public class DevicePrefs extends Prefs { public class DevicePrefs extends Prefs {
public DevicePrefs(final SharedPreferences preferences) { public DevicePrefs(final SharedPreferences preferences) {
@ -43,4 +67,49 @@ public class DevicePrefs extends Prefs {
public boolean getFetchUnknownFiles() { public boolean getFetchUnknownFiles() {
return getBoolean("fetch_unknown_files", false); return getBoolean("fetch_unknown_files", false);
} }
public String getTimeFormat() {
String timeFormat = getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO);
if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(timeFormat)) {
if (DateFormat.is24HourFormat(GBApplication.getContext())) {
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_24H;
} else {
timeFormat = DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_12H;
}
}
return timeFormat;
}
public String getDateFormatDayMonthOrder() {
String dateFormat = getString(DeviceSettingsPreferenceConst.PREF_DATEFORMAT, DeviceSettingsPreferenceConst.PREF_DATEFORMAT_AUTO);
if (DeviceSettingsPreferenceConst.PREF_TIMEFORMAT_AUTO.equals(dateFormat)) {
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dM");
boolean quoted = false;
for (char c: pattern.toCharArray()) {
if (c == '\'') {
quoted = !quoted;
continue;
}
if (quoted)
continue;
if (c == 'd')
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
if (c == 'M' || c == 'L')
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_MONTH_DAY;
}
return DeviceSettingsPreferenceConst.PREF_DATEFORMAT_DAY_MONTH;
}
return dateFormat;
}
public int getReservedReminderCalendarSlots(GBDevice gbDevice) {
if (!gbDevice.getDeviceCoordinator().getReserveReminderSlotsForCalendar())
return 0;
if (!getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false))
return 0;
return getInt(DeviceSettingsPreferenceConst.PREF_RESERVE_REMINDERS_CALENDAR, 9);
}
} }