diff options
| author | Karsten Priegnitz <koem@petoria.de> | 2011-07-30 16:14:01 +0200 |
|---|---|---|
| committer | Karsten Priegnitz <koem@petoria.de> | 2011-07-30 16:14:01 +0200 |
| commit | 85c31e1af4e10cc11dde0a800f0f27078dcd9bc8 (patch) | |
| tree | 74fa616cc588e6a3f0b4ed5ac2dee68cdf8ae8dd /src/cgeo/geocaching/cgBase.java | |
| parent | c0d0aadb058ef60bc6754687945e6d6c7b2e833b (diff) | |
| download | cgeo-85c31e1af4e10cc11dde0a800f0f27078dcd9bc8.zip cgeo-85c31e1af4e10cc11dde0a800f0f27078dcd9bc8.tar.gz cgeo-85c31e1af4e10cc11dde0a800f0f27078dcd9bc8.tar.bz2 | |
- refactoring: less and clearer code
- now parsing watchlist state when reading cache details
- did some little refactoring in cgData (read/write booleans with inline if)
- I introduced a new DB-Version (53). Don't know if I could've put my changes in #52?
- I put the watchlist information in a separate box with buttons
- screenshots
- http://koem.kicks-ass.net/notonwatchlist.png
- http://koem.kicks-ass.net/onwatchlist.png
Diffstat (limited to 'src/cgeo/geocaching/cgBase.java')
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index 06fa2ab..bdba245 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -1113,6 +1113,7 @@ public class cgBase { final Pattern patternSpoilersInside = Pattern.compile("[^<]*<a href=\"([^\"]+)\"[^>]*>[^<]*<img[^>]+>[^<]*<span>([^>]+)</span>[^<]*</a>[^<]*<br[^>]*>(([^<]*)(<br[^<]*>)+)?", Pattern.CASE_INSENSITIVE); final Pattern patternInventory = Pattern.compile("<span id=\"ctl00_ContentBody_uxTravelBugList_uxInventoryLabel\">[^\\w]*Inventory[^<]*</span>[^<]*</h3>[^<]*<div class=\"WidgetBody\">([^<]*<ul>(([^<]*<li>[^<]*<a href=\"[^\"]+\"[^>]*>[^<]*<img src=\"[^\"]+\"[^>]*>[^<]*<span>[^<]+<\\/span>[^<]*<\\/a>[^<]*<\\/li>)+)[^<]*<\\/ul>)?", Pattern.CASE_INSENSITIVE); final Pattern patternInventoryInside = Pattern.compile("[^<]*<li>[^<]*<a href=\"[a-z0-9\\-\\_\\.\\?\\/\\:\\@]*\\/track\\/details\\.aspx\\?guid=([0-9a-z\\-]+)[^\"]*\"[^>]*>[^<]*<img src=\"[^\"]+\"[^>]*>[^<]*<span>([^<]+)<\\/span>[^<]*<\\/a>[^<]*<\\/li>", Pattern.CASE_INSENSITIVE); + final Pattern patternOnWatchlist = Pattern.compile("<img\\s*src=\"\\/images\\/stockholm\\/16x16\\/icon_stop_watchlist.gif\"", Pattern.CASE_INSENSITIVE); final cgCacheWrap caches = new cgCacheWrap(); final cgCache cache = new cgCache(); @@ -1361,6 +1362,15 @@ public class cgBase { // failed to parse type Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache type"); } + + // cache on watchlist + try { + final Matcher matcher = patternOnWatchlist.matcher(page); + cache.onWatchlist = matcher.find(); + } catch (Exception e) { + // failed to parse onWatchlist + Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse onWatchlist"); + } // latitude and logitude try { @@ -3950,35 +3960,11 @@ public class cgBase { return 1000; } - /** - * Checks if the cache is on the watchlist of the user or not. - * - * @param cache the cache to check - * @return 0: removed, 1: added, -1: error occured - */ - public int readWatchlistState(cgCache cache) { - String page = requestLogged(false, "www.geocaching.com", "/my/watchlist.aspx", - "POST", null, false, false, false); - - if (page == null || page.length() == 0) { - Log.e(cgSettings.tag, "cgBase.readWatchlistState: No data from server"); - return -1; // error - } - - boolean guidOnPage = checkPageForGuid(cache, page); - if (guidOnPage) - Log.i(cgSettings.tag, "cgBase.readWatchlistState: cache is on watchlist"); - else - Log.i(cgSettings.tag, "cgBase.readWatchlistState: cache is not on watchlist"); - - return guidOnPage ? 1 : 0; // on watchlist / not on watchlist - } - /** * Adds the cache is to the watchlist of the user. * * @param cache the cache to add - * @return 0: removed, 1: added, -1: error occured + * @return -1: error occured */ public int addToWatchlist(cgCache cache) { String page = requestLogged(false, "www.geocaching.com", "/my/watchlist.aspx?w=" + cache.cacheid, @@ -3990,11 +3976,12 @@ public class cgBase { } boolean guidOnPage = checkPageForGuid(cache, page); - if (guidOnPage) + if (guidOnPage) { Log.i(cgSettings.tag, "cgBase.addToWatchlist: cache is on watchlist"); - else + cache.onWatchlist = true; + } else { Log.e(cgSettings.tag, "cgBase.addToWatchlist: cache is not on watchlist"); - + } return guidOnPage ? 1 : -1; // on watchlist (=added) / else: error } @@ -4002,7 +3989,7 @@ public class cgBase { * Removes the given cache from the watchlist * * @param cache the cache to remove - * @return 0: removed, 1: added, -1: error occured + * @return -1: error occured */ public int removeFromWatchlist(cgCache cache) { String method = "POST"; @@ -4030,10 +4017,12 @@ public class cgBase { page = request(false, host, path, method, params, false, false, false).getData(); boolean guidOnPage = checkPageForGuid(cache, page); - if (! guidOnPage) + if (! guidOnPage) { Log.i(cgSettings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist"); - else + cache.onWatchlist = false; + } else { Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: cache not removed from watchlist"); + } return guidOnPage ? -1 : 0; // on watchlist (=error) / not on watchlist } |
