WIP: more work, compile again
This commit is contained in:
parent
3b87966fe9
commit
ae548d0806
|
@ -30,6 +30,7 @@ public class GBDaoGenerator {
|
|||
public static final String VALID_TO_UTC = "validToUTC";
|
||||
private static final String MAIN_PACKAGE = "nodomain.freeyourgadget.gadgetbridge";
|
||||
private static final String MODEL_PACKAGE = MAIN_PACKAGE + ".model";
|
||||
private static final String VALID_BY_DATE = MODEL_PACKAGE + ".ValidByDate";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Schema schema = new Schema(7, MAIN_PACKAGE + ".entities");
|
||||
|
@ -89,12 +90,18 @@ public class GBDaoGenerator {
|
|||
userAttributes.addIntProperty("weightKG").notNull();
|
||||
userAttributes.addIntProperty("sleepGoalHPD");
|
||||
userAttributes.addIntProperty("stepsGoalSPD");
|
||||
userAttributes.addDateProperty(VALID_FROM_UTC);
|
||||
userAttributes.addDateProperty(VALID_TO_UTC);
|
||||
addDateValidityTo(userAttributes);
|
||||
|
||||
return userAttributes;
|
||||
}
|
||||
|
||||
private static void addDateValidityTo(Entity entity) {
|
||||
entity.addDateProperty(VALID_FROM_UTC);
|
||||
entity.addDateProperty(VALID_TO_UTC);
|
||||
|
||||
entity.implementsInterface(VALID_BY_DATE);
|
||||
}
|
||||
|
||||
private static Entity addDevice(Schema schema, Entity deviceAttributes) {
|
||||
Entity device = addEntity(schema, "Device");
|
||||
device.addIdProperty();
|
||||
|
@ -114,8 +121,7 @@ public class GBDaoGenerator {
|
|||
deviceAttributes.addIdProperty();
|
||||
deviceAttributes.addStringProperty("firmwareVersion1").notNull();
|
||||
deviceAttributes.addStringProperty("firmwareVersion2");
|
||||
deviceAttributes.addDateProperty(VALID_FROM_UTC);
|
||||
deviceAttributes.addDateProperty(VALID_TO_UTC);
|
||||
addDateValidityTo(deviceAttributes);
|
||||
|
||||
return deviceAttributes;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -25,6 +26,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.UserAttributes;
|
|||
import nodomain.freeyourgadget.gadgetbridge.entities.UserDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ValidByDate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
|
@ -175,7 +177,7 @@ public class DBHelper {
|
|||
|
||||
private static boolean hasUpToDateUserAttributes(List<UserAttributes> userAttributes, ActivityUser prefsUser) {
|
||||
for (UserAttributes attr : userAttributes) {
|
||||
if (!isActive(attr)) {
|
||||
if (!isValidNow(attr)) {
|
||||
return false;
|
||||
}
|
||||
if (isEqual(attr, prefsUser)) {
|
||||
|
@ -185,7 +187,38 @@ public class DBHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean isValidNow(ValidByDate element) {
|
||||
Calendar cal = DateTimeUtils.getCalendarUTC();
|
||||
Date nowUTC = cal.getTime();
|
||||
return isValid(element, nowUTC);
|
||||
}
|
||||
|
||||
private static boolean isValid(ValidByDate element, Date nowUTC) {
|
||||
Date validFromUTC = element.getValidFromUTC();
|
||||
Date validToUTC = element.getValidToUTC();
|
||||
if (nowUTC.before(validFromUTC)) {
|
||||
return false;
|
||||
}
|
||||
if (validToUTC != null && nowUTC.after(validToUTC)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isEqual(UserAttributes attr, ActivityUser prefsUser) {
|
||||
if (prefsUser.getHeightCm() != attr.getHeightCM()) {
|
||||
return false;
|
||||
}
|
||||
if (prefsUser.getWeightKg() != attr.getWeightKG()) {
|
||||
return false;
|
||||
}
|
||||
if (prefsUser.getSleepDuration() != attr.getSleepGoalHPD()) {
|
||||
return false;
|
||||
}
|
||||
if (prefsUser.getStepsGoal() != attr.getStepsGoalSPD()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Device getDevice(GBDevice gbDevice, DaoSession session) {
|
||||
|
|
|
@ -3,9 +3,9 @@ package nodomain.freeyourgadget.gadgetbridge.model;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
|
@ -15,11 +15,12 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|||
public class ActivityUser {
|
||||
|
||||
private String activityUserName;
|
||||
private Integer activityUserGender;
|
||||
private Integer activityUserYearOfBirth;
|
||||
private Integer activityUserHeightCm;
|
||||
private Integer activityUserWeightKg;
|
||||
private Integer activityUserSleepDuration;
|
||||
private int activityUserGender;
|
||||
private int activityUserYearOfBirth;
|
||||
private int activityUserHeightCm;
|
||||
private int activityUserWeightKg;
|
||||
private int activityUserSleepDuration;
|
||||
private int activityUserStepsGoal;
|
||||
|
||||
private static final String defaultUserName = "gadgetbridge-user";
|
||||
public static final int defaultUserGender = 0;
|
||||
|
@ -28,6 +29,7 @@ public class ActivityUser {
|
|||
public static final int defaultUserHeightCm = 175;
|
||||
public static final int defaultUserWeightKg = 70;
|
||||
public static final int defaultUserSleepDuration = 7;
|
||||
public static final int defaultUserStepsGoal = 8000;
|
||||
|
||||
public static final String PREF_USER_NAME = "mi_user_alias";
|
||||
public static final String PREF_USER_YEAR_OF_BIRTH = "activity_user_year_of_birth";
|
||||
|
@ -35,6 +37,7 @@ public class ActivityUser {
|
|||
public static final String PREF_USER_HEIGHT_CM = "activity_user_height_cm";
|
||||
public static final String PREF_USER_WEIGHT_KG = "activity_user_weight_kg";
|
||||
public static final String PREF_USER_SLEEP_DURATION = "activity_user_sleep_duration";
|
||||
public static final String PREF_USER_STEPS_GOAL = MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||
|
||||
public ActivityUser() {
|
||||
fetchPreferences();
|
||||
|
@ -71,6 +74,13 @@ public class ActivityUser {
|
|||
return activityUserSleepDuration;
|
||||
}
|
||||
|
||||
public int getStepsGoal() {
|
||||
if (activityUserStepsGoal < 0) {
|
||||
activityUserStepsGoal = defaultUserStepsGoal;
|
||||
}
|
||||
return activityUserStepsGoal;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
int userYear = getYearOfBirth();
|
||||
int age = 25;
|
||||
|
@ -91,6 +101,7 @@ public class ActivityUser {
|
|||
activityUserWeightKg = prefs.getInt(PREF_USER_WEIGHT_KG, defaultUserWeightKg);
|
||||
activityUserYearOfBirth = prefs.getInt(PREF_USER_YEAR_OF_BIRTH, defaultUserYearOfBirth);
|
||||
activityUserSleepDuration = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDuration);
|
||||
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
|
||||
}
|
||||
|
||||
public Date getUserBirthday() {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public interface ValidByDate {
|
||||
Date getValidFromUTC();
|
||||
Date getValidToUTC();
|
||||
}
|
|
@ -58,20 +58,18 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
private boolean store(OverlayRecord[] overlayRecords) {
|
||||
DBHandler dbHandler = null;
|
||||
SampleProvider sampleProvider = new HealthSampleProvider();
|
||||
try {
|
||||
dbHandler = GBApplication.acquireDB();
|
||||
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
SampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
||||
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
||||
for (OverlayRecord overlayRecord : overlayRecords) {
|
||||
if (latestTimestamp < (overlayRecord.timestampStart + overlayRecord.durationSeconds))
|
||||
return false;
|
||||
switch (overlayRecord.type) {
|
||||
case 1:
|
||||
dbHandler.changeStoredSamplesType(overlayRecord.timestampStart, (overlayRecord.timestampStart + overlayRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
sampleProvider.changeStoredSamplesType(overlayRecord.timestampStart, (overlayRecord.timestampStart + overlayRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP));
|
||||
break;
|
||||
case 2:
|
||||
dbHandler.changeStoredSamplesType(overlayRecord.timestampStart, (overlayRecord.timestampStart + overlayRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP), sampleProvider);
|
||||
sampleProvider.changeStoredSamplesType(overlayRecord.timestampStart, (overlayRecord.timestampStart + overlayRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP));
|
||||
break;
|
||||
default:
|
||||
//TODO: other values refer to unknown activity types.
|
||||
|
@ -79,10 +77,6 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.debug(ex.getMessage());
|
||||
} finally {
|
||||
if (dbHandler != null) {
|
||||
dbHandler.release();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1905,7 +1905,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
LOG.info("DATALOG OPENSESSION. id=" + (id & 0xff) + ", App UUID=" + uuid.toString() + ", log_tag=" + log_tag + ", item_type=" + item_type + ", itemSize=" + item_size);
|
||||
if (!mDatalogSessions.containsKey(id)) {
|
||||
if (uuid.equals(UUID_ZERO) && log_tag == 81) {
|
||||
mDatalogSessions.put(id, new DatalogSessionHealthSteps(id, uuid, log_tag, item_type, item_size, getDevice())));
|
||||
mDatalogSessions.put(id, new DatalogSessionHealthSteps(id, uuid, log_tag, item_type, item_size, getDevice()));
|
||||
} else if (uuid.equals(UUID_ZERO) && log_tag == 83) {
|
||||
mDatalogSessions.put(id, new DatalogSessionHealthSleep(id, uuid, log_tag, item_type, item_size));
|
||||
} else if (uuid.equals(UUID_ZERO) && log_tag == 84) {
|
||||
|
|
Loading…
Reference in New Issue