Search in sources :

Example 1 with ActivityDescription

use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.

the class EntitiesTest method testActivityDescription.

@Test
public void testActivityDescription() {
    User user = DBHelper.getUser(daoSession);
    assertNotNull(user);
    ActivityDescriptionDao descDao = daoSession.getActivityDescriptionDao();
    assertEquals(0, descDao.count());
    List<ActivityDescription> list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertTrue(list.isEmpty());
    ActivityDescription desc = DBHelper.createActivityDescription(user, 10, 100, daoSession);
    assertNotNull(desc);
    assertEquals(user, desc.getUser());
    assertEquals(10, desc.getTimestampFrom());
    assertEquals(100, desc.getTimestampTo());
    List<Tag> tagList = desc.getTagList();
    assertEquals(0, tagList.size());
    Tag t1 = DBHelper.getTag(user, "Table Tennis", daoSession);
    assertNotNull(t1);
    assertEquals("Table Tennis", t1.getName());
    t1.setDescription("Table tennis training for Olympia");
    tagList.add(t1);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(1, list.size());
    ActivityDescription desc1 = list.get(0);
    assertEquals(desc, desc1);
    assertEquals(1, desc1.getTagList().size());
    // check for partial range overlaps
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(1, list.size());
    // Now with a second, adjacent ActivityDescription
    ActivityDescription desc2 = DBHelper.createActivityDescription(user, 101, 200, daoSession);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(1, list.size());
    // Now with a third, partially overlapping ActivityDescription
    ActivityDescription desc3 = DBHelper.createActivityDescription(user, 5, 15, daoSession);
    list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
    assertEquals(1, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
    assertEquals(3, list.size());
    list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
    assertEquals(2, list.size());
    list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
    assertEquals(2, list.size());
}
Also used : ActivityUser(nodomain.freeyourgadget.gadgetbridge.model.ActivityUser) User(nodomain.freeyourgadget.gadgetbridge.entities.User) ActivityDescription(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription) ActivityDescriptionDao(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao) Tag(nodomain.freeyourgadget.gadgetbridge.entities.Tag) Test(org.junit.Test)

Example 2 with ActivityDescription

use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.

the class DBHelper method findActivityDecriptions.

@NonNull
public static List<ActivityDescription> findActivityDecriptions(@NonNull User user, int tsFrom, int tsTo, @NonNull DaoSession session) {
    Property tsFromProperty = ActivityDescriptionDao.Properties.TimestampFrom;
    Property tsToProperty = ActivityDescriptionDao.Properties.TimestampTo;
    Property userIdProperty = ActivityDescriptionDao.Properties.UserId;
    QueryBuilder<ActivityDescription> qb = session.getActivityDescriptionDao().queryBuilder();
    qb.where(userIdProperty.eq(user.getId()), isAtLeastPartiallyInRange(qb, tsFromProperty, tsToProperty, tsFrom, tsTo));
    List<ActivityDescription> descriptions = qb.build().list();
    return descriptions;
}
Also used : ActivityDescription(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription) Property(de.greenrobot.dao.Property) NonNull(android.support.annotation.NonNull)

Example 3 with ActivityDescription

use of nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription in project Gadgetbridge by Freeyourgadget.

the class DBHelper method createActivityDescription.

@NonNull
public static ActivityDescription createActivityDescription(@NonNull User user, int tsFrom, int tsTo, @NonNull DaoSession session) {
    ActivityDescription desc = new ActivityDescription();
    desc.setUser(user);
    desc.setTimestampFrom(tsFrom);
    desc.setTimestampTo(tsTo);
    session.getActivityDescriptionDao().insertOrReplace(desc);
    return desc;
}
Also used : ActivityDescription(nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription) NonNull(android.support.annotation.NonNull)

Aggregations

ActivityDescription (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription)3 NonNull (android.support.annotation.NonNull)2 Property (de.greenrobot.dao.Property)1 ActivityDescriptionDao (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao)1 Tag (nodomain.freeyourgadget.gadgetbridge.entities.Tag)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1 Test (org.junit.Test)1