mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Huawei: fix workouts pace
This commit is contained in:
parent
58a8c91c80
commit
af64ff3a79
@ -54,7 +54,7 @@ public class GBDaoGenerator {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final Schema schema = new Schema(82, MAIN_PACKAGE + ".entities");
|
||||
final Schema schema = new Schema(83, MAIN_PACKAGE + ".entities");
|
||||
|
||||
Entity userAttributes = addUserAttributes(schema);
|
||||
Entity user = addUserInfo(schema, userAttributes);
|
||||
@ -1418,10 +1418,12 @@ public class GBDaoGenerator {
|
||||
Property id = workoutPaceSample.addLongProperty("workoutId").primaryKey().notNull().getProperty();
|
||||
workoutPaceSample.addToOne(summaryEntity, id);
|
||||
|
||||
workoutPaceSample.addIntProperty("paceIndex").notNull().primaryKey();
|
||||
workoutPaceSample.addIntProperty("distance").notNull().primaryKey();
|
||||
workoutPaceSample.addByteProperty("type").notNull().primaryKey();
|
||||
workoutPaceSample.addIntProperty("pace").notNull();
|
||||
workoutPaceSample.addIntProperty("correction").notNull();
|
||||
workoutPaceSample.addIntProperty("pointIndex").notNull();
|
||||
workoutPaceSample.addIntProperty("correction");
|
||||
|
||||
return workoutPaceSample;
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
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.HuaweiWorkoutPaceSampleDao;
|
||||
|
||||
public class GadgetbridgeUpdate_83 implements DBUpdateScript {
|
||||
@Override
|
||||
public void upgradeSchema(final SQLiteDatabase db) {
|
||||
if (!DBHelper.existsColumn(HuaweiWorkoutPaceSampleDao.TABLENAME, HuaweiWorkoutPaceSampleDao.Properties.PaceIndex.columnName, db) && !DBHelper.existsColumn(HuaweiWorkoutPaceSampleDao.TABLENAME, HuaweiWorkoutPaceSampleDao.Properties.PointIndex.columnName, db)) {
|
||||
String MOVE_DATA_TO_TEMP_TABLE = "ALTER TABLE " + HuaweiWorkoutPaceSampleDao.TABLENAME + " RENAME TO " +HuaweiWorkoutPaceSampleDao.TABLENAME + "_temp;";
|
||||
db.execSQL(MOVE_DATA_TO_TEMP_TABLE);
|
||||
|
||||
String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS \"" + HuaweiWorkoutPaceSampleDao.TABLENAME +
|
||||
"\" (\""+HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.columnName+"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.PaceIndex.columnName +"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.Distance.columnName +"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.Type.columnName +"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.Pace.columnName +"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.PointIndex.columnName +"\" INTEGER NOT NULL ," +
|
||||
"\""+ HuaweiWorkoutPaceSampleDao.Properties.Correction.columnName +"\" INTEGER ," +
|
||||
"PRIMARY KEY (\""+HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.columnName+"\" ,\""+ HuaweiWorkoutPaceSampleDao.Properties.PaceIndex.columnName +"\" ,\""+ HuaweiWorkoutPaceSampleDao.Properties.Distance.columnName +"\", \""+ HuaweiWorkoutPaceSampleDao.Properties.Type.columnName +"\") ON CONFLICT REPLACE) WITHOUT ROWID;";
|
||||
db.execSQL(CREATE_TABLE);
|
||||
|
||||
String MIGATE_DATA = "INSERT INTO " + HuaweiWorkoutPaceSampleDao.TABLENAME
|
||||
+ " (" +HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.columnName+ ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.PaceIndex.columnName + ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.Distance.columnName+ ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.Type.columnName + ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.Pace.columnName + ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.PointIndex.columnName + ","
|
||||
+ HuaweiWorkoutPaceSampleDao.Properties.Correction.columnName + ") "
|
||||
+ " SELECT WORKOUT_ID, 0, DISTANCE, TYPE, PACE, 0, CORRECTION FROM " +HuaweiWorkoutPaceSampleDao.TABLENAME + "_temp;";
|
||||
|
||||
db.execSQL(MIGATE_DATA);
|
||||
|
||||
String DROP_TEMP_TABLE = "drop table if exists " +HuaweiWorkoutPaceSampleDao.TABLENAME + "_temp;";
|
||||
db.execSQL(DROP_TEMP_TABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downgradeSchema(final SQLiteDatabase db) {
|
||||
}
|
||||
}
|
@ -475,7 +475,9 @@ public class Workout {
|
||||
public short distance = -1;
|
||||
public byte type = -1;
|
||||
public int pace = -1;
|
||||
public short pointIndex = 0;
|
||||
public short correction = 0;
|
||||
public boolean hasCorrection = false;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -483,7 +485,9 @@ public class Workout {
|
||||
"distance=" + distance +
|
||||
", type=" + type +
|
||||
", pace=" + pace +
|
||||
", pointIndex=" + pointIndex +
|
||||
", correction=" + correction +
|
||||
", hasCorrection=" + hasCorrection +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -509,8 +513,12 @@ public class Workout {
|
||||
block.distance = blockTlv.getShort(0x04);
|
||||
block.type = blockTlv.getByte(0x05);
|
||||
block.pace = blockTlv.getInteger(0x06);
|
||||
if (blockTlv.contains(0x09))
|
||||
if (blockTlv.contains(0x07))
|
||||
block.pointIndex = blockTlv.getShort(0x07);
|
||||
if (blockTlv.contains(0x09)) {
|
||||
block.hasCorrection = true;
|
||||
block.correction = blockTlv.getShort(0x09);
|
||||
}
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import de.greenrobot.dao.query.DeleteQuery;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -546,13 +547,15 @@ public class HuaweiSupportProvider {
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeDeviceNotify() {} //TODO
|
||||
protected void initializeDeviceNotify() {
|
||||
} //TODO
|
||||
|
||||
RequestCallback configureReq = new RequestCallback() {
|
||||
@Override
|
||||
public void call() {
|
||||
initializeDeviceConfigure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void timeout(Request request) {
|
||||
LOG.error("Authentication timed out");
|
||||
@ -563,6 +566,7 @@ public class HuaweiSupportProvider {
|
||||
GBApplication.deviceService(device).disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleException(Request.ResponseParseException e) {
|
||||
LOG.error("Authentication exception", e);
|
||||
@ -1675,13 +1679,23 @@ public class HuaweiSupportProvider {
|
||||
try (DBHandler db = GBApplication.acquireDB()) {
|
||||
HuaweiWorkoutPaceSampleDao dao = db.getDaoSession().getHuaweiWorkoutPaceSampleDao();
|
||||
|
||||
final DeleteQuery<HuaweiWorkoutPaceSample> tableDeleteQuery = dao.queryBuilder()
|
||||
.where(HuaweiWorkoutPaceSampleDao.Properties.WorkoutId.eq(workoutId))
|
||||
.buildDelete();
|
||||
tableDeleteQuery.executeDeleteWithoutDetachingEntities();
|
||||
|
||||
int paceIndex = 0;
|
||||
for (Workout.WorkoutPace.Response.Block block : paceList) {
|
||||
|
||||
Integer correction = block.hasCorrection ? (int) block.correction : null;
|
||||
HuaweiWorkoutPaceSample paceSample = new HuaweiWorkoutPaceSample(
|
||||
workoutId,
|
||||
paceIndex++,
|
||||
block.distance,
|
||||
block.type,
|
||||
block.pace,
|
||||
block.correction
|
||||
block.pointIndex,
|
||||
correction
|
||||
);
|
||||
dao.insertOrReplace(paceSample);
|
||||
}
|
||||
@ -1999,6 +2013,7 @@ public class HuaweiSupportProvider {
|
||||
LOG.error("Failed to update progress notification", e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<GBDeviceApp> gbWatchFaces = null;
|
||||
private List<GBDeviceApp> gbWatchApps = null;
|
||||
|
||||
@ -2011,6 +2026,7 @@ public class HuaweiSupportProvider {
|
||||
this.gbWatchApps = gbWatchApps;
|
||||
updateAppList();
|
||||
}
|
||||
|
||||
private void updateAppList() {
|
||||
ArrayList<GBDeviceApp> gbDeviceApps = new ArrayList<>();
|
||||
if (this.gbWatchFaces != null)
|
||||
|
@ -35,6 +35,7 @@ import de.greenrobot.dao.query.CloseableListIterator;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
@ -661,25 +662,30 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
|
||||
Arrays.asList(
|
||||
new ActivitySummaryValue("#", ActivitySummaryEntries.UNIT_RAW_STRING),
|
||||
new ActivitySummaryValue("distance"),
|
||||
new ActivitySummaryValue("watchface_dialog_widget_type"),
|
||||
new ActivitySummaryValue("Pace"),
|
||||
new ActivitySummaryValue("paceCorrection")
|
||||
new ActivitySummaryValue("Pace")
|
||||
),
|
||||
true,
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
String measurementSystem = GBApplication.getPrefs().getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, "metric");
|
||||
|
||||
byte unitType = (byte) (measurementSystem.equals("metric")?0:1);
|
||||
try (CloseableListIterator<HuaweiWorkoutPaceSample> it = qbPace.build().listIterator()) {
|
||||
HashMap<Byte, Integer> typeCount = new HashMap<>();
|
||||
HashMap<Byte, Integer> typePace = new HashMap<>();
|
||||
|
||||
int currentIndex = 1;
|
||||
while (it.hasNext()) {
|
||||
int index = it.nextIndex();
|
||||
HuaweiWorkoutPaceSample sample = it.next();
|
||||
|
||||
int count = 1;
|
||||
if(sample.getType() != unitType)
|
||||
continue;
|
||||
|
||||
int pace = sample.getPace();
|
||||
int count = 1;
|
||||
|
||||
Integer previousCount = typeCount.get(sample.getType());
|
||||
Integer previousPace = typePace.get(sample.getType());
|
||||
@ -689,19 +695,18 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser {
|
||||
pace += previousPace;
|
||||
typeCount.put(sample.getType(), count);
|
||||
typePace.put(sample.getType(), pace);
|
||||
double distance = sample.getDistance();
|
||||
|
||||
if(sample.getCorrection() != null) {
|
||||
distance += sample.getCorrection() / 10000d;
|
||||
}
|
||||
|
||||
final List<ActivitySummaryValue> columns = new LinkedList<>();
|
||||
columns.add(new ActivitySummaryValue(index, ActivitySummaryEntries.UNIT_NONE));
|
||||
columns.add(new ActivitySummaryValue(sample.getDistance(), ActivitySummaryEntries.UNIT_KILOMETERS));
|
||||
columns.add(new ActivitySummaryValue(sample.getType(), ActivitySummaryEntries.UNIT_NONE)); // TODO: find out types
|
||||
// TODO: add proper units for type == 1. MILES and SECONDS PER MILE
|
||||
columns.add(new ActivitySummaryValue(currentIndex++, ActivitySummaryEntries.UNIT_NONE));
|
||||
columns.add(new ActivitySummaryValue(distance, ActivitySummaryEntries.UNIT_KILOMETERS));
|
||||
columns.add(new ActivitySummaryValue(sample.getPace(), ActivitySummaryEntries.UNIT_SECONDS_PER_KM));
|
||||
|
||||
if (sample.getCorrection() != 0) {
|
||||
columns.add(new ActivitySummaryValue(sample.getCorrection() / 10f, ActivitySummaryEntries.UNIT_METERS));
|
||||
} else {
|
||||
columns.add(new ActivitySummaryValue("stats_empty_value"));
|
||||
}
|
||||
|
||||
pacesTable.put("paces_table_" + index,
|
||||
new ActivitySummaryTableRowEntry(
|
||||
ActivitySummaryEntries.GROUP_PACE,
|
||||
|
Loading…
Reference in New Issue
Block a user