use of nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes in project Gadgetbridge by Freeyourgadget.
the class EntitiesTest method testUser.
@Test
public void testUser() {
User user = new User();
user.setName("Peter");
user.setGender(ActivityUser.GENDER_FEMALE);
Calendar cal = GregorianCalendar.getInstance();
cal.add(Calendar.YEAR, -20);
user.setBirthday(cal.getTime());
UserAttributes attributes = new UserAttributes();
attributes.setWeightKG(55);
attributes.setHeightCM(170);
attributes.setSleepGoalHPD(8);
attributes.setStepsGoalSPD(10000);
daoSession.getUserDao().insert(user);
assertNotNull(user.getId());
attributes.setUserId(user.getId());
daoSession.getUserAttributesDao().insert(attributes);
user.getUserAttributesList().add(attributes);
assertNotNull(userDao.load(user.getId()));
assertEquals(1, userDao.count());
assertEquals(1, daoSession.loadAll(User.class).size());
assertNotNull(userAttributesDao.load(attributes.getId()));
assertEquals(1, userAttributesDao.count());
assertEquals(1, daoSession.loadAll(UserAttributes.class).size());
daoSession.getUserDao().update(user);
daoSession.delete(user);
daoSession.delete(attributes);
daoSession.delete(attributes);
assertNull(userDao.load(user.getId()));
}
use of nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes in project Gadgetbridge by Freeyourgadget.
the class DBHelper method ensureUserAttributes.
private static void ensureUserAttributes(User user, ActivityUser prefsUser, DaoSession session) {
List<UserAttributes> userAttributes = user.getUserAttributesList();
UserAttributes[] previousUserAttributes = new UserAttributes[1];
if (hasUpToDateUserAttributes(userAttributes, prefsUser, previousUserAttributes)) {
return;
}
Calendar now = DateTimeUtils.getCalendarUTC();
invalidateUserAttributes(previousUserAttributes[0], now, session);
UserAttributes attributes = new UserAttributes();
attributes.setValidFromUTC(now.getTime());
attributes.setHeightCM(prefsUser.getHeightCm());
attributes.setWeightKG(prefsUser.getWeightKg());
attributes.setSleepGoalHPD(prefsUser.getSleepDuration());
attributes.setStepsGoalSPD(prefsUser.getStepsGoal());
attributes.setUserId(user.getId());
session.getUserAttributesDao().insert(attributes);
// sort order is important, so we re-fetch from the db
// userAttributes.add(attributes);
user.resetUserAttributesList();
}
Aggregations