Call onSetConfiguration() in listener if measurement system gets changed in preferences
(And implement onSetConfiguration() for HPlus)
This commit is contained in:
parent
8e0688ba66
commit
6d8ffad55c
|
@ -61,6 +61,8 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
|
||||||
public class SettingsActivity extends AbstractSettingsActivity {
|
public class SettingsActivity extends AbstractSettingsActivity {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(SettingsActivity.class);
|
private static final Logger LOG = LoggerFactory.getLogger(SettingsActivity.class);
|
||||||
|
|
||||||
|
public static final String PREF_MEASUREMENT_SYSTEM = "measurement_system";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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()) {
|
if (!GBApplication.isRunningMarshmallowOrLater()) {
|
||||||
pref = findPreference("notification_filter");
|
pref = findPreference("notification_filter");
|
||||||
PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications");
|
PreferenceCategory category = (PreferenceCategory) findPreference("pref_key_notifications");
|
||||||
|
@ -268,6 +284,13 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||||
audioPlayer.setDefaultValue(newValues[0]);
|
audioPlayer.setDefaultValue(newValues[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* delayed execution so that the preferences are applied first
|
||||||
|
*/
|
||||||
|
private void invokeLater(Runnable runnable) {
|
||||||
|
getListView().post(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getPreferenceKeysWithSummary() {
|
protected String[] getPreferenceKeysWithSummary() {
|
||||||
return new String[]{
|
return new String[]{
|
||||||
|
|
|
@ -127,7 +127,6 @@ public final class HPlusConstants {
|
||||||
|
|
||||||
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
|
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";
|
||||||
public static final String PREF_HPLUS_ALLDAYHR = "hplus_alldayhr";
|
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_TIMEFORMAT = "hplus_timeformat";
|
||||||
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
|
public static final String PREF_HPLUS_WRIST = "hplus_wrist";
|
||||||
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";
|
public static final String PREF_HPLUS_SIT_START_TIME = "hplus_sit_start_time";
|
||||||
|
|
|
@ -35,6 +35,7 @@ import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||||
|
@ -202,7 +203,7 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte getUnit(String address) {
|
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))){
|
if(units.equals(getContext().getString(R.string.p_unit_metric))){
|
||||||
return HPlusConstants.ARG_UNIT_METRIC;
|
return HPlusConstants.ARG_UNIT_METRIC;
|
||||||
|
|
|
@ -45,6 +45,7 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
|
||||||
|
@ -646,8 +647,18 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendConfiguration(String config) {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue