diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index b65a26472..53707c79b 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -43,7 +43,7 @@ public class GBDaoGenerator { 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 user = addUserInfo(schema, userAttributes); @@ -83,7 +83,7 @@ public class GBDaoGenerator { addNotificationFilterEntry(schema, notificationFilter); - addBipActivitySummary(schema, user, device); + addActivitySummary(schema, user, device); new DaoGenerator().generateAll(schema, "app/src/main/java"); } @@ -484,7 +484,7 @@ public class GBDaoGenerator { 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"); summary.implementsInterface(ACTIVITY_SUMMARY); summary.addIdProperty(); @@ -507,6 +507,7 @@ public class GBDaoGenerator { summary.addToOne(device, deviceId); Property userId = summary.addLongProperty("userId").notNull().codeBeforeGetter(OVERRIDE).getProperty(); summary.addToOne(user, userId); + summary.addStringProperty("summaryData"); } private static Property findProperty(Entity entity, String propertyName) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_29.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_29.java new file mode 100644 index 000000000..7239e1fa3 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/schema/GadgetbridgeUpdate_29.java @@ -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 . */ +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) { + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java index d348b665b..e2c38f7ae 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/operations/FetchSportsSummaryOperation.java @@ -21,6 +21,8 @@ import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.widget.Toast; +import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -164,6 +166,8 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation { private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) { BaseActivitySummary summary = new BaseActivitySummary(); + JSONObject summaryData = new JSONObject(); + ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN); // summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort())); short version = buffer.getShort(); // version @@ -260,6 +264,15 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation { } 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 averageStride = buffer.getShort(); @@ -310,6 +323,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation { // summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace); // summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride); + summary.setSummaryData(summaryData.toString()); return summary; }