mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 03:55:47 +02:00
Add month and day to date of birth
This commit is contained in:
parent
b59ba76803
commit
4da02fa851
@ -123,7 +123,7 @@ public class GBApplication extends Application {
|
|||||||
private static SharedPreferences sharedPrefs;
|
private static SharedPreferences sharedPrefs;
|
||||||
private static final String PREFS_VERSION = "shared_preferences_version";
|
private static final String PREFS_VERSION = "shared_preferences_version";
|
||||||
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
//if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version
|
||||||
private static final int CURRENT_PREFS_VERSION = 37;
|
private static final int CURRENT_PREFS_VERSION = 38;
|
||||||
|
|
||||||
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
private static final LimitedQueue<Integer, String> mIDSenderLookup = new LimitedQueue<>(16);
|
||||||
private static GBPrefs prefs;
|
private static GBPrefs prefs;
|
||||||
@ -735,7 +735,7 @@ public class GBApplication extends Application {
|
|||||||
editor.remove("mi_user_weight_kg");
|
editor.remove("mi_user_weight_kg");
|
||||||
}
|
}
|
||||||
if (legacyYOB != null) {
|
if (legacyYOB != null) {
|
||||||
editor.putString(ActivityUser.PREF_USER_YEAR_OF_BIRTH, legacyYOB);
|
editor.putString("activity_user_year_of_birth", legacyYOB);
|
||||||
editor.remove("mi_user_year_of_birth");
|
editor.remove("mi_user_year_of_birth");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1726,6 +1726,14 @@ public class GBApplication extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldVersion < 38) {
|
||||||
|
// Migrate year of birth to date of birth
|
||||||
|
final String yearOfBirth = sharedPrefs.getString("activity_user_year_of_birth", null);
|
||||||
|
if (StringUtils.isNotBlank(yearOfBirth)) {
|
||||||
|
editor.putString("activity_user_date_of_birth", String.format(Locale.ROOT, "%s-01-01", yearOfBirth.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
editor.putString(PREFS_VERSION, Integer.toString(CURRENT_PREFS_VERSION));
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
|
|||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_ACTIVETIME_MINUTES;
|
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_CALORIES_BURNT;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DATE_OF_BIRTH;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DISTANCE_METERS;
|
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_GENDER;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GOAL_FAT_BURN_TIME_MINUTES;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GOAL_FAT_BURN_TIME_MINUTES;
|
||||||
@ -29,7 +30,6 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEP_LENGTH_CM;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEP_LENGTH_CM;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -62,7 +62,7 @@ public class AboutUserPreferencesActivity extends AbstractSettingsActivityV2 {
|
|||||||
setPreferencesFromResource(R.xml.about_user, rootKey);
|
setPreferencesFromResource(R.xml.about_user, rootKey);
|
||||||
|
|
||||||
addPreferenceHandlerFor(PREF_USER_NAME, true, false);
|
addPreferenceHandlerFor(PREF_USER_NAME, true, false);
|
||||||
addPreferenceHandlerFor(PREF_USER_YEAR_OF_BIRTH, true, false);
|
addPreferenceHandlerFor(PREF_USER_DATE_OF_BIRTH, true, false);
|
||||||
addPreferenceHandlerFor(PREF_USER_HEIGHT_CM, true, true);
|
addPreferenceHandlerFor(PREF_USER_HEIGHT_CM, true, true);
|
||||||
addPreferenceHandlerFor(PREF_USER_WEIGHT_KG, true, false);
|
addPreferenceHandlerFor(PREF_USER_WEIGHT_KG, true, false);
|
||||||
addPreferenceHandlerFor(PREF_USER_GENDER, true, false);
|
addPreferenceHandlerFor(PREF_USER_GENDER, true, false);
|
||||||
@ -74,7 +74,6 @@ public class AboutUserPreferencesActivity extends AbstractSettingsActivityV2 {
|
|||||||
addPreferenceHandlerFor(PREF_USER_STEP_LENGTH_CM, false, true);
|
addPreferenceHandlerFor(PREF_USER_STEP_LENGTH_CM, false, true);
|
||||||
addPreferenceHandlerFor(PREF_USER_DISTANCE_METERS, false, true);
|
addPreferenceHandlerFor(PREF_USER_DISTANCE_METERS, false, true);
|
||||||
|
|
||||||
setInputTypeFor(PREF_USER_YEAR_OF_BIRTH, InputType.TYPE_CLASS_NUMBER);
|
|
||||||
setInputTypeFor(PREF_USER_HEIGHT_CM, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(PREF_USER_HEIGHT_CM, InputType.TYPE_CLASS_NUMBER);
|
||||||
setInputTypeFor(PREF_USER_WEIGHT_KG, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(PREF_USER_WEIGHT_KG, InputType.TYPE_CLASS_NUMBER);
|
||||||
setInputTypeFor(PREF_USER_STEPS_GOAL, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(PREF_USER_STEPS_GOAL, InputType.TYPE_CLASS_NUMBER);
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Period;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -36,7 +38,7 @@ public class ActivityUser {
|
|||||||
|
|
||||||
private String activityUserName;
|
private String activityUserName;
|
||||||
private int activityUserGender;
|
private int activityUserGender;
|
||||||
private int activityUserYearOfBirth;
|
private LocalDate activityUserDateOfBirth;
|
||||||
private int activityUserHeightCm;
|
private int activityUserHeightCm;
|
||||||
private int activityUserWeightKg;
|
private int activityUserWeightKg;
|
||||||
private int activityUserSleepDurationGoal;
|
private int activityUserSleepDurationGoal;
|
||||||
@ -49,7 +51,7 @@ public class ActivityUser {
|
|||||||
|
|
||||||
private static final String defaultUserName = "gadgetbridge-user";
|
private static final String defaultUserName = "gadgetbridge-user";
|
||||||
public static final int defaultUserGender = GENDER_FEMALE;
|
public static final int defaultUserGender = GENDER_FEMALE;
|
||||||
public static final int defaultUserYearOfBirth = 1970;
|
public static final String defaultUserDateOfBirth = "1970-01-01";
|
||||||
public static final int defaultUserAge = 0;
|
public static final int defaultUserAge = 0;
|
||||||
public static final int defaultUserHeightCm = 175;
|
public static final int defaultUserHeightCm = 175;
|
||||||
public static final int defaultUserWeightKg = 70;
|
public static final int defaultUserWeightKg = 70;
|
||||||
@ -64,7 +66,7 @@ public class ActivityUser {
|
|||||||
public static final int defaultUserFatBurnTimeMinutes = 30;
|
public static final int defaultUserFatBurnTimeMinutes = 30;
|
||||||
|
|
||||||
public static final String PREF_USER_NAME = "mi_user_alias";
|
public static final String PREF_USER_NAME = "mi_user_alias";
|
||||||
public static final String PREF_USER_YEAR_OF_BIRTH = "activity_user_year_of_birth";
|
public static final String PREF_USER_DATE_OF_BIRTH = "activity_user_date_of_birth";
|
||||||
public static final String PREF_USER_GENDER = "activity_user_gender";
|
public static final String PREF_USER_GENDER = "activity_user_gender";
|
||||||
public static final String PREF_USER_HEIGHT_CM = "activity_user_height_cm";
|
public static final String PREF_USER_HEIGHT_CM = "activity_user_height_cm";
|
||||||
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
|
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
|
||||||
@ -99,8 +101,8 @@ public class ActivityUser {
|
|||||||
return activityUserGender;
|
return activityUserGender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getYearOfBirth() {
|
public LocalDate getDateOfBirth() {
|
||||||
return activityUserYearOfBirth;
|
return activityUserDateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,15 +147,7 @@ public class ActivityUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getAge() {
|
public int getAge() {
|
||||||
int userYear = getYearOfBirth();
|
return Period.between(getDateOfBirth(), LocalDate.now()).getYears();
|
||||||
int age = 25;
|
|
||||||
if (userYear > 1900) {
|
|
||||||
age = Calendar.getInstance().get(Calendar.YEAR) - userYear;
|
|
||||||
if (age <= 0) {
|
|
||||||
age = 25;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return age;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchPreferences() {
|
private void fetchPreferences() {
|
||||||
@ -162,7 +156,7 @@ public class ActivityUser {
|
|||||||
activityUserGender = prefs.getInt(PREF_USER_GENDER, defaultUserGender);
|
activityUserGender = prefs.getInt(PREF_USER_GENDER, defaultUserGender);
|
||||||
activityUserHeightCm = prefs.getInt(PREF_USER_HEIGHT_CM, defaultUserHeightCm);
|
activityUserHeightCm = prefs.getInt(PREF_USER_HEIGHT_CM, defaultUserHeightCm);
|
||||||
activityUserWeightKg = prefs.getInt(PREF_USER_WEIGHT_KG, defaultUserWeightKg);
|
activityUserWeightKg = prefs.getInt(PREF_USER_WEIGHT_KG, defaultUserWeightKg);
|
||||||
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
activityUserDateOfBirth = prefs.getLocalDate(PREF_USER_DATE_OF_BIRTH, defaultUserDateOfBirth);
|
||||||
activityUserSleepDurationGoal = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDurationGoal);
|
activityUserSleepDurationGoal = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDurationGoal);
|
||||||
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
||||||
activityUserCaloriesBurntGoal = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurntGoal);
|
activityUserCaloriesBurntGoal = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurntGoal);
|
||||||
@ -172,9 +166,16 @@ public class ActivityUser {
|
|||||||
activityUserStepLengthCm = prefs.getInt(PREF_USER_STEP_LENGTH_CM, defaultUserStepLengthCm);
|
activityUserStepLengthCm = prefs.getInt(PREF_USER_STEP_LENGTH_CM, defaultUserStepLengthCm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use {@link #getDateOfBirth()}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public Date getUserBirthday() {
|
public Date getUserBirthday() {
|
||||||
|
final LocalDate dateOfBirth = getDateOfBirth();
|
||||||
Calendar cal = DateTimeUtils.getCalendarUTC();
|
Calendar cal = DateTimeUtils.getCalendarUTC();
|
||||||
cal.set(GregorianCalendar.YEAR, getYearOfBirth());
|
cal.set(GregorianCalendar.YEAR, dateOfBirth.getYear());
|
||||||
|
cal.set(GregorianCalendar.MONTH, dateOfBirth.getMonthValue() - 1);
|
||||||
|
cal.set(GregorianCalendar.DAY_OF_MONTH, dateOfBirth.getDayOfMonth());
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +69,12 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_PREVIEW_MESSAGE_IN_TITLE;
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_PREVIEW_MESSAGE_IN_TITLE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
|
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_ACTIVETIME_MINUTES;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_ACTIVETIME_MINUTES;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DATE_OF_BIRTH;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DISTANCE_METERS;
|
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_GENDER;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_HEIGHT_CM;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_STEPS_GOAL;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_WEIGHT_KG;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_YEAR_OF_BIRTH;
|
|
||||||
|
|
||||||
public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceSupport.class);
|
private static final Logger LOG = LoggerFactory.getLogger(CasioGBX100DeviceSupport.class);
|
||||||
@ -676,7 +676,7 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared
|
|||||||
case PREF_USER_WEIGHT_KG:
|
case PREF_USER_WEIGHT_KG:
|
||||||
new SetConfigurationOperation(this, CasioConstants.ConfigurationOption.OPTION_WEIGHT).perform();
|
new SetConfigurationOperation(this, CasioConstants.ConfigurationOption.OPTION_WEIGHT).perform();
|
||||||
break;
|
break;
|
||||||
case PREF_USER_YEAR_OF_BIRTH:
|
case PREF_USER_DATE_OF_BIRTH:
|
||||||
new SetConfigurationOperation(this, CasioConstants.ConfigurationOption.OPTION_BIRTHDAY).perform();
|
new SetConfigurationOperation(this, CasioConstants.ConfigurationOption.OPTION_BIRTHDAY).perform();
|
||||||
break;
|
break;
|
||||||
case PREF_TIMEFORMAT:
|
case PREF_TIMEFORMAT:
|
||||||
|
@ -24,6 +24,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -120,10 +121,10 @@ public class SetConfigurationOperation extends AbstractBTLEOperation<CasioGBX10
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(option == CasioConstants.ConfigurationOption.OPTION_BIRTHDAY || all) {
|
if(option == CasioConstants.ConfigurationOption.OPTION_BIRTHDAY || all) {
|
||||||
int year = user.getYearOfBirth();
|
LocalDate dateOfBirth = user.getDateOfBirth();
|
||||||
// Month and Day are not configured in Gadgetbridge!
|
int year = dateOfBirth.getYear();
|
||||||
int month = 1;
|
int month = dateOfBirth.getMonthValue();
|
||||||
int day = 1;
|
int day = dateOfBirth.getDayOfMonth();
|
||||||
data[6] = BcdUtil.toBcd8(year % 100);
|
data[6] = BcdUtil.toBcd8(year % 100);
|
||||||
data[7] = BcdUtil.toBcd8((year - (year % 100)) / 100);
|
data[7] = BcdUtil.toBcd8((year - (year % 100)) / 100);
|
||||||
data[8] = BcdUtil.toBcd8(month);
|
data[8] = BcdUtil.toBcd8(month);
|
||||||
|
@ -491,7 +491,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||||
case ActivityUser.PREF_USER_GENDER:
|
case ActivityUser.PREF_USER_GENDER:
|
||||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||||
case ActivityUser.PREF_USER_YEAR_OF_BIRTH:
|
case ActivityUser.PREF_USER_DATE_OF_BIRTH:
|
||||||
setUserData(builder);
|
setUserData(builder);
|
||||||
break;
|
break;
|
||||||
case ActivityUser.PREF_USER_STEPS_GOAL:
|
case ActivityUser.PREF_USER_STEPS_GOAL:
|
||||||
|
@ -123,7 +123,7 @@ public final class HamaFit6900DeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||||
case ActivityUser.PREF_USER_GENDER:
|
case ActivityUser.PREF_USER_GENDER:
|
||||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||||
case ActivityUser.PREF_USER_YEAR_OF_BIRTH:
|
case ActivityUser.PREF_USER_DATE_OF_BIRTH:
|
||||||
case DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL:
|
case DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL:
|
||||||
sendMessage("update-user-info", makeSetUserInfoMessage());
|
sendMessage("update-user-info", makeSetUserInfoMessage());
|
||||||
return;
|
return;
|
||||||
|
@ -48,6 +48,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.zone.ZoneOffsetTransition;
|
import java.time.zone.ZoneOffsetTransition;
|
||||||
import java.time.zone.ZoneRules;
|
import java.time.zone.ZoneRules;
|
||||||
@ -285,11 +286,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.VIBRATION_PROFILE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefIntValue;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefIntValue;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefStringValue;
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefStringValue;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_DATE_OF_BIRTH;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_GENDER;
|
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_HEIGHT_CM;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivityUser.PREF_USER_NAME;
|
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_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;
|
import static nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL;
|
||||||
|
|
||||||
public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements Huami2021Handler {
|
public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements Huami2021Handler {
|
||||||
@ -646,9 +647,10 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
|||||||
ActivityUser activityUser = new ActivityUser();
|
ActivityUser activityUser = new ActivityUser();
|
||||||
int height = activityUser.getHeightCm();
|
int height = activityUser.getHeightCm();
|
||||||
int weight = activityUser.getWeightKg();
|
int weight = activityUser.getWeightKg();
|
||||||
int birth_year = activityUser.getYearOfBirth();
|
LocalDate dateOfBirth = activityUser.getDateOfBirth();
|
||||||
byte birth_month = 7; // not in user attributes
|
int birth_year = dateOfBirth.getYear();
|
||||||
byte birth_day = 1; // not in user attributes
|
byte birth_month = (byte) dateOfBirth.getMonthValue();
|
||||||
|
byte birth_day = (byte) dateOfBirth.getDayOfMonth();
|
||||||
|
|
||||||
if (alias == null || weight == 0 || height == 0 || birth_year == 0) {
|
if (alias == null || weight == 0 || height == 0 || birth_year == 0) {
|
||||||
LOG.warn("Unable to set user info, make sure it is set up");
|
LOG.warn("Unable to set user info, make sure it is set up");
|
||||||
@ -2914,8 +2916,8 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
|||||||
case PREF_SOUNDS:
|
case PREF_SOUNDS:
|
||||||
setBeepSounds(builder);
|
setBeepSounds(builder);
|
||||||
break;
|
break;
|
||||||
|
case PREF_USER_DATE_OF_BIRTH:
|
||||||
case PREF_USER_NAME:
|
case PREF_USER_NAME:
|
||||||
case PREF_USER_YEAR_OF_BIRTH:
|
|
||||||
case PREF_USER_WEIGHT_KG:
|
case PREF_USER_WEIGHT_KG:
|
||||||
case PREF_USER_HEIGHT_CM:
|
case PREF_USER_HEIGHT_CM:
|
||||||
case PREF_USER_GENDER:
|
case PREF_USER_GENDER:
|
||||||
|
@ -61,6 +61,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -458,9 +459,10 @@ public class ZeppOsSupport extends HuamiSupport implements ZeppOsFileTransferSer
|
|||||||
final ActivityUser activityUser = new ActivityUser();
|
final ActivityUser activityUser = new ActivityUser();
|
||||||
final int height = activityUser.getHeightCm();
|
final int height = activityUser.getHeightCm();
|
||||||
final int weight = activityUser.getWeightKg();
|
final int weight = activityUser.getWeightKg();
|
||||||
final int birthYear = activityUser.getYearOfBirth();
|
final LocalDate dateOfBirth = activityUser.getDateOfBirth();
|
||||||
final byte birthMonth = 7; // not in user attributes
|
final int birthYear = dateOfBirth.getYear();
|
||||||
final byte birthDay = 1; // not in user attributes
|
final byte birthMonth = (byte) dateOfBirth.getMonthValue();
|
||||||
|
final byte birthDay = (byte) dateOfBirth.getDayOfMonth();
|
||||||
final String region = devicePrefs.getString(DeviceSettingsPreferenceConst.PREF_DEVICE_REGION, "unknown");
|
final String region = devicePrefs.getString(DeviceSettingsPreferenceConst.PREF_DEVICE_REGION, "unknown");
|
||||||
|
|
||||||
if (alias == null || weight == 0 || height == 0 || birthYear == 0) {
|
if (alias == null || weight == 0 || height == 0 || birthYear == 0) {
|
||||||
|
@ -1071,7 +1071,7 @@ public class HuaweiSupportProvider {
|
|||||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||||
case ActivityUser.PREF_USER_GENDER:
|
case ActivityUser.PREF_USER_GENDER:
|
||||||
case ActivityUser.PREF_USER_YEAR_OF_BIRTH:
|
case ActivityUser.PREF_USER_DATE_OF_BIRTH:
|
||||||
sendUserInfo();
|
sendUserInfo();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
|
||||||
@ -50,12 +49,10 @@ public class SendFitnessUserInfoRequest extends Request {
|
|||||||
gender = 1;
|
gender = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date birthday = activityUser.getUserBirthday();
|
LocalDate dateOfBirth = activityUser.getDateOfBirth();
|
||||||
Calendar cal = Calendar.getInstance();
|
int birthdayEncoded = dateOfBirth.getYear() << 16;
|
||||||
cal.setTime(birthday);
|
birthdayEncoded += dateOfBirth.getMonthValue() << 8;
|
||||||
int birthdayEncoded = cal.get(Calendar.YEAR) << 16;
|
birthdayEncoded += dateOfBirth.getDayOfMonth();
|
||||||
birthdayEncoded += (cal.get(Calendar.MONTH)+1) << 8;
|
|
||||||
birthdayEncoded += cal.get(Calendar.DAY_OF_MONTH);
|
|
||||||
|
|
||||||
return new UserInfo.Request(paramsProvider,
|
return new UserInfo.Request(paramsProvider,
|
||||||
activityUser.getHeightCm(),
|
activityUser.getHeightCm(),
|
||||||
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -843,7 +844,8 @@ public class SonyWena3DeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private void sendActivityGoalSettings(TransactionBuilder b) {
|
private void sendActivityGoalSettings(TransactionBuilder b) {
|
||||||
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
||||||
ActivityUser user = new ActivityUser();
|
ActivityUser user = new ActivityUser();
|
||||||
if(user.getYearOfBirth() < 1920) {
|
LocalDate dateOfBirth = user.getDateOfBirth();
|
||||||
|
if(dateOfBirth.getYear() < 1920) {
|
||||||
LOG.error("Device does not support this year of birth");
|
LOG.error("Device does not support this year of birth");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -851,8 +853,16 @@ public class SonyWena3DeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
GenderSetting gender = user.getGender() == ActivityUser.GENDER_FEMALE ? GenderSetting.FEMALE : GenderSetting.MALE;
|
GenderSetting gender = user.getGender() == ActivityUser.GENDER_FEMALE ? GenderSetting.FEMALE : GenderSetting.MALE;
|
||||||
|
|
||||||
|
|
||||||
// Maybe we need to set the full birth date?
|
// Maybe we need to set the full birth date?
|
||||||
BodyPropertiesSetting bodyPropertiesSetting = new BodyPropertiesSetting(gender, (short)user.getYearOfBirth(), (short)0, (short)1, (short)user.getHeightCm(), (short)user.getWeightKg());
|
BodyPropertiesSetting bodyPropertiesSetting = new BodyPropertiesSetting(
|
||||||
|
gender,
|
||||||
|
(short)dateOfBirth.getYear(),
|
||||||
|
(short)dateOfBirth.getMonthValue(),
|
||||||
|
(short)dateOfBirth.getDayOfMonth(),
|
||||||
|
(short)user.getHeightCm(),
|
||||||
|
(short)user.getWeightKg()
|
||||||
|
);
|
||||||
GoalStepsSetting stepsSetting = new GoalStepsSetting(stepsNotification, user.getStepsGoal());
|
GoalStepsSetting stepsSetting = new GoalStepsSetting(stepsNotification, user.getStepsGoal());
|
||||||
|
|
||||||
b.write(
|
b.write(
|
||||||
@ -1034,7 +1044,7 @@ public class SonyWena3DeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
sendHomeScreenSettings(builder);
|
sendHomeScreenSettings(builder);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ActivityUser.PREF_USER_YEAR_OF_BIRTH:
|
case ActivityUser.PREF_USER_DATE_OF_BIRTH:
|
||||||
case ActivityUser.PREF_USER_GENDER:
|
case ActivityUser.PREF_USER_GENDER:
|
||||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||||
|
@ -25,15 +25,15 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.sony.wena3.protocol.
|
|||||||
public class BodyPropertiesSetting implements Wena3Packetable {
|
public class BodyPropertiesSetting implements Wena3Packetable {
|
||||||
public final GenderSetting gender;
|
public final GenderSetting gender;
|
||||||
public final short yearOfBirth;
|
public final short yearOfBirth;
|
||||||
public final short monthOfBirthZeroIndexed;
|
public final short monthOfBirth;
|
||||||
public final short dayOfBirth;
|
public final short dayOfBirth;
|
||||||
public final short height;
|
public final short height;
|
||||||
public final short weight;
|
public final short weight;
|
||||||
|
|
||||||
public BodyPropertiesSetting(GenderSetting gender, short yearOfBirth, short monthOfBirthZeroIndexed, short dayOfBirth, short height, short weight) {
|
public BodyPropertiesSetting(GenderSetting gender, short yearOfBirth, short monthOfBirth, short dayOfBirth, short height, short weight) {
|
||||||
this.gender = gender;
|
this.gender = gender;
|
||||||
this.yearOfBirth = yearOfBirth;
|
this.yearOfBirth = yearOfBirth;
|
||||||
this.monthOfBirthZeroIndexed = monthOfBirthZeroIndexed;
|
this.monthOfBirth = monthOfBirth;
|
||||||
this.dayOfBirth = dayOfBirth;
|
this.dayOfBirth = dayOfBirth;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
@ -46,7 +46,7 @@ public class BodyPropertiesSetting implements Wena3Packetable {
|
|||||||
.put((byte) 0x1D)
|
.put((byte) 0x1D)
|
||||||
.put((byte) gender.ordinal())
|
.put((byte) gender.ordinal())
|
||||||
.putShort(yearOfBirth)
|
.putShort(yearOfBirth)
|
||||||
.put((byte) (monthOfBirthZeroIndexed + 1)) // Java uses 0-indexed months
|
.put((byte) monthOfBirth)
|
||||||
.put((byte) dayOfBirth)
|
.put((byte) dayOfBirth)
|
||||||
.putShort((short) (height * 10))
|
.putShort((short) (height * 10))
|
||||||
.putShort((short) (weight * 10))
|
.putShort((short) (weight * 10))
|
||||||
|
@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -209,7 +210,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
|||||||
switch (config) {
|
switch (config) {
|
||||||
case ActivityUser.PREF_USER_HEIGHT_CM:
|
case ActivityUser.PREF_USER_HEIGHT_CM:
|
||||||
case ActivityUser.PREF_USER_WEIGHT_KG:
|
case ActivityUser.PREF_USER_WEIGHT_KG:
|
||||||
case ActivityUser.PREF_USER_YEAR_OF_BIRTH:
|
case ActivityUser.PREF_USER_DATE_OF_BIRTH:
|
||||||
case ActivityUser.PREF_USER_GENDER:
|
case ActivityUser.PREF_USER_GENDER:
|
||||||
case ActivityUser.PREF_USER_CALORIES_BURNT:
|
case ActivityUser.PREF_USER_CALORIES_BURNT:
|
||||||
case ActivityUser.PREF_USER_STEPS_GOAL:
|
case ActivityUser.PREF_USER_STEPS_GOAL:
|
||||||
@ -260,14 +261,14 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
|||||||
LOG.debug("Setting user info");
|
LOG.debug("Setting user info");
|
||||||
|
|
||||||
final ActivityUser activityUser = new ActivityUser();
|
final ActivityUser activityUser = new ActivityUser();
|
||||||
final int birthYear = activityUser.getYearOfBirth();
|
final LocalDate dateOfBirth = activityUser.getDateOfBirth();
|
||||||
final byte birthMonth = 7; // not in user attributes
|
final int birthYear = dateOfBirth.getYear();
|
||||||
final byte birthDay = 1; // not in user attributes
|
final byte birthMonth = (byte) dateOfBirth.getMonthValue();
|
||||||
|
final byte birthDay = (byte) dateOfBirth.getDayOfMonth();
|
||||||
|
|
||||||
final int genderInt = activityUser.getGender() != ActivityUser.GENDER_FEMALE ? GENDER_MALE : GENDER_FEMALE; // TODO other gender?
|
final int genderInt = activityUser.getGender() != ActivityUser.GENDER_FEMALE ? GENDER_MALE : GENDER_FEMALE; // TODO other gender?
|
||||||
|
|
||||||
final Calendar now = GregorianCalendar.getInstance();
|
final int age = activityUser.getAge();
|
||||||
final int age = now.get(Calendar.YEAR) - birthYear;
|
|
||||||
// Compute the approximate max heart rate from the user age
|
// Compute the approximate max heart rate from the user age
|
||||||
// TODO max heart rate should be input by the user
|
// TODO max heart rate should be input by the user
|
||||||
int maxHeartRate = (int) Math.round(age <= 40 ? 220 - age : 207 - 0.7 * age);
|
int maxHeartRate = (int) Math.round(age <= 40 ? 220 - age : 207 - 0.7 * age);
|
||||||
|
@ -21,6 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -212,6 +213,24 @@ public class Prefs {
|
|||||||
return LocalTime.now();
|
return LocalTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDate getLocalDate(final String key, final String defaultValue) {
|
||||||
|
final String time = getString(key, defaultValue);
|
||||||
|
|
||||||
|
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
|
||||||
|
try {
|
||||||
|
final Date parse = df.parse(time);
|
||||||
|
final Calendar calendar = GregorianCalendar.getInstance();
|
||||||
|
calendar.setTime(parse);
|
||||||
|
|
||||||
|
return LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
Log.e(TAG, "Error reading localdate preference value: " + key + "; returning default current day", e); // log the first exception
|
||||||
|
}
|
||||||
|
|
||||||
|
return LocalDate.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void logReadError(String key, Exception ex) {
|
private void logReadError(String key, Exception ex) {
|
||||||
Log.e(TAG, "Error reading preference value: " + key + "; returning default value", ex); // log the first exception
|
Log.e(TAG, "Error reading preference value: " + key + "; returning default value", ex); // log the first exception
|
||||||
}
|
}
|
||||||
|
@ -1160,6 +1160,7 @@
|
|||||||
<string name="waiting_for_reconnect">Waiting for reconnect</string>
|
<string name="waiting_for_reconnect">Waiting for reconnect</string>
|
||||||
<string name="activity_prefs_about_you">About you</string>
|
<string name="activity_prefs_about_you">About you</string>
|
||||||
<string name="activity_prefs_goals">Goals</string>
|
<string name="activity_prefs_goals">Goals</string>
|
||||||
|
<string name="activity_prefs_date_birth">Date of birth</string>
|
||||||
<string name="activity_prefs_year_birth">Year of birth</string>
|
<string name="activity_prefs_year_birth">Year of birth</string>
|
||||||
<string name="activity_prefs_gender">Gender</string>
|
<string name="activity_prefs_gender">Gender</string>
|
||||||
<string name="activity_prefs_height_cm">Height in cm</string>
|
<string name="activity_prefs_height_cm">Height in cm</string>
|
||||||
|
@ -13,13 +13,10 @@
|
|||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<EditTextPreference
|
<nodomain.freeyourgadget.gadgetbridge.util.XDatePreference
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
android:inputType="number"
|
android:key="activity_user_date_of_birth"
|
||||||
android:key="activity_user_year_of_birth"
|
android:title="@string/activity_prefs_date_birth" />
|
||||||
android:maxLength="4"
|
|
||||||
android:title="@string/activity_prefs_year_birth"
|
|
||||||
app:useSimpleSummaryProvider="true" />
|
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
|
Loading…
Reference in New Issue
Block a user