Cleanup: rename category to activityType.

This commit is contained in:
Dennis Guse
2023-06-15 18:45:11 +02:00
parent 75a88ca0e1
commit dbd64a8075
32 changed files with 120 additions and 130 deletions
@@ -20,12 +20,12 @@ public class TrackFilenameGenerator {
public static final String UUID_KEY = "{uuid}";
public static final String TRACKNAME_KEY = "{name}";
public static final String CATEGORY_KEY = "{category}";
public static final String ACTIVITY_TYPE_KEY = "{category}";
public static final String STARTTIME_TIME_KEY = "{time}";
public static final String STARTTIME_DATE_KEY = "{date}";
public static String getAllOptions() {
return Stream.of(UUID_KEY, TRACKNAME_KEY, CATEGORY_KEY, STARTTIME_TIME_KEY, STARTTIME_DATE_KEY)
return Stream.of(UUID_KEY, TRACKNAME_KEY, ACTIVITY_TYPE_KEY, STARTTIME_TIME_KEY, STARTTIME_DATE_KEY)
.collect(Collectors.joining(", "));
}
@@ -44,7 +44,7 @@ public class TrackFilenameGenerator {
values.put(UUID_KEY, track.getUuid().toString().substring(0, 8));
values.put(TRACKNAME_KEY, track.getName());
values.put(CATEGORY_KEY, track.getCategory());
values.put(ACTIVITY_TYPE_KEY, track.getActivityType());
values.put(STARTTIME_TIME_KEY, track.getStartTime().toLocalTime().toString());
values.put(STARTTIME_DATE_KEY, track.getStartTime().toLocalDate().toString());
@@ -268,7 +268,7 @@ public class GPXTrackExporter implements TrackExporter {
printWriter.println("<trk>");
printWriter.println("<name>" + StringUtils.formatCData(track.getName()) + "</name>");
printWriter.println("<desc>" + StringUtils.formatCData(track.getDescription()) + "</desc>");
printWriter.println("<type>" + StringUtils.formatCData(track.getCategory()) + "</type>");
printWriter.println("<type>" + StringUtils.formatCData(track.getActivityType()) + "</type>");
printWriter.println("<extensions>");
printWriter.println("<topografix:color>c0c0c0</topografix:color>");
@@ -59,7 +59,7 @@ public class KMLTrackExporter implements TrackExporter {
private static final String TRACK_STYLE = "track";
private static final String SCHEMA_ID = "schema";
public static final String EXTENDED_DATA_TYPE_CATEGORY = "type";
public static final String EXTENDED_DATA_TYPE_ACTIVITYTYPE = "type";
public static final String EXTENDED_DATA_TYPE_SPEED = "speed";
public static final String EXTENDED_DATA_TYPE_DISTANCE = "distance";
@@ -311,7 +311,7 @@ public class KMLTrackExporter implements TrackExporter {
printWriter.println("<opentracks:trackid>" + track.getUuid() + "</opentracks:trackid>");
printWriter.println("<styleUrl>#" + TRACK_STYLE + "</styleUrl>");
writeCategory(track.getCategory());
writeActivityType(track.getActivityType());
printWriter.println("<MultiTrack>");
printWriter.println("<altitudeMode>absolute</altitudeMode>");
printWriter.println("<interpolate>1</interpolate>");
@@ -426,19 +426,19 @@ public class KMLTrackExporter implements TrackExporter {
/**
* Writes a placemark.
*
* @param name the name
* @param category the category
* @param description the description
* @param location the location
* @param name the name
* @param activityType the activityType
* @param description the description
* @param location the location
*/
private void writePlacemark(String name, String category, String description, Location location, ZoneOffset zoneOffset) {
private void writePlacemark(String name, String activityType, String description, Location location, ZoneOffset zoneOffset) {
if (location != null) {
printWriter.println("<Placemark>");
printWriter.println("<name>" + StringUtils.formatCData(name) + "</name>");
printWriter.println("<description>" + StringUtils.formatCData(description) + "</description>");
printWriter.println("<TimeStamp><when>" + getTime(zoneOffset, location) + "</when></TimeStamp>");
printWriter.println("<styleUrl>#" + KMLTrackExporter.MARKER_STYLE + "</styleUrl>");
writeCategory(category);
writeActivityType(activityType);
printWriter.println("<Point>");
printWriter.println("<coordinates>" + getCoordinates(location, ",") + "</coordinates>");
printWriter.println("</Point>");
@@ -459,7 +459,7 @@ public class KMLTrackExporter implements TrackExporter {
printWriter.println("</Camera>");
printWriter.println("<TimeStamp><when>" + getTime(zoneOffset, marker.getLocation()) + "</when></TimeStamp>");
printWriter.println("<styleUrl>#" + MARKER_STYLE + "</styleUrl>");
writeCategory(marker.getCategory());
writeActivityType(marker.getCategory());
if (exportPhotos) {
printWriter.println("<Icon><href>" + KmzTrackExporter.buildKmzImageFilePath(marker) + "</href></Icon>");
@@ -514,23 +514,15 @@ public class KMLTrackExporter implements TrackExporter {
return result;
}
/**
* Writes the category.
*
* @param category the category
*/
private void writeCategory(String category) {
if (category == null || category.equals("")) {
private void writeActivityType(String actiivtyType) {
if (actiivtyType == null || actiivtyType.equals("")) {
return;
}
printWriter.println("<ExtendedData>");
printWriter.println("<Data name=\"" + EXTENDED_DATA_TYPE_CATEGORY + "\"><value>" + StringUtils.formatCData(category) + "</value></Data>");
printWriter.println("<Data name=\"" + EXTENDED_DATA_TYPE_ACTIVITYTYPE + "\"><value>" + StringUtils.formatCData(actiivtyType) + "</value></Data>");
printWriter.println("</ExtendedData>");
}
/**
* Writes the track style.
*/
private void writeTrackStyle() {
printWriter.println("<Style id=\"" + TRACK_STYLE + "\">");
printWriter.println("<LineStyle><color>7f0000ff</color><width>4</width></LineStyle>");
@@ -98,7 +98,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
private String name;
private String description;
private String category;
private String activityType;
private String latitude;
private String longitude;
private String altitude;
@@ -159,7 +159,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
case TAG_GPX -> onFileEnd();
case TAG_MARKER -> onMarkerEnd();
case TAG_TRACK -> {
trackImporter.setTrack(context, name, uuid, description, category, null, zoneOffset);
trackImporter.setTrack(context, name, uuid, description, activityType, null, zoneOffset);
zoneOffset = null;
}
case TAG_TRACK_SEGMENT -> onTrackSegmentEnd();
@@ -176,7 +176,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
}
case TAG_TYPE -> {
if (content != null) {
category = content.trim();
activityType = content.trim();
}
}
case TAG_TIME -> {
@@ -385,7 +385,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
private void onMarkerStart(Attributes attributes) {
name = null;
description = null;
category = null;
activityType = null;
photoUrl = null;
latitude = attributes.getValue(ATTRIBUTE_LAT);
longitude = attributes.getValue(ATTRIBUTE_LON);
@@ -415,8 +415,8 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac
if (description != null) {
marker.setDescription(description);
}
if (category != null) {
marker.setCategory(category);
if (activityType != null) {
marker.setCategory(activityType);
}
if (photoUrl != null) {
@@ -61,7 +61,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
private static final String TAG_MULTI_TRACK = "MultiTrack";
private static final String TAG_KML22_MULTI_TRACK = "gx:MultiTrack";
private static final String TAG_DATA_CATEGORY = "Data"; //used for Track.category
private static final String TAG_DATA_ACTIVITYTYPE = "Data";
private static final String TAG_SIMPLE_ARRAY_DATA = "SimpleArrayData";
private static final String TAG_KML22_SIMPLE_ARRAY_DATA = "gx:SimpleArrayData";
@@ -113,7 +113,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
private String icon;
private String name;
private String description;
private String category;
private String activityType;
private String latitude;
private String longitude;
private String altitude;
@@ -146,7 +146,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
}
onTrackSegmentStart();
}
case TAG_DATA_CATEGORY, TAG_SIMPLE_ARRAY_DATA, TAG_KML22_SIMPLE_ARRAY_DATA ->
case TAG_DATA_ACTIVITYTYPE, TAG_SIMPLE_ARRAY_DATA, TAG_KML22_SIMPLE_ARRAY_DATA ->
dataType = attributes.getValue(ATTRIBUTE_NAME);
}
}
@@ -165,15 +165,15 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
onMarkerEnd();
case TAG_COORDINATES -> onMarkerLocationEnd();
case TAG_MULTI_TRACK, TAG_KML22_MULTI_TRACK -> {
trackImporter.setTrack(context, name, uuid, description, category, icon, zoneOffset);
trackImporter.setTrack(context, name, uuid, description, activityType, icon, zoneOffset);
zoneOffset = null;
}
case TAG_TRACK, TAG_KML22_TRACK -> onTrackSegmentEnd();
case TAG_COORD, TAG_KML22_COORD -> onCoordEnded();
case TAG_VALUE, TAG_KML22_VALUE -> {
if (KMLTrackExporter.EXTENDED_DATA_TYPE_CATEGORY.equals(dataType)) {
if (KMLTrackExporter.EXTENDED_DATA_TYPE_ACTIVITYTYPE.equals(dataType)) {
if (content != null) {
category = content.trim();
activityType = content.trim();
}
} else {
onExtendedDataValueEnd();
@@ -233,7 +233,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
name = null;
icon = null;
description = null;
category = null;
activityType = null;
photoUrl = null;
latitude = null;
longitude = null;
@@ -260,13 +260,13 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac
Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, location, whenList.get(0))); //TODO Creating marker without need
marker.setName(name != null ? name : "");
marker.setDescription(description != null ? description : "");
marker.setCategory(category != null ? category : "");
marker.setCategory(activityType != null ? activityType : "");
marker.setPhotoUrl(photoUrl);
markers.add(marker);
name = null;
description = null;
category = null;
activityType = null;
photoUrl = null;
whenList.clear();
}
@@ -90,7 +90,7 @@ public class TrackImporter {
this.markers.addAll(markers);
}
void setTrack(Context context, String name, String uuid, String description, String category, String icon, @Nullable ZoneOffset zoneOffset) {
void setTrack(Context context, String name, String uuid, String description, String activityType, String icon, @Nullable ZoneOffset zoneOffset) {
track = new Track(zoneOffset != null ? zoneOffset : ZoneOffset.UTC);
track.setName(name != null ? name : "");
@@ -103,11 +103,11 @@ public class TrackImporter {
track.setDescription(description != null ? description : "");
if (category != null) {
track.setCategory(category);
if (activityType != null) {
track.setActivityType(activityType);
if (icon == null) {
icon = TrackIconUtils.getIconValue(context, category);
icon = TrackIconUtils.getIconValue(context, activityType);
}
}