mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01: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;
|
||||
}
|
||||
|
||||
if (activityParser.parse(fileId, activityData)) {
|
||||
if (activityParser.parse(mHealthService.getSupport(), fileId, activityData)) {
|
||||
if (!XiaomiPreferences.keepActivityDataOnDevice(mHealthService.getSupport().getDevice())) {
|
||||
LOG.debug("Acking recorded data {}", fileId);
|
||||
mHealthService.ackRecordedData(fileId);
|
||||
|
@ -25,12 +25,6 @@ import java.util.Date;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
|
||||
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 int timezone;
|
||||
private final int type;
|
||||
@ -60,16 +54,16 @@ public class XiaomiActivityFileId {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
public Type getType() {
|
||||
return Type.fromCode(type);
|
||||
}
|
||||
|
||||
public int getSubtype() {
|
||||
return subtype;
|
||||
public Subtype getSubtype() {
|
||||
return Subtype.fromCode(getType(), subtype);
|
||||
}
|
||||
|
||||
public int getDetailType() {
|
||||
return detailType;
|
||||
public DetailType getDetailType() {
|
||||
return DetailType.fromCode(detailType);
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
@ -113,13 +107,98 @@ public class XiaomiActivityFileId {
|
||||
@NonNull
|
||||
@Override
|
||||
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() + "{" +
|
||||
"timestamp=" + DateTimeUtils.formatIso8601(timestamp) +
|
||||
", timezone=" + timezone +
|
||||
", type=" + type +
|
||||
", subtype=" + subtype +
|
||||
", detailType=" + detailType +
|
||||
", type=" + (typeName != Type.UNKNOWN ? typeName : "UNKNOWN(" + type + ")") +
|
||||
", subtype=" + (subtypeName != Subtype.UNKNOWN ? subtypeName : "UNKNOWN(" + subtype + ")") +
|
||||
", detailType=" + (detailTypeName != DetailType.UNKNOWN ? detailTypeName : "UNKNOWN(" + detailType + ")") +
|
||||
", 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 {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(XiaomiActivityParser.class);
|
||||
|
||||
private final XiaomiSupport mSupport;
|
||||
|
||||
public XiaomiActivityParser(final XiaomiSupport support) {
|
||||
this.mSupport = support;
|
||||
}
|
||||
|
||||
public abstract boolean parse(final XiaomiActivityFileId fileId, final byte[] bytes);
|
||||
|
||||
public XiaomiSupport getSupport() {
|
||||
return mSupport;
|
||||
}
|
||||
public abstract boolean parse(final XiaomiSupport support, final XiaomiActivityFileId fileId, final byte[] bytes);
|
||||
|
||||
@Nullable
|
||||
public static XiaomiActivityParser create(final XiaomiActivityFileId fileId) {
|
||||
switch (fileId.getType()) {
|
||||
case XiaomiActivityFileId.TYPE_ACTIVITY:
|
||||
case ACTIVITY:
|
||||
return createForActivity(fileId);
|
||||
case XiaomiActivityFileId.TYPE_SPORTS:
|
||||
case SPORTS:
|
||||
return createForSports(fileId);
|
||||
}
|
||||
|
||||
@ -51,14 +41,30 @@ public abstract class XiaomiActivityParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static XiaomiActivityParser createForActivity(final XiaomiActivityFileId fileId) {
|
||||
assert fileId.getType() == XiaomiActivityFileId.TYPE_ACTIVITY;
|
||||
private static XiaomiActivityParser createForActivity(final XiaomiActivityFileId fileId) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static XiaomiActivityParser createForSports(final XiaomiActivityFileId fileId) {
|
||||
assert fileId.getType() == XiaomiActivityFileId.TYPE_SPORTS;
|
||||
private static XiaomiActivityParser createForSports(final XiaomiActivityFileId fileId) {
|
||||
assert fileId.getType() == XiaomiActivityFileId.Type.SPORTS;
|
||||
|
||||
LOG.warn("No parser for sports subtype in {}", fileId);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user