diff options
| -rw-r--r-- | src/cgeo/geocaching/cgCache.java | 8 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgGPXParser.java | 58 |
2 files changed, 37 insertions, 29 deletions
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index fe087e1..5abc057 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -272,7 +272,7 @@ public class cgCache { } public boolean isEventCache() { - return (type.equalsIgnoreCase("event") || type.equalsIgnoreCase("mega") || type.equalsIgnoreCase("cito")); + return ("event".equalsIgnoreCase(type) || "mega".equalsIgnoreCase(type) || "cito".equalsIgnoreCase(type)); } public boolean logVisit(IAbstractActivity fromActivity) { @@ -312,9 +312,9 @@ public class cgCache { } public ArrayList<Integer> getPossibleLogTypes(cgSettings settings) { - boolean isOwner = owner.equalsIgnoreCase(settings.getUsername()); + boolean isOwner = owner != null && owner.equalsIgnoreCase(settings.getUsername()); ArrayList<Integer> types = new ArrayList<Integer>(); - if (type.equals("event") || type.equals("mega") || type.equals("cito") || type.equals("lostfound")) { + if ("event".equals(type) || "mega".equals(type) || "cito".equals(type) || "lostfound".equals(type)) { types.add(cgBase.LOG_WILL_ATTEND); types.add(cgBase.LOG_NOTE); types.add(cgBase.LOG_ATTENDED); @@ -322,7 +322,7 @@ public class cgCache { if (isOwner) { types.add(cgBase.LOG_ANNOUNCEMENT); } - } else if (type.equals("webcam")) { + } else if ("webcam".equals(type)) { types.add(cgBase.LOG_WEBCAM_PHOTO_TAKEN); types.add(cgBase.LOG_DIDNT_FIND_IT); types.add(cgBase.LOG_NOTE); diff --git a/src/cgeo/geocaching/cgGPXParser.java b/src/cgeo/geocaching/cgGPXParser.java index c8c013f..2e9b671 100644 --- a/src/cgeo/geocaching/cgGPXParser.java +++ b/src/cgeo/geocaching/cgGPXParser.java @@ -254,20 +254,10 @@ public class cgGPXParser { cache.cacheid = attrs.getValue("id"); } if (attrs.getIndex("archived") > -1) { - final String at = attrs.getValue("archived").toLowerCase(); - if (at.equals("true")) { - cache.archived = true; - } else { - cache.archived = false; - } + cache.archived = attrs.getValue("archived").equalsIgnoreCase("true"); } if (attrs.getIndex("available") > -1) { - final String at = attrs.getValue("available").toLowerCase(); - if (at.equals("true")) { - cache.disabled = false; - } else { - cache.disabled = true; - } + cache.disabled = !attrs.getValue("available").equalsIgnoreCase("true"); } } catch (Exception e) { Log.w(cgSettings.tag, "Failed to parse cache attributes."); @@ -280,7 +270,7 @@ public class cgGPXParser { public void end(String body) { final String content = Html.fromHtml(body).toString().trim(); - cache.name = content; + cache.name = validate(content); } }); @@ -289,7 +279,7 @@ public class cgGPXParser { public void end(String body) { final String content = Html.fromHtml(body).toString().trim(); - cache.owner = content; + cache.owner = validate(content); } }); @@ -297,8 +287,8 @@ public class cgGPXParser { gcCache.getChild(nsGC, "type").setEndTextElementListener(new EndTextElementListener() { public void end(String body) { - final String content = cgBase.cacheTypes.get(body.toLowerCase()); - cache.type = content; + String parsedString = validate(body.toLowerCase()); + setType(parsedString); } }); @@ -307,7 +297,7 @@ public class cgGPXParser { public void end(String body) { final String content = body.toLowerCase(); - cache.size = content; + cache.size = validate(content); } }); @@ -340,7 +330,7 @@ public class cgGPXParser { public void end(String body) { if (cache.location == null || cache.location.length() == 0) { - cache.location = body.trim(); + cache.location = validate(body.trim()); } else { cache.location = cache.location + ", " + body.trim(); } @@ -352,7 +342,7 @@ public class cgGPXParser { public void end(String body) { if (cache.location == null || cache.location.length() == 0) { - cache.location = body.trim(); + cache.location = validate(body.trim()); } else { cache.location = body.trim() + ", " + cache.location; } @@ -363,7 +353,7 @@ public class cgGPXParser { gcCache.getChild(nsGC, "encoded_hints").setEndTextElementListener(new EndTextElementListener() { public void end(String body) { - cache.hint = body.trim(); + cache.hint = validate(body.trim()); } }); @@ -373,8 +363,8 @@ public class cgGPXParser { public void start(Attributes attrs) { try { if (attrs.getIndex("html") > -1) { - final String at = attrs.getValue("html").toLowerCase(); - if (at.equals("false")) { + final String at = attrs.getValue("html"); + if (at.equalsIgnoreCase("false")) { htmlShort = false; } } @@ -387,7 +377,7 @@ public class cgGPXParser { gcCache.getChild(nsGC, "short_description").setEndTextElementListener(new EndTextElementListener() { public void end(String body) { - if (htmlShort == false) { + if (!htmlShort) { cache.shortdesc = Html.fromHtml(body).toString(); } else { cache.shortdesc = body; @@ -401,8 +391,7 @@ public class cgGPXParser { public void start(Attributes attrs) { try { if (attrs.getIndex("html") > -1) { - final String at = attrs.getValue("html").toLowerCase(); - if (at.equals("false")) { + if (attrs.getValue("html").equalsIgnoreCase("false")) { htmlLong = false; } } @@ -562,4 +551,23 @@ public class cgGPXParser { } return parsed ? search.getCurrentId() : 0l; } + + protected String validate(String input) { + if ("nil".equalsIgnoreCase(input)) { + return ""; + } + return input; + } + + private void setType(String parsedString) { + final String knownType = cgBase.cacheTypes.get(parsedString); + if (knownType != null) { + cache.type = knownType; + } + else { + if (cache.type == null || cache.type.length() == 0) { + cache.type = "mystery"; // default for not recognized types + } + } + } } |
