mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-10-18 09:19:34 +02:00
Do not ack the sleep data until we can actually store them
Added helper method to fetch the latest timestamp stored in the DB, needed for the aforementioned feature. Update changelog This closes #188 \o/
This commit is contained in:
parent
7436778700
commit
8294921de7
@ -1,7 +1,7 @@
|
|||||||
###Changelog
|
###Changelog
|
||||||
|
|
||||||
####Version (next)
|
####Version (next)
|
||||||
* Pebble: Support reading Pebble Health steps/activity data
|
* Pebble: Support Pebble Health: steps/activity data are stored correctly. Sleep time is considered as light sleep. Deep sleep is discarded. The pebble will send data where it deems appropriate, there is no action to perform on the watch for this to happen.
|
||||||
|
|
||||||
####Version 0.7.4
|
####Version 0.7.4
|
||||||
* Refactored the settings activity: User details are now generic instead of miband specific. Old settings are preserved.
|
* Refactored the settings activity: User details are now generic instead of miband specific. Old settings are preserved.
|
||||||
|
@ -258,4 +258,16 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
|||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int fetchLatestTimestamp(SampleProvider provider) {
|
||||||
|
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
||||||
|
try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, new String[]{KEY_TIMESTAMP}, KEY_PROVIDER + "=" + String.valueOf(provider.getID()), null, null, null, KEY_TIMESTAMP + " DESC", "1")) {
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
return cursor.getInt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,4 +32,6 @@ public interface DBHandler {
|
|||||||
|
|
||||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider);
|
void changeStoredSamplesType(int timestampFrom, int timestampTo, byte kind, SampleProvider provider);
|
||||||
|
|
||||||
|
int fetchLatestTimestamp(SampleProvider provider);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,20 +50,21 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
|||||||
datalogMessage.getInt(),
|
datalogMessage.getInt(),
|
||||||
datalogMessage.getInt(),
|
datalogMessage.getInt(),
|
||||||
datalogMessage.getInt());
|
datalogMessage.getInt());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store(sleepRecords);
|
return store(sleepRecords);//NACK if we cannot store the data yet, the watch will send the sleep records again.
|
||||||
return true;//ACK by default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void store(SleepRecord[] sleepRecords) {
|
private boolean store(SleepRecord[] sleepRecords) {
|
||||||
DBHandler dbHandler = null;
|
DBHandler dbHandler = null;
|
||||||
SampleProvider sampleProvider = new HealthSampleProvider();
|
SampleProvider sampleProvider = new HealthSampleProvider();
|
||||||
GB.toast("We don't know how to store deep sleep from the pebble yet.", Toast.LENGTH_LONG, GB.INFO);
|
GB.toast("We don't know how to store deep sleep from the pebble yet.", Toast.LENGTH_LONG, GB.INFO);
|
||||||
try {
|
try {
|
||||||
dbHandler = GBApplication.acquireDB();
|
dbHandler = GBApplication.acquireDB();
|
||||||
|
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
|
||||||
for (SleepRecord sleepRecord : sleepRecords) {
|
for (SleepRecord sleepRecord : sleepRecords) {
|
||||||
|
if (latestTimestamp < sleepRecord.bedTimeEnd)
|
||||||
|
return false;
|
||||||
dbHandler.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
dbHandler.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -73,6 +74,7 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
|||||||
dbHandler.release();
|
dbHandler.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SleepRecord {
|
private class SleepRecord {
|
||||||
|
Loading…
Reference in New Issue
Block a user