mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-11 18:35:49 +01:00
Initial support for user-configured activity descriptions
- for a given user and time span, there may be an ActivityDescription - with a textual description - and a list of tags - every tag has - a name - and an optional description
This commit is contained in:
parent
5ab40918c0
commit
350e72d534
@ -35,13 +35,13 @@ public class GBDaoGenerator {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Schema schema = new Schema(13, MAIN_PACKAGE + ".entities");
|
Schema schema = new Schema(13, MAIN_PACKAGE + ".entities");
|
||||||
|
|
||||||
addActivityDescription(schema);
|
|
||||||
|
|
||||||
Entity userAttributes = addUserAttributes(schema);
|
Entity userAttributes = addUserAttributes(schema);
|
||||||
Entity user = addUserInfo(schema, userAttributes);
|
Entity user = addUserInfo(schema, userAttributes);
|
||||||
|
|
||||||
Entity deviceAttributes = addDeviceAttributes(schema);
|
Entity deviceAttributes = addDeviceAttributes(schema);
|
||||||
Entity device = addDevice(schema, deviceAttributes);
|
Entity device = addDevice(schema, deviceAttributes);
|
||||||
|
Entity tag = addTag(schema);
|
||||||
|
Entity userDefinedActivityOverlay = addActivityDescription(schema, tag, user);
|
||||||
|
|
||||||
addMiBandActivitySample(schema, user, device);
|
addMiBandActivitySample(schema, user, device);
|
||||||
addPebbleHealthActivitySample(schema, user, device);
|
addPebbleHealthActivitySample(schema, user, device);
|
||||||
@ -52,12 +52,35 @@ public class GBDaoGenerator {
|
|||||||
new DaoGenerator().generateAll(schema, "app/src/main/java");
|
new DaoGenerator().generateAll(schema, "app/src/main/java");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity addActivityDescription(Schema schema) {
|
private static Entity addTag(Schema schema) {
|
||||||
Entity activityDescription = addEntity(schema, "ActivityDescription");
|
Entity tag = addEntity(schema, "Tag");
|
||||||
activityDescription.addIdProperty();
|
tag.addIdProperty();
|
||||||
activityDescription.addIntProperty("fromTimestamp").notNull();
|
tag.addStringProperty("name").notNull();
|
||||||
activityDescription.addIntProperty("toTimestamp");
|
tag.addStringProperty("description").javaDocGetterAndSetter("An optional description of this tag.");
|
||||||
return activityDescription;
|
tag.addLongProperty("userId");
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Entity addActivityDescription(Schema schema, Entity tag, Entity user) {
|
||||||
|
Entity activityDesc = addEntity(schema, "ActivityDescription");
|
||||||
|
activityDesc.setJavaDoc("A user may further specify his activity with a detailed description and the help of tags.\nOne or more tags can be added to a given activity range.");
|
||||||
|
activityDesc.addIdProperty();
|
||||||
|
activityDesc.addIntProperty("timestampFrom").notNull();
|
||||||
|
activityDesc.addIntProperty("timestampTo").notNull();
|
||||||
|
activityDesc.addStringProperty("details").javaDocGetterAndSetter("An optional detailed description, specific to this very activity occurrence.");
|
||||||
|
|
||||||
|
Property userId = activityDesc.addLongProperty("userId").notNull().getProperty();
|
||||||
|
activityDesc.addToOne(user, userId);
|
||||||
|
|
||||||
|
Entity activityDescTagLink = addEntity(schema, "ActivityDescTagLink");
|
||||||
|
activityDescTagLink.addIdProperty();
|
||||||
|
Property sourceId = activityDescTagLink.addLongProperty("activityDescriptionId").notNull().getProperty();
|
||||||
|
Property targetId = activityDescTagLink.addLongProperty("tagId").notNull().getProperty();
|
||||||
|
|
||||||
|
activityDesc.addToMany(tag, activityDescTagLink, sourceId, targetId);
|
||||||
|
|
||||||
|
return activityDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity addUserInfo(Schema schema, Entity userAttributes) {
|
private static Entity addUserInfo(Schema schema, Entity userAttributes) {
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -12,18 +13,23 @@ import java.io.IOException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import de.greenrobot.dao.Property;
|
||||||
import de.greenrobot.dao.query.Query;
|
import de.greenrobot.dao.query.Query;
|
||||||
|
import de.greenrobot.dao.query.QueryBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMisfitSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMisfitSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
||||||
@ -31,6 +37,8 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributesDao;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Tag;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.TagDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
||||||
@ -352,6 +360,50 @@ public class DBHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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()), tsFromProperty.ge(tsFrom))
|
||||||
|
.where(tsToProperty.le(tsTo));
|
||||||
|
List<ActivityDescription> descriptions = qb.build().list();
|
||||||
|
return descriptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.insertOrReplace(desc);
|
||||||
|
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Tag createTag(@NonNull User user, @NonNull String name, @NonNull String description, @NonNull DaoSession session) {
|
||||||
|
Tag tag = new Tag();
|
||||||
|
tag.setUserId(user.getId());
|
||||||
|
tag.setName(name);
|
||||||
|
tag.setDescription(description);
|
||||||
|
session.insertOrReplace(tag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the old activity database handler if there is any content in that
|
* Returns the old activity database handler if there is any content in that
|
||||||
* db, or null otherwise.
|
* db, or null otherwise.
|
||||||
|
@ -12,14 +12,18 @@ import org.robolectric.annotation.Config;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescription;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.ActivityDescriptionDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
import nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.Tag;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributesDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributesDao;
|
||||||
@ -28,9 +32,10 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(constants = BuildConfig.class, sdk = 19)
|
@Config(constants = BuildConfig.class, sdk = 19)
|
||||||
@ -98,19 +103,56 @@ public class EntitiesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDBHelper() {
|
public void testDBHelper() {
|
||||||
// DBHelper dbHelper = new DBHelper(RuntimeEnvironment.application);
|
GBDevice dummyGBDevice = createDummyGDevice();
|
||||||
GBDevice dummyGBDevice = new GBDevice("00:00:00:00:00", "Testie", DeviceType.TEST);
|
|
||||||
dummyGBDevice.setFirmwareVersion("1.2.3");
|
|
||||||
dummyGBDevice.setModel("4.0");
|
|
||||||
Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
|
Device device = DBHelper.getDevice(dummyGBDevice, daoSession);
|
||||||
assertNotNull(device);
|
assertNotNull(device);
|
||||||
assertEquals("00:00:00:00:00", device.getIdentifier());
|
assertEquals("00:00:00:00:00", device.getIdentifier());
|
||||||
assertEquals("Testie", device.getName());
|
assertEquals("Testie", device.getName());
|
||||||
// assertEquals("4.0", device.get());
|
assertEquals("4.0", device.getModel());
|
||||||
assertEquals(DeviceType.TEST.getKey(), device.getType());
|
assertEquals(DeviceType.TEST.getKey(), device.getType());
|
||||||
DeviceAttributes attributes = device.getDeviceAttributesList().get(0);
|
DeviceAttributes attributes = device.getDeviceAttributesList().get(0);
|
||||||
assertNotNull(attributes);
|
assertNotNull(attributes);
|
||||||
assertEquals("1.2.3", attributes.getFirmwareVersion1());
|
assertEquals("1.2.3", attributes.getFirmwareVersion1());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GBDevice createDummyGDevice() {
|
||||||
|
GBDevice dummyGBDevice = new GBDevice("00:00:00:00:00", "Testie", DeviceType.TEST);
|
||||||
|
dummyGBDevice.setFirmwareVersion("1.2.3");
|
||||||
|
dummyGBDevice.setModel("4.0");
|
||||||
|
return dummyGBDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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, 0, 10, daoSession);
|
||||||
|
assertTrue(list.isEmpty());
|
||||||
|
|
||||||
|
ActivityDescription desc = DBHelper.createActivityDescription(user, 0, 10, daoSession);
|
||||||
|
assertNotNull(desc);
|
||||||
|
assertEquals(user, desc.getUser());
|
||||||
|
assertEquals(0, desc.getTimestampFrom());
|
||||||
|
assertEquals(10, 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, 0, 10, daoSession);
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
ActivityDescription desc1 = list.get(0);
|
||||||
|
assertEquals(desc, desc1);
|
||||||
|
assertEquals(1, desc1.getTagList().size());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user