Search in sources :

Example 1 with Tag

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

the class DBHelper method getTag.

@NonNull
public static Tag getTag(@NonNull User user, @NonNull String name, @NonNull DaoSession session) {
    TagDao tagDao = session.getTagDao();
    QueryBuilder<Tag> qb = tagDao.queryBuilder();
    Query<Tag> query = qb.where(TagDao.Properties.UserId.eq(user.getId()), TagDao.Properties.Name.eq(name)).build();
    List<Tag> tags = query.list();
    if (tags.size() > 0) {
        return tags.get(0);
    }
    return createTag(user, name, null, session);
}
Also used : TagDao(nodomain.freeyourgadget.gadgetbridge.entities.TagDao) Tag(nodomain.freeyourgadget.gadgetbridge.entities.Tag) NonNull(android.support.annotation.NonNull)

Example 2 with Tag

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

the class DBHelper method createTag.

static Tag createTag(@NonNull User user, @NonNull String name, @Nullable String description, @NonNull DaoSession session) {
    Tag tag = new Tag();
    tag.setUserId(user.getId());
    tag.setName(name);
    tag.setDescription(description);
    session.getTagDao().insertOrReplace(tag);
    return tag;
}
Also used : Tag(nodomain.freeyourgadget.gadgetbridge.entities.Tag)

Example 3 with Tag

use of nodomain.freeyourgadget.gadgetbridge.entities.Tag 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)

Aggregations

Tag (nodomain.freeyourgadget.gadgetbridge.entities.Tag)3 NonNull (android.support.annotation.NonNull)1 ActivityDescription (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription)1 ActivityDescriptionDao (nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao)1 TagDao (nodomain.freeyourgadget.gadgetbridge.entities.TagDao)1 User (nodomain.freeyourgadget.gadgetbridge.entities.User)1 ActivityUser (nodomain.freeyourgadget.gadgetbridge.model.ActivityUser)1 Test (org.junit.Test)1