2016-02-02 17:33:24 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class holding the common user information needed by most activity trackers
|
|
|
|
*/
|
|
|
|
public class ActivityUser {
|
|
|
|
|
|
|
|
private Integer activityUserGender;
|
|
|
|
private Integer activityUserYearOfBirth;
|
|
|
|
private Integer activityUserHeightCm;
|
|
|
|
private Integer activityUserWeightKg;
|
|
|
|
|
|
|
|
public static final int defaultUserGender = 0;
|
|
|
|
public static final int defaultUserYearOfBirth = 0;
|
|
|
|
public static final int defaultUserAge = 0;
|
|
|
|
public static final int defaultUserHeightCm = 175;
|
|
|
|
public static final int defaultUserWeightKg = 70;
|
|
|
|
|
|
|
|
public static final String PREF_USER_YEAR_OF_BIRTH = "activity_user_year_of_birth";
|
|
|
|
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_WEIGHT_KG = "activity_user_weight_kg";
|
|
|
|
|
|
|
|
public int getActivityUserWeightKg() {
|
2016-02-29 20:54:39 +01:00
|
|
|
if (activityUserWeightKg == null) {
|
2016-02-02 17:33:24 +01:00
|
|
|
fetchPreferences();
|
|
|
|
}
|
|
|
|
return activityUserWeightKg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityUserGender() {
|
2016-02-29 20:54:39 +01:00
|
|
|
if (activityUserGender == null) {
|
2016-02-02 17:33:24 +01:00
|
|
|
fetchPreferences();
|
|
|
|
}
|
|
|
|
return activityUserGender;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityUserYearOfBirth() {
|
2016-02-29 20:54:39 +01:00
|
|
|
if (activityUserYearOfBirth == null) {
|
2016-02-02 17:33:24 +01:00
|
|
|
fetchPreferences();
|
|
|
|
}
|
|
|
|
return activityUserYearOfBirth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityUserHeightCm() {
|
2016-02-29 20:54:39 +01:00
|
|
|
if (activityUserHeightCm == null) {
|
2016-02-02 17:33:24 +01:00
|
|
|
fetchPreferences();
|
|
|
|
}
|
|
|
|
return activityUserHeightCm;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getActivityUserAge() {
|
|
|
|
int userYear = getActivityUserYearOfBirth();
|
|
|
|
int age = 25;
|
|
|
|
if (userYear > 1900) {
|
|
|
|
age = Calendar.getInstance().get(Calendar.YEAR) - userYear;
|
|
|
|
if (age <= 0) {
|
|
|
|
age = 25;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return age;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchPreferences() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
2016-02-21 13:04:32 +01:00
|
|
|
activityUserGender = Integer.parseInt(prefs.getString(PREF_USER_GENDER, Integer.toString(defaultUserGender)));
|
2016-02-02 17:33:24 +01:00
|
|
|
activityUserHeightCm = Integer.parseInt(prefs.getString(PREF_USER_HEIGHT_CM, Integer.toString(defaultUserHeightCm)));
|
|
|
|
activityUserWeightKg = Integer.parseInt(prefs.getString(PREF_USER_WEIGHT_KG, Integer.toString(defaultUserWeightKg)));
|
|
|
|
activityUserYearOfBirth = Integer.parseInt(prefs.getString(PREF_USER_YEAR_OF_BIRTH, Integer.toString(defaultUserYearOfBirth)));
|
|
|
|
}
|
|
|
|
}
|