Search in sources :

Example 1 with UserAttributes

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()));
}
Also used : ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) User(nodomain.freeyourgadget.gadgetbridge.entities.User) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) UserAttributes(nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes) Test(org.junit.Test)

Example 2 with UserAttributes

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();
}
Also used : Calendar(java.util.Calendar) UserAttributes(nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes)

Aggregations

Calendar (java.util.Calendar)2 UserAttributes (nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes)2 GregorianCalendar (java.util.GregorianCalendar)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1 Test (org.junit.Test)1