1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Add text column to BaseActivityData for storing unstructured data to be displayed later

As a test first test, this currently only stores the average heart rate.
This commit is contained in:
Andreas Shimokawa 2020-08-07 23:12:29 +02:00
parent 9b8f4d329e
commit 94afcba363
3 changed files with 56 additions and 3 deletions

View File

@ -43,7 +43,7 @@ public class GBDaoGenerator {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Schema schema = new Schema(28, MAIN_PACKAGE + ".entities"); Schema schema = new Schema(29, MAIN_PACKAGE + ".entities");
Entity userAttributes = addUserAttributes(schema); Entity userAttributes = addUserAttributes(schema);
Entity user = addUserInfo(schema, userAttributes); Entity user = addUserInfo(schema, userAttributes);
@ -83,7 +83,7 @@ public class GBDaoGenerator {
addNotificationFilterEntry(schema, notificationFilter); addNotificationFilterEntry(schema, notificationFilter);
addBipActivitySummary(schema, user, device); addActivitySummary(schema, user, device);
new DaoGenerator().generateAll(schema, "app/src/main/java"); new DaoGenerator().generateAll(schema, "app/src/main/java");
} }
@ -484,7 +484,7 @@ public class GBDaoGenerator {
return notificatonFilter; return notificatonFilter;
} }
private static void addBipActivitySummary(Schema schema, Entity user, Entity device) { private static void addActivitySummary(Schema schema, Entity user, Entity device) {
Entity summary = addEntity(schema, "BaseActivitySummary"); Entity summary = addEntity(schema, "BaseActivitySummary");
summary.implementsInterface(ACTIVITY_SUMMARY); summary.implementsInterface(ACTIVITY_SUMMARY);
summary.addIdProperty(); summary.addIdProperty();
@ -507,6 +507,7 @@ public class GBDaoGenerator {
summary.addToOne(device, deviceId); summary.addToOne(device, deviceId);
Property userId = summary.addLongProperty("userId").notNull().codeBeforeGetter(OVERRIDE).getProperty(); Property userId = summary.addLongProperty("userId").notNull().codeBeforeGetter(OVERRIDE).getProperty();
summary.addToOne(user, userId); summary.addToOne(user, userId);
summary.addStringProperty("summaryData");
} }
private static Property findProperty(Entity entity, String propertyName) { private static Property findProperty(Entity entity, String propertyName) {

View File

@ -0,0 +1,38 @@
/* Copyright (C) 2017-2020 Andreas Shimokawa, protomors
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.database.schema;
import android.database.sqlite.SQLiteDatabase;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
public class GadgetbridgeUpdate_29 implements DBUpdateScript {
@Override
public void upgradeSchema(SQLiteDatabase db) {
if (!DBHelper.existsColumn(BaseActivitySummaryDao.TABLENAME, BaseActivitySummaryDao.Properties.SummaryData.columnName, db)) {
String ADD_COLUMN_SUMMARY_DATA = "ALTER TABLE " + BaseActivitySummaryDao.TABLENAME + " ADD COLUMN "
+ BaseActivitySummaryDao.Properties.SummaryData.columnName + " TEXT";
db.execSQL(ADD_COLUMN_SUMMARY_DATA);
}
}
@Override
public void downgradeSchema(SQLiteDatabase db) {
}
}

View File

@ -21,6 +21,8 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.widget.Toast; import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -164,6 +166,8 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) { private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) {
BaseActivitySummary summary = new BaseActivitySummary(); BaseActivitySummary summary = new BaseActivitySummary();
JSONObject summaryData = new JSONObject();
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN); ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
// summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort())); // summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort()));
short version = buffer.getShort(); // version short version = buffer.getShort(); // version
@ -260,6 +264,15 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
} }
short averageHR = buffer.getShort(); short averageHR = buffer.getShort();
// this is just here for demonstration purboses for now
if (averageHR > 0) {
try {
summaryData.put("averageHR", averageHR);
} catch (JSONException ignore) {
}
}
short averageKMPaceSeconds = buffer.getShort(); short averageKMPaceSeconds = buffer.getShort();
short averageStride = buffer.getShort(); short averageStride = buffer.getShort();
@ -310,6 +323,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
// summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace); // summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace);
// summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride); // summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride);
summary.setSummaryData(summaryData.toString());
return summary; return summary;
} }