aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2011-10-08 22:54:33 -0700
committerBananeweizen <Bananeweizen@gmx.de>2011-10-08 22:54:33 -0700
commitfa6ca9f186a68ad098a58545d3b8eafff8285b9a (patch)
tree6c6d24b5474e727bb145550f6af7a85ae6ad072c
parent2acbfbca3d26aa8d09870c5ccab0fc89be32ec13 (diff)
parentff3d220d8667897a0b19123bb1af0b4061ef0104 (diff)
downloadcgeo-fa6ca9f186a68ad098a58545d3b8eafff8285b9a.zip
cgeo-fa6ca9f186a68ad098a58545d3b8eafff8285b9a.tar.gz
cgeo-fa6ca9f186a68ad098a58545d3b8eafff8285b9a.tar.bz2
Merge pull request #640 from blafoo/trackable
Fixed + refactored cgTrackable, added test
-rw-r--r--main/src/cgeo/geocaching/cgBase.java85
-rw-r--r--main/src/cgeo/geocaching/cgData.java36
-rw-r--r--main/src/cgeo/geocaching/cgTrackable.java200
-rw-r--r--main/src/cgeo/geocaching/cgeodetail.java8
-rw-r--r--main/src/cgeo/geocaching/cgeotouch.java6
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java104
-rw-r--r--main/src/cgeo/geocaching/cgeotrackables.java8
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java6
-rw-r--r--tests/src/cgeo/geocaching/cgeoApplicationTest.java23
9 files changed, 327 insertions, 149 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index c122bdb..a8710f4 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -114,8 +114,9 @@ public class cgBase {
private final static Pattern PATTERN_TRACKABLE_SpottedUser = Pattern.compile("<dt>\\W*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\" href=\"[^\"]*/profile/\\?guid=([a-z0-9\\-]+)\">In the hands of ([^<]+).</a>[^<]*</dd>", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN_TRACKABLE_SpottedUnknown = Pattern.compile("<dt>\\W*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">Unknown Location[^<]*</a>[^<]*</dd>", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN_TRACKABLE_SpottedOwner = Pattern.compile("<dt>\\W*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">In the hands of the owner[^<]*</a>[^<]*</dd>", Pattern.CASE_INSENSITIVE);
- private final static Pattern PATTERN_TRACKABLE_Goal = Pattern.compile("<h3>\\W*Current GOAL[^<]*</h3>[^<]*<p[^>]*>(.*)</p>[^<]*<h3>\\W*About This Item[^<]*</h3>", Pattern.CASE_INSENSITIVE);
- private final static Pattern PATTERN_TRACKABLE_DetailsImage = Pattern.compile("<h3>\\W*About This Item[^<]*</h3>([^<]*<p>([^<]*<img id=\"ctl00_ContentBody_BugDetails_BugImage\" class=\"[^\"]+\" src=\"([^\"]+)\"[^>]*>)?[^<]*</p>)?[^<]*<p[^>]*>(.*)</p>[^<]*<div id=\"ctl00_ContentBody_BugDetails_uxAbuseReport\">", Pattern.CASE_INSENSITIVE);
+ private final static Pattern PATTERN_TRACKABLE_GOAL = Pattern.compile("<h3>\\W*Current GOAL[^<]*</h3>[^<]*<div id=\"TrackableGoal\">[^<]*<p>(.*?)</p>[^<]*</div>[^<]*<h3>");
+ private final static Pattern PATTERN_TRACKABLE_DETAILSIMAGE = Pattern.compile("<h3>\\W*About This Item[^<]*</h3>[^<]*<div id=\"TrackableDetails\">([^<]*<p>([^<]*<img id=\"ctl00_ContentBody_BugDetails_BugImage\" class=\"[^\"]+\" src=\"([^\"]+)\"[^>]*>)?[^<]*</p>)?[^<]*<p[^>]*>(.*)</p>[^<]*</div>");
+
private final static Pattern PATTERN_TRACKABLE_Icon = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN_TRACKABLE_Type = Pattern.compile("<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE);
private final static Pattern PATTERN_TRACKABLE_Distance = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE);
@@ -1328,8 +1329,8 @@ public class cgBase {
while (matcherInventoryInside.find()) {
if (matcherInventoryInside.groupCount() > 0) {
final cgTrackable inventoryItem = new cgTrackable();
- inventoryItem.guid = matcherInventoryInside.group(1);
- inventoryItem.name = matcherInventoryInside.group(2);
+ inventoryItem.setGuid(matcherInventoryInside.group(1));
+ inventoryItem.setName(matcherInventoryInside.group(2));
cache.inventory.add(inventoryItem);
cache.inventoryItems++;
@@ -1732,7 +1733,7 @@ public class cgBase {
try {
final Matcher matcherGeocode = PATTERN_TRACKABLE_Geocode.matcher(page);
if (matcherGeocode.find() && matcherGeocode.groupCount() > 0) {
- trackable.geocode = matcherGeocode.group(1).toUpperCase();
+ trackable.setGeocode(matcherGeocode.group(1).toUpperCase());
}
} catch (Exception e) {
// failed to parse trackable geocode
@@ -1743,7 +1744,7 @@ public class cgBase {
try {
final Matcher matcherTrackableId = PATTERN_TRACKABLE_TrackableId.matcher(page);
if (matcherTrackableId.find() && matcherTrackableId.groupCount() > 0) {
- trackable.guid = matcherTrackableId.group(1);
+ trackable.setGuid(matcherTrackableId.group(1));
}
} catch (Exception e) {
// failed to parse trackable id
@@ -1754,7 +1755,7 @@ public class cgBase {
try {
final Matcher matcherTrackableIcon = PATTERN_TRACKABLE_Icon.matcher(page);
if (matcherTrackableIcon.find() && matcherTrackableIcon.groupCount() > 0) {
- trackable.iconUrl = matcherTrackableIcon.group(1);
+ trackable.setIconUrl(matcherTrackableIcon.group(1));
}
} catch (Exception e) {
// failed to parse trackable icon
@@ -1765,7 +1766,7 @@ public class cgBase {
try {
final Matcher matcherName = PATTERN_TRACKABLE_Name.matcher(page);
if (matcherName.find() && matcherName.groupCount() > 1) {
- trackable.name = matcherName.group(2);
+ trackable.setName(matcherName.group(2));
}
} catch (Exception e) {
// failed to parse trackable name
@@ -1773,11 +1774,11 @@ public class cgBase {
}
// trackable type
- if (StringUtils.isNotBlank(trackable.name)) {
+ if (StringUtils.isNotBlank(trackable.getName())) {
try {
final Matcher matcherType = PATTERN_TRACKABLE_Type.matcher(page);
if (matcherType.find() && matcherType.groupCount() > 0) {
- trackable.type = matcherType.group(1);
+ trackable.setType(matcherType.group(1));
}
} catch (Exception e) {
// failed to parse trackable type
@@ -1789,8 +1790,8 @@ public class cgBase {
try {
final Matcher matcherOwner = PATTERN_TRACKABLE_Owner.matcher(page);
if (matcherOwner.find() && matcherOwner.groupCount() > 0) {
- trackable.ownerGuid = matcherOwner.group(1);
- trackable.owner = matcherOwner.group(2);
+ trackable.setOwnerGuid(matcherOwner.group(1));
+ trackable.setOwner(matcherOwner.group(2));
}
} catch (Exception e) {
// failed to parse trackable owner name
@@ -1801,7 +1802,7 @@ public class cgBase {
try {
final Matcher matcherOrigin = PATTERN_TRACKABLE_Origin.matcher(page);
if (matcherOrigin.find() && matcherOrigin.groupCount() > 0) {
- trackable.origin = matcherOrigin.group(1);
+ trackable.setOrigin(matcherOrigin.group(1));
}
} catch (Exception e) {
// failed to parse trackable origin
@@ -1812,26 +1813,26 @@ public class cgBase {
try {
final Matcher matcherSpottedCache = PATTERN_TRACKABLE_SpottedCache.matcher(page);
if (matcherSpottedCache.find() && matcherSpottedCache.groupCount() > 0) {
- trackable.spottedGuid = matcherSpottedCache.group(1);
- trackable.spottedName = matcherSpottedCache.group(2);
- trackable.spottedType = cgTrackable.SPOTTED_CACHE;
+ trackable.setSpottedGuid(matcherSpottedCache.group(1));
+ trackable.setSpottedName(matcherSpottedCache.group(2));
+ trackable.setSpottedType(cgTrackable.SPOTTED_CACHE);
}
final Matcher matcherSpottedUser = PATTERN_TRACKABLE_SpottedUser.matcher(page);
if (matcherSpottedUser.find() && matcherSpottedUser.groupCount() > 0) {
- trackable.spottedGuid = matcherSpottedUser.group(1);
- trackable.spottedName = matcherSpottedUser.group(2);
- trackable.spottedType = cgTrackable.SPOTTED_USER;
+ trackable.setSpottedGuid(matcherSpottedUser.group(1));
+ trackable.setSpottedName(matcherSpottedUser.group(2));
+ trackable.setSpottedType(cgTrackable.SPOTTED_USER);
}
final Matcher matcherSpottedUnknown = PATTERN_TRACKABLE_SpottedUnknown.matcher(page);
if (matcherSpottedUnknown.find()) {
- trackable.spottedType = cgTrackable.SPOTTED_UNKNOWN;
+ trackable.setSpottedType(cgTrackable.SPOTTED_UNKNOWN);
}
final Matcher matcherSpottedOwner = PATTERN_TRACKABLE_SpottedOwner.matcher(page);
if (matcherSpottedOwner.find()) {
- trackable.spottedType = cgTrackable.SPOTTED_OWNER;
+ trackable.setSpottedType(cgTrackable.SPOTTED_OWNER);
}
} catch (Exception e) {
// failed to parse trackable last known place
@@ -1843,16 +1844,16 @@ public class cgBase {
final Matcher matcherReleased = PATTERN_TRACKABLE_Released.matcher(page);
if (matcherReleased.find() && matcherReleased.groupCount() > 0 && matcherReleased.group(1) != null) {
try {
- if (trackable.released == null) {
- trackable.released = dateTbIn1.parse(matcherReleased.group(1));
+ if (trackable.getReleased() == null) {
+ trackable.setReleased(dateTbIn1.parse(matcherReleased.group(1)));
}
} catch (Exception e) {
//
}
try {
- if (trackable.released == null) {
- trackable.released = dateTbIn2.parse(matcherReleased.group(1));
+ if (trackable.getReleased() == null) {
+ trackable.setReleased(dateTbIn2.parse(matcherReleased.group(1)));
}
} catch (Exception e) {
//
@@ -1868,9 +1869,9 @@ public class cgBase {
final Matcher matcherDistance = PATTERN_TRACKABLE_Distance.matcher(page);
if (matcherDistance.find() && matcherDistance.groupCount() > 0) {
try {
- trackable.distance = DistanceParser.parseDistance(matcherDistance.group(1), Settings.isUseMetricUnits());
+ trackable.setDistance(DistanceParser.parseDistance(matcherDistance.group(1), Settings.isUseMetricUnits()));
} catch (NumberFormatException e) {
- trackable.distance = null;
+ trackable.setDistance(null);
throw e;
}
}
@@ -1881,9 +1882,9 @@ public class cgBase {
// trackable goal
try {
- final Matcher matcherGoal = PATTERN_TRACKABLE_Goal.matcher(page);
+ final Matcher matcherGoal = PATTERN_TRACKABLE_GOAL.matcher(page);
if (matcherGoal.find() && matcherGoal.groupCount() > 0) {
- trackable.goal = matcherGoal.group(1);
+ trackable.setGoal(matcherGoal.group(1));
}
} catch (Exception e) {
// failed to parse trackable goal
@@ -1892,16 +1893,16 @@ public class cgBase {
// trackable details & image
try {
- final Matcher matcherDetailsImage = PATTERN_TRACKABLE_DetailsImage.matcher(page);
+ final Matcher matcherDetailsImage = PATTERN_TRACKABLE_DETAILSIMAGE.matcher(page);
if (matcherDetailsImage.find() && matcherDetailsImage.groupCount() > 0) {
final String image = matcherDetailsImage.group(3);
final String details = matcherDetailsImage.group(4);
if (image != null) {
- trackable.image = image;
+ trackable.setImage(image);
}
if (details != null) {
- trackable.details = details;
+ trackable.setDetails(details);
}
}
} catch (Exception e) {
@@ -1950,7 +1951,7 @@ public class cgBase {
logDone.cacheName = matcherLogs.group(5);
}
- trackable.logs.add(logDone);
+ trackable.getLogs().add(logDone);
}
} catch (Exception e) {
// failed to parse logs
@@ -2025,32 +2026,32 @@ public class cgBase {
final Matcher trackableMatcher = trackablePattern.matcher(page);
while (trackableMatcher.find()) {
if (trackableMatcher.groupCount() > 0) {
- final cgTrackableLog trackable = new cgTrackableLog();
+ final cgTrackableLog trackableLog = new cgTrackableLog();
if (trackableMatcher.group(1) != null) {
- trackable.trackCode = trackableMatcher.group(1);
+ trackableLog.trackCode = trackableMatcher.group(1);
} else {
continue;
}
if (trackableMatcher.group(2) != null) {
- trackable.name = Html.fromHtml(trackableMatcher.group(2)).toString();
+ trackableLog.name = Html.fromHtml(trackableMatcher.group(2)).toString();
} else {
continue;
}
if (trackableMatcher.group(3) != null) {
- trackable.ctl = Integer.valueOf(trackableMatcher.group(3));
+ trackableLog.ctl = Integer.valueOf(trackableMatcher.group(3));
} else {
continue;
}
if (trackableMatcher.group(5) != null) {
- trackable.id = Integer.valueOf(trackableMatcher.group(5));
+ trackableLog.id = Integer.valueOf(trackableMatcher.group(5));
} else {
continue;
}
- Log.i(Settings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): " + trackable.trackCode + " - " + trackable.name);
+ Log.i(Settings.tag, "Trackable in inventory (#" + trackableLog.ctl + "/" + trackableLog.id + "): " + trackableLog.trackCode + " - " + trackableLog.name);
- trackables.add(trackable);
+ trackables.add(trackableLog);
}
}
@@ -2828,7 +2829,7 @@ public class cgBase {
public static void postTweetTrackable(cgeoapplication app, String geocode) {
final cgTrackable trackable = app.getTrackableByGeocode(geocode);
- String name = trackable.name;
+ String name = trackable.getName();
if (name.length() > 82) {
name = name.substring(0, 79) + "...";
}
@@ -3585,7 +3586,7 @@ public class cgBase {
/**
* Generate a numeric date and time string according to system-wide settings (locale,
* date format) such as "7 sept. à 12:35".
- *
+ *
* @param context
* a Context
* @param date
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index f27be4c..07a95ab 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -1685,21 +1685,21 @@ public class cgData {
values.put("geocode", geocode);
}
values.put("updated", timeStamp);
- values.put("tbcode", oneTrackable.geocode);
- values.put("guid", oneTrackable.guid);
- values.put("title", oneTrackable.name);
- values.put("owner", oneTrackable.owner);
- if (oneTrackable.released != null) {
- values.put("released", oneTrackable.released.getTime());
+ values.put("tbcode", oneTrackable.getGeocode());
+ values.put("guid", oneTrackable.getGuid());
+ values.put("title", oneTrackable.getName());
+ values.put("owner", oneTrackable.getOwner());
+ if (oneTrackable.getReleased() != null) {
+ values.put("released", oneTrackable.getReleased().getTime());
} else {
values.put("released", 0L);
}
- values.put("goal", oneTrackable.goal);
- values.put("description", oneTrackable.details);
+ values.put("goal", oneTrackable.getGoal());
+ values.put("description", oneTrackable.getDetails());
databaseRW.insert(dbTableTrackables, null, values);
- saveLogs(oneTrackable.geocode, oneTrackable.logs);
+ saveLogs(oneTrackable.getGeocode(), oneTrackable.getLogs());
}
}
databaseRW.setTransactionSuccessful();
@@ -2485,19 +2485,19 @@ public class cgData {
private cgTrackable createTrackableFromDatabaseContent(Cursor cursor) {
cgTrackable trackable = new cgTrackable();
- trackable.geocode = cursor.getString(cursor.getColumnIndex("tbcode"));
- trackable.guid = cursor.getString(cursor.getColumnIndex("guid"));
- trackable.name = cursor.getString(cursor.getColumnIndex("title"));
- trackable.owner = cursor.getString(cursor.getColumnIndex("owner"));
+ trackable.setGeocode(cursor.getString(cursor.getColumnIndex("tbcode")));
+ trackable.setGuid(cursor.getString(cursor.getColumnIndex("guid")));
+ trackable.setName(cursor.getString(cursor.getColumnIndex("title")));
+ trackable.setOwner(cursor.getString(cursor.getColumnIndex("owner")));
String releasedPre = cursor.getString(cursor.getColumnIndex("released"));
if (releasedPre != null && Long.getLong(releasedPre) != null) {
- trackable.released = new Date(Long.getLong(releasedPre));
+ trackable.setReleased(new Date(Long.getLong(releasedPre)));
} else {
- trackable.released = null;
+ trackable.setReleased(null);
}
- trackable.goal = cursor.getString(cursor.getColumnIndex("goal"));
- trackable.details = cursor.getString(cursor.getColumnIndex("description"));
- trackable.logs = loadLogs(trackable.geocode);
+ trackable.setGoal(cursor.getString(cursor.getColumnIndex("goal")));
+ trackable.setDetails(cursor.getString(cursor.getColumnIndex("description")));
+ trackable.setLogs(loadLogs(trackable.getGeocode()));
return trackable;
}
diff --git a/main/src/cgeo/geocaching/cgTrackable.java b/main/src/cgeo/geocaching/cgTrackable.java
index 2a46ed2..29001a8 100644
--- a/main/src/cgeo/geocaching/cgTrackable.java
+++ b/main/src/cgeo/geocaching/cgTrackable.java
@@ -2,8 +2,6 @@ package cgeo.geocaching;
import cgeo.geocaching.enumerations.StatusCode;
-import android.text.Spannable;
-
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -15,29 +13,185 @@ public class cgTrackable {
static final public int SPOTTED_UNKNOWN = 3;
static final public int SPOTTED_OWNER = 4;
- public StatusCode errorRetrieve = null;
- public String error = "";
- public String guid = "";
- public String geocode = "";
- public String iconUrl = "";
- public String name = "";
- public String nameString = null;
- public Spannable nameSp = null;
- public String type = null;
- public Date released = null;
- public Float distance = null;
- public String origin = null;
- public String owner = null;
- public String ownerGuid = null;
- public String spottedName = null;
- public int spottedType = SPOTTED_UNSET;
- public String spottedGuid = null;
- public String goal = null;
- public String details = null;
- public String image = null;
- public List<cgLog> logs = new ArrayList<cgLog>();
+ private StatusCode errorRetrieve = null;
+ private String error = "";
+ private String guid = "";
+ private String geocode = "";
+ private String iconUrl = "";
+ private String name = "";
+ private String type = null;
+ private Date released = null;
+ private Float distance = null;
+ private String origin = null;
+ private String owner = null;
+ private String ownerGuid = null;
+ private String spottedName = null;
+ private int spottedType = SPOTTED_UNSET;
+ private String spottedGuid = null;
+ private String goal = null;
+ private String details = null;
+ private String image = null;
+ private List<cgLog> logs = new ArrayList<cgLog>();
public String getUrl() {
return "http://coord.info/" + geocode.toUpperCase();
}
+
+ public StatusCode getErrorRetrieve() {
+ return errorRetrieve;
+ }
+
+ /*
+ * unused
+ * public void setErrorRetrieve(StatusCode errorRetrieve) {
+ * this.errorRetrieve = errorRetrieve;
+ * }
+ */
+
+ public String getError() {
+ return error;
+ }
+
+ /*
+ * Unused
+ * public void setError(String error) {
+ * this.error = error;
+ * }
+ */
+
+ public String getGuid() {
+ return guid;
+ }
+
+ public void setGuid(String guid) {
+ this.guid = guid;
+ }
+
+ public String getGeocode() {
+ return geocode;
+ }
+
+ public void setGeocode(String geocode) {
+ this.geocode = geocode;
+ }
+
+ public String getIconUrl() {
+ return iconUrl;
+ }
+
+ public void setIconUrl(String iconUrl) {
+ this.iconUrl = iconUrl;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Date getReleased() {
+ return released;
+ }
+
+ public void setReleased(Date released) {
+ this.released = released;
+ }
+
+ public Float getDistance() {
+ return distance;
+ }
+
+ public void setDistance(Float distance) {
+ this.distance = distance;
+ }
+
+ public String getOrigin() {
+ return origin;
+ }
+
+ public void setOrigin(String origin) {
+ this.origin = origin;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public String getOwnerGuid() {
+ return ownerGuid;
+ }
+
+ public void setOwnerGuid(String ownerGuid) {
+ this.ownerGuid = ownerGuid;
+ }
+
+ public String getSpottedName() {
+ return spottedName;
+ }
+
+ public void setSpottedName(String spottedName) {
+ this.spottedName = spottedName;
+ }
+
+ public int getSpottedType() {
+ return spottedType;
+ }
+
+ public void setSpottedType(int spottedType) {
+ this.spottedType = spottedType;
+ }
+
+ public String getSpottedGuid() {
+ return spottedGuid;
+ }
+
+ public void setSpottedGuid(String spottedGuid) {
+ this.spottedGuid = spottedGuid;
+ }
+
+ public String getGoal() {
+ return goal;
+ }
+
+ public void setGoal(String goal) {
+ this.goal = goal;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+
+ public void setDetails(String details) {
+ this.details = details;
+ }
+
+ public String getImage() {
+ return image;
+ }
+
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+ public List<cgLog> getLogs() {
+ return logs;
+ }
+
+ public void setLogs(List<cgLog> logs) {
+ this.logs = logs;
+ }
}
diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java
index c26b885..c871fb7 100644
--- a/main/src/cgeo/geocaching/cgeodetail.java
+++ b/main/src/cgeo/geocaching/cgeodetail.java
@@ -906,11 +906,11 @@ public class cgeodetail extends AbstractActivity {
inventoryString.append('\n');
}
// avoid HTML parsing where possible
- if (containsHtml(inventoryItem.name)) {
- inventoryString.append(Html.fromHtml(inventoryItem.name).toString());
+ if (containsHtml(inventoryItem.getName())) {
+ inventoryString.append(Html.fromHtml(inventoryItem.getName()).toString());
}
else {
- inventoryString.append(inventoryItem.name);
+ inventoryString.append(inventoryItem.getName());
}
}
inventView.setText(inventoryString);
@@ -1671,7 +1671,7 @@ public class cgeodetail extends AbstractActivity {
// jump directly into details if there is only one trackable
if (cache != null && cache.inventory != null && cache.inventory.size() == 1) {
cgTrackable trackable = cache.inventory.get(0);
- cgeotrackable.startActivity(cgeodetail.this, trackable.guid, trackable.geocode, trackable.name);
+ cgeotrackable.startActivity(cgeodetail.this, trackable.getGuid(), trackable.getGeocode(), trackable.getName());
}
else {
Intent trackablesIntent = new Intent(cgeodetail.this, cgeotrackables.class);
diff --git a/main/src/cgeo/geocaching/cgeotouch.java b/main/src/cgeo/geocaching/cgeotouch.java
index fc9b255..7cd566d 100644
--- a/main/src/cgeo/geocaching/cgeotouch.java
+++ b/main/src/cgeo/geocaching/cgeotouch.java
@@ -113,10 +113,10 @@ public class cgeotouch extends cgLogForm {
trackable = app.getTrackableByGeocode("logging trackable");
- if (StringUtils.isNotBlank(trackable.name)) {
- setTitle(res.getString(R.string.trackable_touch) + trackable.name);
+ if (StringUtils.isNotBlank(trackable.getName())) {
+ setTitle(res.getString(R.string.trackable_touch) + trackable.getName());
} else {
- setTitle(res.getString(R.string.trackable_touch) + trackable.geocode.toUpperCase());
+ setTitle(res.getString(R.string.trackable_touch) + trackable.getGeocode().toUpperCase());
}
app.setAction("logging trackable");
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index aea5855..921dbcb 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -45,15 +45,15 @@ public class cgeotrackable extends AbstractActivity {
TextView itemName;
TextView itemValue;
- if (trackable != null && trackable.errorRetrieve != null) {
- showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.errorRetrieve.getErrorString(res) + ".");
+ if (trackable != null && trackable.getErrorRetrieve() != null) {
+ showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.getErrorRetrieve().getErrorString(res) + ".");
finish();
return;
}
- if (trackable != null && StringUtils.isNotBlank(trackable.error)) {
- showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.error + ".");
+ if (trackable != null && StringUtils.isNotBlank(trackable.getError())) {
+ showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.getError() + ".");
finish();
return;
@@ -76,21 +76,21 @@ public class cgeotrackable extends AbstractActivity {
try {
inflater = getLayoutInflater();
- geocode = trackable.geocode.toUpperCase();
+ geocode = trackable.getGeocode().toUpperCase();
- if (StringUtils.isNotBlank(trackable.name)) {
- setTitle(Html.fromHtml(trackable.name).toString());
+ if (StringUtils.isNotBlank(trackable.getName())) {
+ setTitle(Html.fromHtml(trackable.getName()).toString());
} else {
- setTitle(trackable.name.toUpperCase());
+ setTitle(trackable.getName().toUpperCase());
}
((ScrollView) findViewById(R.id.details_list_box)).setVisibility(View.VISIBLE);
LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
// actiobar icon
- if (StringUtils.isNotBlank(trackable.iconUrl)) {
+ if (StringUtils.isNotBlank(trackable.getIconUrl())) {
final tbIconHandler iconHandler = new tbIconHandler(((TextView) findViewById(R.id.actionbar_title)));
- final tbIconThread iconThread = new tbIconThread(trackable.iconUrl, iconHandler);
+ final tbIconThread iconThread = new tbIconThread(trackable.getIconUrl(), iconHandler);
iconThread.start();
}
@@ -100,8 +100,8 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_name));
- if (StringUtils.isNotBlank(trackable.name)) {
- itemValue.setText(Html.fromHtml(trackable.name).toString());
+ if (StringUtils.isNotBlank(trackable.getName())) {
+ itemValue.setText(Html.fromHtml(trackable.getName()).toString());
} else {
itemValue.setText(res.getString(R.string.trackable_unknown));
}
@@ -113,8 +113,8 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
String tbType = null;
- if (StringUtils.isNotBlank(trackable.type)) {
- tbType = Html.fromHtml(trackable.type).toString();
+ if (StringUtils.isNotBlank(trackable.getType())) {
+ tbType = Html.fromHtml(trackable.getType()).toString();
} else {
tbType = res.getString(R.string.trackable_unknown);
}
@@ -128,7 +128,7 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_code));
- itemValue.setText(trackable.geocode.toUpperCase());
+ itemValue.setText(trackable.getGeocode().toUpperCase());
detailsList.addView(itemLayout);
// trackable owner
@@ -137,8 +137,8 @@ public class cgeotrackable extends AbstractActivity {
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_owner));
- if (StringUtils.isNotBlank(trackable.owner)) {
- itemValue.setText(Html.fromHtml(trackable.owner), TextView.BufferType.SPANNABLE);
+ if (StringUtils.isNotBlank(trackable.getOwner())) {
+ itemValue.setText(Html.fromHtml(trackable.getOwner()), TextView.BufferType.SPANNABLE);
itemLayout.setOnClickListener(new userActions());
} else {
itemValue.setText(res.getString(R.string.trackable_unknown));
@@ -146,9 +146,9 @@ public class cgeotrackable extends AbstractActivity {
detailsList.addView(itemLayout);
// trackable spotted
- if (StringUtils.isNotBlank(trackable.spottedName) ||
- trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN ||
- trackable.spottedType == cgTrackable.SPOTTED_OWNER
+ if (StringUtils.isNotBlank(trackable.getSpottedName()) ||
+ trackable.getSpottedType() == cgTrackable.SPOTTED_UNKNOWN ||
+ trackable.getSpottedType() == cgTrackable.SPOTTED_OWNER
) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
@@ -157,13 +157,13 @@ public class cgeotrackable extends AbstractActivity {
itemName.setText(res.getString(R.string.trackable_spotted));
String text = null;
- if (trackable.spottedType == cgTrackable.SPOTTED_CACHE) {
- text = res.getString(R.string.trackable_spotted_in_cache) + " " + Html.fromHtml(trackable.spottedName).toString();
- } else if (trackable.spottedType == cgTrackable.SPOTTED_USER) {
- text = res.getString(R.string.trackable_spotted_at_user) + " " + Html.fromHtml(trackable.spottedName).toString();
- } else if (trackable.spottedType == cgTrackable.SPOTTED_UNKNOWN) {
+ if (trackable.getSpottedType() == cgTrackable.SPOTTED_CACHE) {
+ text = res.getString(R.string.trackable_spotted_in_cache) + " " + Html.fromHtml(trackable.getSpottedName()).toString();
+ } else if (trackable.getSpottedType() == cgTrackable.SPOTTED_USER) {
+ text = res.getString(R.string.trackable_spotted_at_user) + " " + Html.fromHtml(trackable.getSpottedName()).toString();
+ } else if (trackable.getSpottedType() == cgTrackable.SPOTTED_UNKNOWN) {
text = res.getString(R.string.trackable_spotted_unknown_location);
- } else if (trackable.spottedType == cgTrackable.SPOTTED_OWNER) {
+ } else if (trackable.getSpottedType() == cgTrackable.SPOTTED_OWNER) {
text = res.getString(R.string.trackable_spotted_owner);
} else {
text = "N/A";
@@ -171,16 +171,16 @@ public class cgeotrackable extends AbstractActivity {
itemValue.setText(text);
itemLayout.setClickable(true);
- if (cgTrackable.SPOTTED_CACHE == trackable.spottedType) {
+ if (cgTrackable.SPOTTED_CACHE == trackable.getSpottedType()) {
itemLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent cacheIntent = new Intent(cgeotrackable.this, cgeodetail.class);
- cacheIntent.putExtra("guid", trackable.spottedGuid);
- cacheIntent.putExtra("name", trackable.spottedName);
+ cacheIntent.putExtra("guid", trackable.getSpottedGuid());
+ cacheIntent.putExtra("name", trackable.getSpottedName());
startActivity(cacheIntent);
}
});
- } else if (cgTrackable.SPOTTED_USER == trackable.spottedType) {
+ } else if (cgTrackable.SPOTTED_USER == trackable.getSpottedType()) {
itemLayout.setOnClickListener(new userActions());
//activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?guid=" + trackable.spottedGuid)));
}
@@ -189,58 +189,58 @@ public class cgeotrackable extends AbstractActivity {
}
// trackable origin
- if (StringUtils.isNotBlank(trackable.origin)) {
+ if (StringUtils.isNotBlank(trackable.getOrigin())) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_origin));
- itemValue.setText(Html.fromHtml(trackable.origin), TextView.BufferType.SPANNABLE);
+ itemValue.setText(Html.fromHtml(trackable.getOrigin()), TextView.BufferType.SPANNABLE);
detailsList.addView(itemLayout);
}
// trackable released
- if (trackable.released != null) {
+ if (trackable.getReleased() != null) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_released));
- itemValue.setText(base.formatDate(trackable.released.getTime()));
+ itemValue.setText(base.formatDate(trackable.getReleased().getTime()));
detailsList.addView(itemLayout);
}
// trackable distance
- if (trackable.distance != null) {
+ if (trackable.getDistance() != null) {
itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
itemName = (TextView) itemLayout.findViewById(R.id.name);
itemValue = (TextView) itemLayout.findViewById(R.id.value);
itemName.setText(res.getString(R.string.trackable_distance));
- itemValue.setText(cgBase.getHumanDistance(trackable.distance));
+ itemValue.setText(cgBase.getHumanDistance(trackable.getDistance()));
detailsList.addView(itemLayout);
}
// trackable goal
- if (StringUtils.isNotBlank(trackable.goal)) {
+ if (StringUtils.isNotBlank(trackable.getGoal())) {
((LinearLayout) findViewById(R.id.goal_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.goal);
descView.setVisibility(View.VISIBLE);
- descView.setText(Html.fromHtml(trackable.goal, new cgHtmlImg(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
+ descView.setText(Html.fromHtml(trackable.getGoal(), new cgHtmlImg(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
descView.setMovementMethod(LinkMovementMethod.getInstance());
}
// trackable details
- if (StringUtils.isNotBlank(trackable.details)) {
+ if (StringUtils.isNotBlank(trackable.getDetails())) {
((LinearLayout) findViewById(R.id.details_box)).setVisibility(View.VISIBLE);
TextView descView = (TextView) findViewById(R.id.details);
descView.setVisibility(View.VISIBLE);
- descView.setText(Html.fromHtml(trackable.details, new cgHtmlImg(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
+ descView.setText(Html.fromHtml(trackable.getDetails(), new cgHtmlImg(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE);
descView.setMovementMethod(LinkMovementMethod.getInstance());
}
// trackable image
- if (StringUtils.isNotBlank(trackable.image)) {
+ if (StringUtils.isNotBlank(trackable.getImage())) {
((LinearLayout) findViewById(R.id.image_box)).setVisibility(View.VISIBLE);
LinearLayout imgView = (LinearLayout) findViewById(R.id.image);
@@ -251,7 +251,7 @@ public class cgeotrackable extends AbstractActivity {
trackableImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(trackable.image)));
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(trackable.getImage())));
}
});
@@ -275,7 +275,7 @@ public class cgeotrackable extends AbstractActivity {
try {
cgHtmlImg imgGetter = new cgHtmlImg(cgeotrackable.this, geocode, true, 0, false);
- image = imgGetter.getDrawable(trackable.image);
+ image = imgGetter.getDrawable(trackable.getImage());
Message message = handler.obtainMessage(0, image);
handler.sendMessage(message);
} catch (Exception e) {
@@ -401,9 +401,9 @@ public class cgeotrackable extends AbstractActivity {
String selectedName = itemName.getText().toString();
if (selectedName.equals(res.getString(R.string.trackable_owner))) {
- contextMenuUser = trackable.owner;
+ contextMenuUser = trackable.getOwner();
} else if (selectedName.equals(res.getString(R.string.trackable_spotted))) {
- contextMenuUser = trackable.spottedName;
+ contextMenuUser = trackable.getSpottedName();
}
}
@@ -446,7 +446,7 @@ public class cgeotrackable extends AbstractActivity {
logTouch();
return true;
case 2:
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/track/details.aspx?tracker=" + trackable.geocode)));
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/track/details.aspx?tracker=" + trackable.getGeocode())));
return true;
}
@@ -489,8 +489,8 @@ public class cgeotrackable extends AbstractActivity {
RelativeLayout rowView;
- if (trackable != null && trackable.logs != null) {
- for (cgLog log : trackable.logs) {
+ if (trackable != null && trackable.getLogs() != null) {
+ for (cgLog log : trackable.getLogs()) {
rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logitem, null);
if (log.date > 0) {
@@ -526,7 +526,7 @@ public class cgeotrackable extends AbstractActivity {
listView.addView(rowView);
}
- if (trackable.logs.size() > 0) {
+ if (trackable.getLogs().size() > 0) {
((LinearLayout) findViewById(R.id.log_box)).setVisibility(View.VISIBLE);
}
}
@@ -550,8 +550,8 @@ public class cgeotrackable extends AbstractActivity {
private void logTouch() {
Intent logTouchIntent = new Intent(this, cgeotouch.class);
- logTouchIntent.putExtra("geocode", trackable.geocode.toUpperCase());
- logTouchIntent.putExtra("guid", trackable.guid);
+ logTouchIntent.putExtra("geocode", trackable.getGeocode().toUpperCase());
+ logTouchIntent.putExtra("guid", trackable.getGuid());
startActivity(logTouchIntent);
}
@@ -572,7 +572,7 @@ public class cgeotrackable extends AbstractActivity {
BitmapDrawable image = null;
try {
- cgHtmlImg imgGetter = new cgHtmlImg(cgeotrackable.this, trackable.geocode, false, 0, false);
+ cgHtmlImg imgGetter = new cgHtmlImg(cgeotrackable.this, trackable.getGeocode(), false, 0, false);
image = imgGetter.getDrawable(url);
Message message = handler.obtainMessage(0, image);
diff --git a/main/src/cgeo/geocaching/cgeotrackables.java b/main/src/cgeo/geocaching/cgeotrackables.java
index c27ce11..d3e0ceb 100644
--- a/main/src/cgeo/geocaching/cgeotrackables.java
+++ b/main/src/cgeo/geocaching/cgeotrackables.java
@@ -46,7 +46,7 @@ public class cgeotrackables extends AbstractActivity {
return;
} else if (trackables.size() == 1) {
cgTrackable trackable = trackables.get(0);
- cgeotrackable.startActivity(cgeotrackables.this, trackable.guid, trackable.geocode, trackable.name);
+ cgeotrackable.startActivity(cgeotrackables.this, trackable.getGuid(), trackable.getGeocode(), trackable.getName());
finish();
return;
} else {
@@ -56,13 +56,13 @@ public class cgeotrackables extends AbstractActivity {
Button oneTb = (Button) oneTbPre.findViewById(R.id.button);
- if (trackable.name != null) {
- oneTb.setText(Html.fromHtml(trackable.name).toString());
+ if (trackable.getName() != null) {
+ oneTb.setText(Html.fromHtml(trackable.getName()).toString());
} else {
oneTb.setText("some trackable");
}
oneTb.setClickable(true);
- oneTb.setOnClickListener(new buttonListener(trackable.guid, trackable.geocode, trackable.name));
+ oneTb.setOnClickListener(new buttonListener(trackable.getGuid(), trackable.getGeocode(), trackable.getName()));
addList.addView(oneTbPre);
}
}
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index eb1afe0..eb4ee13 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -617,7 +617,7 @@ public abstract class GPXParser extends FileParser {
try {
if (attrs.getIndex("ref") > -1) {
- trackable.geocode = attrs.getValue("ref").toUpperCase();
+ trackable.setGeocode(attrs.getValue("ref").toUpperCase());
}
} catch (Exception e) {
// nothing
@@ -632,7 +632,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end() {
- if (StringUtils.isNotBlank(trackable.geocode) && StringUtils.isNotBlank(trackable.name)) {
+ if (StringUtils.isNotBlank(trackable.getGeocode()) && StringUtils.isNotBlank(trackable.getName())) {
if (cache.inventory == null) {
cache.inventory = new ArrayList<cgTrackable>();
}
@@ -646,7 +646,7 @@ public abstract class GPXParser extends FileParser {
@Override
public void end(String tbName) {
- trackable.name = validate(tbName);
+ trackable.setName(validate(tbName));
}
});
diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
index ff84b5b..96d1f5f 100644
--- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
@@ -9,6 +9,7 @@ import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@@ -102,4 +103,26 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
cgCache cache = caches.cacheList.get(0);
Assert.assertEquals("California, United States", cache.getLocation());
}
+
+ public void testSearchTrackable() {
+ cgTrackable tb = base.searchTrackable("TB2J1VZ", null, null);
+ Assert.assertEquals("aefffb86-099f-444f-b132-605436163aa8", tb.getGuid());
+ Assert.assertEquals("TB2J1VZ", tb.getGeocode());
+ Assert.assertEquals("http://www.geocaching.com/images/wpttypes/21.gif", tb.getIconUrl());
+ Assert.assertEquals("blafoo's Children Music CD", tb.getName());
+ Assert.assertEquals("Travel Bug Dog Tag", tb.getType());
+ Assert.assertEquals(new Date(2009 - 1900, 8 - 1, 24), tb.getReleased());
+ Assert.assertEquals(10617.8f, tb.getDistance());
+ Assert.assertEquals("Niedersachsen, Germany", tb.getOrigin());
+ Assert.assertEquals("blafoo", tb.getOwner());
+ Assert.assertEquals("0564a940-8311-40ee-8e76-7e91b2cf6284", tb.getOwnerGuid());
+ Assert.assertEquals("Nice place for a break cache", tb.getSpottedName());
+ Assert.assertEquals(cgTrackable.SPOTTED_CACHE, tb.getSpottedType());
+ Assert.assertEquals("faa2d47d-19ea-422f-bec8-318fc82c8063", tb.getSpottedGuid());
+ Assert.assertEquals(" Kinder erfreuen.<br/><br/>Make children happy. ", tb.getGoal());
+ Assert.assertTrue(tb.getDetails().startsWith(" Auf der CD sind"));
+ Assert.assertEquals("http://img.geocaching.com/track/display/38382780-87a7-4393-8393-78841678ee8c.jpg", tb.getImage());
+ Assert.assertEquals(10, tb.getLogs().size());
+ }
+
}