1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Call onSetConfiguration() in listener if measurement system gets changed in preferences

(And implement onSetConfiguration() for HPlus)
This commit is contained in:
Andreas Shimokawa 2017-09-30 22:45:45 +02:00
parent 8e0688ba66
commit 6d8ffad55c
4 changed files with 38 additions and 4 deletions

View File

@ -61,6 +61,8 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
public class SettingsActivity extends AbstractSettingsActivity {
private static final Logger LOG = LoggerFactory.getLogger(SettingsActivity.class);
public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -172,6 +174,20 @@ public class SettingsActivity extends AbstractSettingsActivity {
});
final Preference unit = findPreference(PREF_MEASUREMENT_SYSTEM);
unit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
invokeLater(new Runnable() {
@Override
public void run() {
GBApplication.deviceService().onSendConfiguration(PREF_MEASUREMENT_SYSTEM);
}
});
return true;
}
});
if (!GBApplication.isRunningMarshmallowOrLater()) {
pref = findPreference("notification_filter");
PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications");
@ -268,6 +284,13 @@ public class SettingsActivity extends AbstractSettingsActivity {
audioPlayer.setDefaultValue(newValues[0]);
}
/*
* delayed execution so that the preferences are applied first
*/
private void invokeLater(Runnable runnable) {
getListView().post(runnable);
}
@Override
protected String[] getPreferenceKeysWithSummary() {
return new String[]{

View File

@ -127,7 +127,6 @@ public final class HPlusConstants {
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
public static final String PREF_HPLUS_UNIT = "measurement_system";
public static final String PREF_HPLUS_TIMEFORMAT = "hplus_timeformat";
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";

View File

@ -35,6 +35,7 @@ import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
@ -202,7 +203,7 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getUnit(String address) {
String units = prefs.getString(HPlusConstants.PREF_HPLUS_UNIT, getContext().getString(R.string.p_unit_metric));
String units = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, getContext().getString(R.string.p_unit_metric));
if(units.equals(getContext().getString(R.string.p_unit_metric))){
return HPlusConstants.ARG_UNIT_METRIC;

View File

@ -45,6 +45,7 @@ import java.util.List;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
@ -646,8 +647,18 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
@Override
public void onSendConfiguration(String config) {
LOG.info("Send Configuration: " + config);
TransactionBuilder builder;
try {
builder = performInitialized("Sending configuration for option: " + config);
switch (config) {
case SettingsActivity.PREF_MEASUREMENT_SYSTEM:
setUnit(builder);
break;
}
builder.queue(getQueue());
} catch (IOException e) {
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
}
}
@Override