mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: Fix crash when parsing some activities
This commit is contained in:
+9
-5
@@ -13,11 +13,15 @@ public class FieldDefinitionAlarm extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, Math.round(raw / 60));
|
||||
calendar.set(Calendar.MINUTE, raw % 60);
|
||||
return calendar;
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(Calendar.HOUR_OF_DAY, raw / 60);
|
||||
calendar.set(Calendar.MINUTE, raw % 60);
|
||||
return calendar;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -16,8 +16,12 @@ public class FieldDefinitionDayOfWeek extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return DayOfWeek.of(raw == 0 ? 7 : raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return DayOfWeek.of(raw == 0 ? 7 : raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-3
@@ -14,9 +14,13 @@ public class FieldDefinitionFileType extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
final FileType.FILETYPE fileType = FileType.FILETYPE.fromDataTypeSubType(128, raw);
|
||||
return fileType == null ? raw : fileType;
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
final FileType.FILETYPE fileType = FileType.FILETYPE.fromDataTypeSubType(128, raw);
|
||||
return fileType == null ? raw : fileType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -15,8 +15,12 @@ public class FieldDefinitionGoalSource extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return Source.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return Source.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -15,8 +15,12 @@ public class FieldDefinitionGoalType extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return Type.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return Type.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -14,8 +14,12 @@ public class FieldDefinitionHrvStatus extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(final ByteBuffer byteBuffer) {
|
||||
final int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return HrvStatus.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return HrvStatus.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -15,8 +15,12 @@ public class FieldDefinitionLanguage extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return Language.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return Language.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -14,8 +14,12 @@ public class FieldDefinitionMeasurementSystem extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return Type.fromId(raw) == null ? raw : Type.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return Type.fromId(raw) == null ? raw : Type.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -14,8 +14,12 @@ public class FieldDefinitionSleepStage extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(final ByteBuffer byteBuffer) {
|
||||
final int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return SleepStage.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return SleepStage.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -17,8 +17,12 @@ public class FieldDefinitionSwimStyle extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int raw = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return SwimStyle.fromId(raw);
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return SwimStyle.fromId(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -13,8 +13,12 @@ public class FieldDefinitionWeatherAqi extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int idx = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return AQI_LEVELS.values()[idx];
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return AQI_LEVELS.values()[raw];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -13,8 +13,12 @@ public class FieldDefinitionWeatherCondition extends FieldDefinition {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuffer byteBuffer) {
|
||||
int idx = (int) baseType.decode(byteBuffer, scale, offset);
|
||||
return Condition.values()[idx];
|
||||
final Object rawObj = baseType.decode(byteBuffer, scale, offset);
|
||||
if (rawObj != null) {
|
||||
final int raw = (int) rawObj;
|
||||
return Condition.values()[raw];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user