diff options
Diffstat (limited to 'main/src/cgeo/geocaching/Trackable.java')
-rw-r--r-- | main/src/cgeo/geocaching/Trackable.java | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/Trackable.java b/main/src/cgeo/geocaching/Trackable.java index 9c2b044..6ec8c0d 100644 --- a/main/src/cgeo/geocaching/Trackable.java +++ b/main/src/cgeo/geocaching/Trackable.java @@ -3,17 +3,21 @@ package cgeo.geocaching; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.trackable.TrackableConnector; import cgeo.geocaching.enumerations.LogType; +import cgeo.geocaching.utils.ImageUtils; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; import android.text.Html; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; +import java.util.LinkedList; import java.util.List; public class Trackable implements ILogable { - static final public int SPOTTED_UNSET = 0; + static final private int SPOTTED_UNSET = 0; static final public int SPOTTED_CACHE = 1; static final public int SPOTTED_USER = 2; static final public int SPOTTED_UNKNOWN = 3; @@ -38,10 +42,19 @@ public class Trackable implements ILogable { private List<LogEntry> logs = new ArrayList<>(); private String trackingcode = null; + /** + * Check whether this trackable has a corresponding URL. + */ + public boolean hasUrl() { + return getConnector().hasTrackableUrls(); + } + + @NonNull public String getUrl() { return getConnector().getUrl(this); } + @NonNull private TrackableConnector getConnector() { return ConnectorFactory.getConnector(this); } @@ -50,7 +63,7 @@ public class Trackable implements ILogable { return guid; } - public void setGuid(String guid) { + public void setGuid(final String guid) { this.guid = guid; } @@ -59,7 +72,7 @@ public class Trackable implements ILogable { return geocode; } - public void setGeocode(String geocode) { + public void setGeocode(final String geocode) { this.geocode = StringUtils.upperCase(geocode); } @@ -67,7 +80,7 @@ public class Trackable implements ILogable { return iconUrl; } - public void setIconUrl(String iconUrl) { + public void setIconUrl(final String iconUrl) { this.iconUrl = iconUrl; } @@ -76,7 +89,7 @@ public class Trackable implements ILogable { return name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } @@ -84,7 +97,7 @@ public class Trackable implements ILogable { return type; } - public void setType(String type) { + public void setType(final String type) { this.type = type; } @@ -92,7 +105,7 @@ public class Trackable implements ILogable { return released; } - public void setReleased(Date released) { + public void setReleased(final Date released) { if (released == null) { this.released = null; } @@ -105,7 +118,7 @@ public class Trackable implements ILogable { return distance; } - public void setDistance(float distance) { + public void setDistance(final float distance) { this.distance = distance; } @@ -113,7 +126,7 @@ public class Trackable implements ILogable { return origin; } - public void setOrigin(String origin) { + public void setOrigin(final String origin) { this.origin = origin; } @@ -121,7 +134,7 @@ public class Trackable implements ILogable { return owner; } - public void setOwner(String owner) { + public void setOwner(final String owner) { this.owner = owner; } @@ -129,7 +142,7 @@ public class Trackable implements ILogable { return ownerGuid; } - public void setOwnerGuid(String ownerGuid) { + public void setOwnerGuid(final String ownerGuid) { this.ownerGuid = ownerGuid; } @@ -137,7 +150,7 @@ public class Trackable implements ILogable { return spottedName; } - public void setSpottedName(String spottedName) { + public void setSpottedName(final String spottedName) { this.spottedName = spottedName; } @@ -145,7 +158,7 @@ public class Trackable implements ILogable { return spottedType; } - public void setSpottedType(int spottedType) { + public void setSpottedType(final int spottedType) { this.spottedType = spottedType; } @@ -153,7 +166,7 @@ public class Trackable implements ILogable { return spottedGuid; } - public void setSpottedGuid(String spottedGuid) { + public void setSpottedGuid(final String spottedGuid) { this.spottedGuid = spottedGuid; } @@ -161,7 +174,7 @@ public class Trackable implements ILogable { return goal; } - public void setGoal(String goal) { + public void setGoal(final String goal) { this.goal = goal; } @@ -169,7 +182,7 @@ public class Trackable implements ILogable { return details; } - public void setDetails(String details) { + public void setDetails(final String details) { this.details = details; } @@ -177,15 +190,16 @@ public class Trackable implements ILogable { return image; } - public void setImage(String image) { + public void setImage(final String image) { this.image = image; } + @NonNull public List<LogEntry> getLogs() { return logs; } - public void setLogs(List<LogEntry> logs) { + public void setLogs(final List<LogEntry> logs) { this.logs = logs != null ? logs : new ArrayList<LogEntry>(); } @@ -210,11 +224,25 @@ public class Trackable implements ILogable { return trackingcode; } - public void setTrackingcode(String trackingcode) { + public void setTrackingcode(final String trackingcode) { this.trackingcode = trackingcode; } - static public List<LogType> getPossibleLogTypes() { + @NonNull + public Collection<Image> getImages() { + final List<Image> images = new LinkedList<>(); + if (StringUtils.isNotBlank(image)) { + images.add(new Image(image, StringUtils.defaultIfBlank(name, geocode))); + } + ImageUtils.addImagesFromHtml(images, geocode, getDetails()); + for (final LogEntry log : getLogs()) { + images.addAll(log.getLogImages()); + } + return images; + } + + @NonNull + static List<LogType> getPossibleLogTypes() { final List<LogType> logTypes = new ArrayList<>(); logTypes.add(LogType.RETRIEVED_IT); logTypes.add(LogType.GRABBED_IT); |