mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-26 09:11:37 +02:00
Xiaomi: Make activity file ID types readable
This commit is contained in:
parent
5316a7dcf8
commit
db57072dd3
@ -116,7 +116,7 @@ public class XiaomiActivityFileFetcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activityParser.parse(fileId, activityData)) {
|
if (activityParser.parse(mHealthService.getSupport(), fileId, activityData)) {
|
||||||
if (!XiaomiPreferences.keepActivityDataOnDevice(mHealthService.getSupport().getDevice())) {
|
if (!XiaomiPreferences.keepActivityDataOnDevice(mHealthService.getSupport().getDevice())) {
|
||||||
LOG.debug("Acking recorded data {}", fileId);
|
LOG.debug("Acking recorded data {}", fileId);
|
||||||
mHealthService.ackRecordedData(fileId);
|
mHealthService.ackRecordedData(fileId);
|
||||||
|
@ -25,12 +25,6 @@ import java.util.Date;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
|
|
||||||
public class XiaomiActivityFileId {
|
public class XiaomiActivityFileId {
|
||||||
public static final int TYPE_ACTIVITY = 0;
|
|
||||||
public static final int TYPE_SPORTS = 1;
|
|
||||||
|
|
||||||
public static final int TYPE_DETAILS = 0;
|
|
||||||
public static final int TYPE_SUMMARY = 1;
|
|
||||||
|
|
||||||
private final Date timestamp;
|
private final Date timestamp;
|
||||||
private final int timezone;
|
private final int timezone;
|
||||||
private final int type;
|
private final int type;
|
||||||
@ -60,16 +54,16 @@ public class XiaomiActivityFileId {
|
|||||||
return timezone;
|
return timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getType() {
|
public Type getType() {
|
||||||
return type;
|
return Type.fromCode(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSubtype() {
|
public Subtype getSubtype() {
|
||||||
return subtype;
|
return Subtype.fromCode(getType(), subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDetailType() {
|
public DetailType getDetailType() {
|
||||||
return detailType;
|
return DetailType.fromCode(detailType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVersion() {
|
public int getVersion() {
|
||||||
@ -113,13 +107,98 @@ public class XiaomiActivityFileId {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
final Type typeName = Type.fromCode(type);
|
||||||
|
final Subtype subtypeName = Subtype.fromCode(typeName, subtype);
|
||||||
|
final DetailType detailTypeName = DetailType.fromCode(detailType);
|
||||||
|
|
||||||
return getClass().getSimpleName() + "{" +
|
return getClass().getSimpleName() + "{" +
|
||||||
"timestamp=" + DateTimeUtils.formatIso8601(timestamp) +
|
"timestamp=" + DateTimeUtils.formatIso8601(timestamp) +
|
||||||
", timezone=" + timezone +
|
", timezone=" + timezone +
|
||||||
", type=" + type +
|
", type=" + (typeName != Type.UNKNOWN ? typeName : "UNKNOWN(" + type + ")") +
|
||||||
", subtype=" + subtype +
|
", subtype=" + (subtypeName != Subtype.UNKNOWN ? subtypeName : "UNKNOWN(" + subtype + ")") +
|
||||||
", detailType=" + detailType +
|
", detailType=" + (detailTypeName != DetailType.UNKNOWN ? detailTypeName : "UNKNOWN(" + detailType + ")") +
|
||||||
", version=" + version +
|
", version=" + version +
|
||||||
"}";
|
"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
UNKNOWN(-1),
|
||||||
|
ACTIVITY(0),
|
||||||
|
SPORTS(1),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
Type(final int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type fromCode(final int code) {
|
||||||
|
for (final Type type : values()) {
|
||||||
|
if (type.getCode() == code) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Subtype {
|
||||||
|
UNKNOWN(Type.UNKNOWN, -1),
|
||||||
|
ACTIVITY_DAILY(Type.ACTIVITY, 0),
|
||||||
|
ACTIVITY_SLEEP(Type.ACTIVITY,8),
|
||||||
|
SPORTS_FREESTYLE(Type.SPORTS, 8),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Type type;
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
Subtype(final Type type, final int code) {
|
||||||
|
this.type = type;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Subtype fromCode(final Type type, final int code) {
|
||||||
|
for (final Subtype subtype : values()) {
|
||||||
|
if (subtype.type == type && subtype.getCode() == code) {
|
||||||
|
return subtype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DetailType {
|
||||||
|
UNKNOWN(-1),
|
||||||
|
DETAILS(0),
|
||||||
|
SUMMARY(1),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
DetailType(final int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DetailType fromCode(final int code) {
|
||||||
|
for (final DetailType detailType : values()) {
|
||||||
|
if (detailType.getCode() == code) {
|
||||||
|
return detailType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,24 +26,14 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport
|
|||||||
public abstract class XiaomiActivityParser {
|
public abstract class XiaomiActivityParser {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(XiaomiActivityParser.class);
|
private static final Logger LOG = LoggerFactory.getLogger(XiaomiActivityParser.class);
|
||||||
|
|
||||||
private final XiaomiSupport mSupport;
|
public abstract boolean parse(final XiaomiSupport support, final XiaomiActivityFileId fileId, final byte[] bytes);
|
||||||
|
|
||||||
public XiaomiActivityParser(final XiaomiSupport support) {
|
|
||||||
this.mSupport = support;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean parse(final XiaomiActivityFileId fileId, final byte[] bytes);
|
|
||||||
|
|
||||||
public XiaomiSupport getSupport() {
|
|
||||||
return mSupport;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static XiaomiActivityParser create(final XiaomiActivityFileId fileId) {
|
public static XiaomiActivityParser create(final XiaomiActivityFileId fileId) {
|
||||||
switch (fileId.getType()) {
|
switch (fileId.getType()) {
|
||||||
case XiaomiActivityFileId.TYPE_ACTIVITY:
|
case ACTIVITY:
|
||||||
return createForActivity(fileId);
|
return createForActivity(fileId);
|
||||||
case XiaomiActivityFileId.TYPE_SPORTS:
|
case SPORTS:
|
||||||
return createForSports(fileId);
|
return createForSports(fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,14 +41,30 @@ public abstract class XiaomiActivityParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XiaomiActivityParser createForActivity(final XiaomiActivityFileId fileId) {
|
private static XiaomiActivityParser createForActivity(final XiaomiActivityFileId fileId) {
|
||||||
assert fileId.getType() == XiaomiActivityFileId.TYPE_ACTIVITY;
|
assert fileId.getType() == XiaomiActivityFileId.Type.ACTIVITY;
|
||||||
|
|
||||||
|
switch (fileId.getSubtype()) {
|
||||||
|
case ACTIVITY_DAILY:
|
||||||
|
switch (fileId.getDetailType()) {
|
||||||
|
case DETAILS:
|
||||||
|
return null;
|
||||||
|
case SUMMARY:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.warn("No parser for activity subtype in {}", fileId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static XiaomiActivityParser createForSports(final XiaomiActivityFileId fileId) {
|
private static XiaomiActivityParser createForSports(final XiaomiActivityFileId fileId) {
|
||||||
assert fileId.getType() == XiaomiActivityFileId.TYPE_SPORTS;
|
assert fileId.getType() == XiaomiActivityFileId.Type.SPORTS;
|
||||||
|
|
||||||
|
LOG.warn("No parser for sports subtype in {}", fileId);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user