diff options
Diffstat (limited to 'main/src/cgeo/geocaching')
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 38 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 7 |
4 files changed, 39 insertions, 12 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 8173ee0..9b4e09c 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -374,7 +374,13 @@ public class cgBase { return StatusCode.NO_ERROR; } - public static boolean checkLogin(String page) { + /** + * Check if the user has been logged in when he retrieved the data. + * + * @param page + * @return true = User has been logged in, false else + */ + private static boolean checkLogin(String page) { if (StringUtils.isBlank(page)) { Log.e(Settings.tag, "cgeoBase.checkLogin: No page given"); return false; @@ -913,7 +919,7 @@ public class cgBase { // on watchlist cache.setOnWatchlist(BaseUtils.matches(page, GCConstants.PATTERN_WATCHLIST)); - // latitude and longitude + // latitude and longitude. Can only be retrieved if user is logged in cache.setLatlon(BaseUtils.getMatch(page, GCConstants.PATTERN_LATLON, true, cache.getLatlon())); if (StringUtils.isNotEmpty(cache.getLatlon())) { try { @@ -1196,11 +1202,13 @@ public class cgBase { int position = 0; List<cgLog> allLogs = cache.getLogs(); List<cgLog> friendLogs = loadLogsFromDetails(page, cache, true); - for (cgLog log : friendLogs) { - if (allLogs.contains(log)) { - allLogs.get(allLogs.indexOf(log)).friend = true; - } else { - allLogs.add(position++, log); + if (friendLogs != null) { + for (cgLog log : friendLogs) { + if (allLogs.contains(log)) { + allLogs.get(allLogs.indexOf(log)).friend = true; + } else { + allLogs.add(position++, log); + } } } } @@ -2393,11 +2401,20 @@ public class cgBase { return getResponseDataOnError(response); } + /** + * POST HTTP request. Do the request a second time if the user is not logged in + * + * @param uri + * @return + */ public static String postRequestLogged(final String uri) { - final String data = getResponseData(postRequest(uri, null)); + HttpResponse response = postRequest(uri, null); + String data = getResponseData(response); + if (!checkLogin(data)) { if (login() == StatusCode.NO_ERROR) { - return getResponseData(postRequest(uri, null)); + response = postRequest(uri, null); + data = getResponseData(response); } else { Log.i(Settings.tag, "Working as guest."); } @@ -2406,7 +2423,7 @@ public class cgBase { } /** - * GET HTTP request + * GET HTTP request. Do the request a second time if the user is not logged in * * @param uri * @param params @@ -2427,7 +2444,6 @@ public class cgBase { Log.i(Settings.tag, "Working as guest."); } } - return data; } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 1bad99d..e7fee43 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -688,6 +688,9 @@ public class cgCache implements ICache { this.coords = coords; } + /** + * @return true if the coords are from the cache details page and the user has been logged in + */ public boolean isReliableLatLon() { return reliableLatLon; } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 206d3f3..df98fb0 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2991,7 +2991,8 @@ public class cgData { * @param geocodes * list of geocodes to drop from cache */ - private void dropCaches(final List<String> geocodes) { + public void dropCaches(final List<String> geocodes) { + init(); // Drop caches from the database final ArrayList<String> quotedGeocodes = new ArrayList<String>(geocodes.size()); for (final String geocode : geocodes) { diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 96fa5e0..99d894d 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -495,6 +495,13 @@ public class cgeoapplication extends Application { storage.dropStored(listId); } + /** + * {@link cgData#dropCaches(List)} + */ + public void dropCaches(final List<String> geocodes) { + storage.dropCaches(geocodes); + } + public List<cgTrackable> loadInventory(String geocode) { return storage.loadInventory(geocode); } |
