diff options
author | blafoo <github@blafoo.de> | 2012-05-10 08:32:40 +0200 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2012-05-10 20:30:49 +0200 |
commit | a1872ca8261b558d6a737067bfa580921f1d6f42 (patch) | |
tree | bef89a35300eeade857e0d4f76cefcbb08648ab0 | |
parent | 05dfbb7b0126b50a852d3be422f6c1d0bdf0f2e1 (diff) | |
download | cgeo-a1872ca8261b558d6a737067bfa580921f1d6f42.zip cgeo-a1872ca8261b558d6a737067bfa580921f1d6f42.tar.gz cgeo-a1872ca8261b558d6a737067bfa580921f1d6f42.tar.bz2 |
Refactoring: updateCache()
-rw-r--r-- | main/src/cgeo/geocaching/VisitCacheActivity.java | 4 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 10 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCConnector.java | 8 |
3 files changed, 13 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/VisitCacheActivity.java b/main/src/cgeo/geocaching/VisitCacheActivity.java index df55ad6..13b21c7 100644 --- a/main/src/cgeo/geocaching/VisitCacheActivity.java +++ b/main/src/cgeo/geocaching/VisitCacheActivity.java @@ -4,7 +4,6 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.connector.gc.GCParser; import cgeo.geocaching.connector.gc.Login; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.LogTypeTrackable; import cgeo.geocaching.enumerations.StatusCode; @@ -43,7 +42,6 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.EnumSet; import java.util.List; public class VisitCacheActivity extends AbstractActivity implements DateDialog.DateDialogParent { @@ -708,7 +706,7 @@ public class VisitCacheActivity extends AbstractActivity implements DateDialog.D cache.setFound(true); } - app.saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE)); + app.updateCache(cache); } if (status == StatusCode.NO_ERROR) { diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 231bf55..63e34a6 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -5,6 +5,7 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; +import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; @@ -416,6 +417,15 @@ public class cgeoapplication extends Application { return storage.loadCaches(geocodes, loadFlags); } + /** + * Update a cache in the DB or in the CacheCace depending on it's storage location + * + * {@link cgData#saveCache} + */ + public boolean updateCache(cgCache cache) { + return saveCache(cache, cache.getListId() != StoredList.TEMPORARY_LIST_ID ? LoadFlags.SAVE_ALL : EnumSet.of(SaveFlag.SAVE_CACHE)); + } + /** {@link cgData#saveCache} */ public boolean saveCache(cgCache cache, EnumSet<LoadFlags.SaveFlag> saveFlags) { return storage.saveCache(cache, saveFlags); diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index f0d85ff..e30ce44 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -3,14 +3,11 @@ 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; @@ -21,7 +18,6 @@ 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 { @@ -141,7 +137,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, 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)); + cgeoapplication.getInstance().updateCache(cache); } return added; } @@ -149,7 +145,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, 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)); + cgeoapplication.getInstance().updateCache(cache); } return removed; } |