aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2012-05-10 07:16:31 +0200
committerBananeweizen <bananeweizen@gmx.de>2012-05-10 07:16:31 +0200
commit1a464a8b22467dfd9f4f5ddd76065528510a0987 (patch)
treeaa0a1d04e858f920e5488e84071f08a0c3c8d895 /main/src
parent0f5fcf18ede16f209d346ae6872238d5499b0b98 (diff)
downloadcgeo-1a464a8b22467dfd9f4f5ddd76065528510a0987.zip
cgeo-1a464a8b22467dfd9f4f5ddd76065528510a0987.tar.gz
cgeo-1a464a8b22467dfd9f4f5ddd76065528510a0987.tar.bz2
#1430: refactoring as discussed
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java12
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConnector.java20
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java20
3 files changed, 28 insertions, 24 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index a3ce685..1ec6eca 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -1634,11 +1634,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- final int result = GCConnector.addToWatchlist(cache);
- if (-1 != result) {
- app.saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE));
- }
- handler.sendEmptyMessage(result);
+ handler.sendEmptyMessage(GCConnector.addToWatchlist(cache) ? 1 : -1);
}
}
@@ -1652,11 +1648,7 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
public void run() {
- final int result = GCConnector.removeFromWatchlist(cache);
- if (-1 != result) {
- app.saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE));
- }
- handler.sendEmptyMessage(result);
+ handler.sendEmptyMessage(GCConnector.removeFromWatchlist(cache) ? 1 : -1);
}
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
index fbda5cd..4288a72 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
@@ -3,11 +3,14 @@ package cgeo.geocaching.connector.gc;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.StoredList;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
+import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
@@ -18,6 +21,7 @@ import cgeo.geocaching.utils.Log;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import java.util.EnumSet;
import java.util.regex.Pattern;
public class GCConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter {
@@ -134,12 +138,20 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
return cacheHasReliableLatLon;
}
- public static int addToWatchlist(cgCache cache) {
- return GCParser.addToWatchlist(cache);
+ public static boolean addToWatchlist(cgCache cache) {
+ final boolean added = GCParser.addToWatchlist(cache);
+ if (added) {
+ cgeoapplication.getInstance().saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE));
+ }
+ return added;
}
- public static int removeFromWatchlist(cgCache cache) {
- return GCParser.removeFromWatchlist(cache);
+ public static boolean removeFromWatchlist(cgCache cache) {
+ final boolean removed = GCParser.removeFromWatchlist(cache);
+ if (removed) {
+ cgeoapplication.getInstance().saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE));
+ }
+ return removed;
}
@Override
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index a986a7b..ed5a5a6 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -1099,18 +1099,18 @@ public abstract class GCParser {
/**
* Adds the cache to the watchlist of the user.
- *
+ *
* @param cache
* the cache to add
- * @return -1: error occured
+ * @return <code>false</code> if an error occurred, <code>true</code> otherwise
*/
- static int addToWatchlist(final cgCache cache) {
+ static boolean addToWatchlist(final cgCache cache) {
final String uri = "http://www.geocaching.com/my/watchlist.aspx?w=" + cache.getCacheId();
String page = Login.postRequestLogged(uri, null);
if (StringUtils.isBlank(page)) {
Log.e("cgBase.addToWatchlist: No data from server");
- return -1; // error
+ return false; // error
}
boolean guidOnPage = cache.isGuidContainedInPage(page);
@@ -1120,23 +1120,23 @@ public abstract class GCParser {
} else {
Log.e("cgBase.addToWatchlist: cache is not on watchlist");
}
- return guidOnPage ? 1 : -1; // on watchlist (=added) / else: error
+ return guidOnPage; // on watchlist (=added) / else: error
}
/**
* Removes the cache from the watchlist
- *
+ *
* @param cache
* the cache to remove
- * @return -1: error occured
+ * @return <code>false</code> if an error occurred, <code>true</code> otherwise
*/
- static int removeFromWatchlist(final cgCache cache) {
+ static boolean removeFromWatchlist(final cgCache cache) {
final String uri = "http://www.geocaching.com/my/watchlist.aspx?ds=1&action=rem&id=" + cache.getCacheId();
String page = Login.postRequestLogged(uri, null);
if (StringUtils.isBlank(page)) {
Log.e("cgBase.removeFromWatchlist: No data from server");
- return -1; // error
+ return false; // error
}
// removing cache from list needs approval by hitting "Yes" button
@@ -1154,7 +1154,7 @@ public abstract class GCParser {
} else {
Log.e("cgBase.removeFromWatchlist: cache not removed from watchlist");
}
- return guidOnPage ? -1 : 0; // on watchlist (=error) / not on watchlist
+ return !guidOnPage; // on watchlist (=error) / not on watchlist
}
/**