mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 10:56:50 +01:00
Huami: Send "about you" preferences to device immediately when changing values
Closes #2297
This commit is contained in:
parent
3eff54c807
commit
348f459e3f
@ -19,12 +19,17 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_ACTIVETIME_MINUTES;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_CALORIES_BURNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DISTANCE_METERS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GENDER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_SLEEP_DURATION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEP_LENGTH_CM;
|
||||
@ -36,6 +41,11 @@ public class AboutUserPreferencesActivity extends AbstractSettingsActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.about_user);
|
||||
addPreferenceHandlerFor(PREF_USER_NAME);
|
||||
addPreferenceHandlerFor(PREF_USER_YEAR_OF_BIRTH);
|
||||
addPreferenceHandlerFor(PREF_USER_HEIGHT_CM);
|
||||
addPreferenceHandlerFor(PREF_USER_WEIGHT_KG);
|
||||
addPreferenceHandlerFor(PREF_USER_GENDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -228,4 +228,19 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
|
||||
}
|
||||
AndroidUtils.setLanguage(this, language);
|
||||
}
|
||||
|
||||
protected void addPreferenceHandlerFor(final String preferenceKey) {
|
||||
Preference pref = findPreference(preferenceKey);
|
||||
if (pref != null) {
|
||||
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
GBApplication.deviceService().onSendConfiguration(preferenceKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
LOG.warn("Could not find preference " + preferenceKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||
|
||||
public final class MiBandConst {
|
||||
|
||||
public static final String PREF_USER_ALIAS = "mi_user_alias";
|
||||
public static final String PREF_MIBAND_ADDRESS = "development_miaddr"; // FIXME: should be prefixed mi_
|
||||
public static final String PREF_MIBAND_ALARMS = "mi_alarms";
|
||||
public static final String PREF_MIBAND_DONT_ACK_TRANSFER = "mi_dont_ack_transfer";
|
||||
|
@ -26,13 +26,14 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelUuid;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||
@ -51,6 +52,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
||||
|
||||
public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MiBandCoordinator.class);
|
||||
|
||||
@ -218,7 +221,7 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||
|
||||
UserInfo info = UserInfo.create(
|
||||
miBandAddress,
|
||||
prefs.getString(MiBandConst.PREF_USER_ALIAS, null),
|
||||
prefs.getString(PREF_USER_NAME, null),
|
||||
activityUser.getGender(),
|
||||
activityUser.getAge(),
|
||||
activityUser.getHeightCm(),
|
||||
|
@ -49,9 +49,9 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefKey;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
||||
|
||||
public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
||||
@Override
|
||||
@ -261,7 +261,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
||||
@Override
|
||||
protected String[] getPreferenceKeysWithSummary() {
|
||||
Set<String> prefKeys = new HashSet<>();
|
||||
prefKeys.add(PREF_USER_ALIAS);
|
||||
prefKeys.add(PREF_USER_NAME);
|
||||
prefKeys.add(PREF_MIBAND_ADDRESS);
|
||||
prefKeys.add(ActivityUser.PREF_USER_STEPS_GOAL);
|
||||
prefKeys.add(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD);
|
||||
|
@ -22,7 +22,6 @@ import android.preference.Preference;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
|
||||
public class ZeTimePreferenceActivity extends AbstractSettingsActivity {
|
||||
@Override
|
||||
@ -93,16 +92,6 @@ public class ZeTimePreferenceActivity extends AbstractSettingsActivity {
|
||||
addPreferenceHandlerFor(ZeTimeConstants.PREF_USER_ACTIVETIME_GOAL);
|
||||
}
|
||||
|
||||
private void addPreferenceHandlerFor(final String preferenceKey) {
|
||||
Preference pref = findPreference(preferenceKey);
|
||||
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||
GBApplication.deviceService().onSendConfiguration(preferenceKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* delayed execution so that the preferences are applied first
|
||||
*/
|
||||
|
@ -169,6 +169,11 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VI
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_PROFILE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefIntValue;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefStringValue;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GENDER;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL;
|
||||
|
||||
public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
@ -448,7 +453,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
LOG.info("Attempting to set user info...");
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
String alias = prefs.getString(MiBandConst.PREF_USER_ALIAS, null);
|
||||
String alias = prefs.getString(PREF_USER_NAME, null);
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int height = activityUser.getHeightCm();
|
||||
int weight = activityUser.getWeightKg();
|
||||
@ -2011,6 +2016,13 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
case PREF_SOUNDS:
|
||||
setBeepSounds(builder);
|
||||
break;
|
||||
case PREF_USER_NAME:
|
||||
case PREF_USER_YEAR_OF_BIRTH:
|
||||
case PREF_USER_WEIGHT_KG:
|
||||
case PREF_USER_HEIGHT_CM:
|
||||
case PREF_USER_GENDER:
|
||||
setUserInfo(builder);
|
||||
break;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user