diff options
| author | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
|---|---|---|
| committer | blafoo <github@blafoo.de> | 2012-02-08 00:44:27 +0100 |
| commit | 0679e76ce7da5640cbeedbeff008624052b83991 (patch) | |
| tree | 3a8385e8f0b31b85691b1400e0a3e272f5e1bf01 /main/src/cgeo/geocaching/files | |
| parent | db271dd2cd94a809d4422f58818a02403c08bbd6 (diff) | |
| download | cgeo-0679e76ce7da5640cbeedbeff008624052b83991.zip cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.gz cgeo-0679e76ce7da5640cbeedbeff008624052b83991.tar.bz2 | |
Changed database handling
Diffstat (limited to 'main/src/cgeo/geocaching/files')
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileList.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXImporter.java | 16 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/LocParser.java | 11 |
4 files changed, 21 insertions, 17 deletions
diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java index 2ad05f5..5a788c0 100644 --- a/main/src/cgeo/geocaching/files/FileList.java +++ b/main/src/cgeo/geocaching/files/FileList.java @@ -2,6 +2,7 @@ package cgeo.geocaching.files; import cgeo.geocaching.R; import cgeo.geocaching.Settings; +import cgeo.geocaching.StoredList; import cgeo.geocaching.activity.AbstractListActivity; import org.apache.commons.collections.CollectionUtils; @@ -29,8 +30,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis private ProgressDialog waitDialog = null; private loadFiles searchingThread = null; private boolean endSearching = false; - private int listId = 1; - + private int listId = StoredList.STANDARD_LIST_ID; final private Handler changeWaitDialogHandler = new Handler() { private String searchInfo; @@ -105,8 +105,8 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis if (extras != null) { listId = extras.getInt("list"); } - if (listId <= 0) { - listId = 1; + if (listId <= StoredList.TEMPORARY_LIST_ID) { + listId = StoredList.STANDARD_LIST_ID; } setAdapter(); diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java index 8a4a8fc..836f6e8 100644 --- a/main/src/cgeo/geocaching/files/GPXImporter.java +++ b/main/src/cgeo/geocaching/files/GPXImporter.java @@ -7,6 +7,7 @@ import cgeo.geocaching.cgCache; import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.activity.Progress;
+import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.utils.CancellableHandler;
import org.apache.commons.lang3.StringUtils;
@@ -29,6 +30,7 @@ import java.io.InputStream; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.zip.ZipEntry;
@@ -138,7 +140,7 @@ public class GPXImporter { SearchResult search = storeParsedCaches(caches);
Log.i(Settings.tag, "Imported successfully " + caches.size() + " caches.");
- importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_FINISHED, SearchResult.getCount(search), 0, search));
+ importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_FINISHED, search.getCount(), 0, search));
} catch (IOException e) {
Log.i(Settings.tag, "Importing caches failed - error reading data: " + e.getMessage());
importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_FINISHED_WITH_ERROR, R.string.gpx_import_error_io, 0, e.getLocalizedMessage()));
@@ -161,17 +163,15 @@ public class GPXImporter { final cgeoapplication app = cgeoapplication.getInstance();
int storedCaches = 0;
for (cgCache cache : caches) {
- // remove from cache because a cache might be re-imported
- cgeoapplication.removeCacheFromCache(cache.getGeocode());
- app.addCacheToSearch(search, cache);
-
- // save memory, imported caches are typically not used immediately
- cgeoapplication.removeCacheFromCache(cache.getGeocode());
+ search.addCache(cache);
+ if (app.saveCache(cache, EnumSet.of(SaveFlag.SAVEDB))) {
+ storedCaches++;
+ }
if (progressHandler.isCancelled()) {
throw new CancellationException();
}
- progressHandler.sendMessage(progressHandler.obtainMessage(0, ++storedCaches, 0));
+ progressHandler.sendMessage(progressHandler.obtainMessage(0, storedCaches, 0));
}
return search;
}
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 1082c9c..79e790c 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -2,6 +2,7 @@ package cgeo.geocaching.files; import cgeo.geocaching.R; import cgeo.geocaching.Settings; +import cgeo.geocaching.StoredList; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgLog; import cgeo.geocaching.cgTrackable; @@ -64,7 +65,7 @@ public abstract class GPXParser extends FileParser { private static final Pattern PATTERN_MILLISECONDS = Pattern.compile("\\.\\d{3,7}"); - private int listId = 1; + private int listId = StoredList.STANDARD_LIST_ID; final protected String namespace; final private String version; diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 7a8a674..ea4c824 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -1,11 +1,13 @@ package cgeo.geocaching.files; -import cgeo.geocaching.ParseResult; +import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgCoord; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.geopoint.GeopointParser; import cgeo.geocaching.utils.CancellableHandler; @@ -42,12 +44,13 @@ public final class LocParser extends FileParser { private int listId; - public static void parseLoc(final ParseResult parseResult, final String fileContent) { + public static void parseLoc(final SearchResult searchResult, final String fileContent) { final Map<String, cgCoord> cidCoords = parseCoordinates(fileContent); // save found cache coordinates - for (cgCache cache : parseResult.cacheList) { - if (cidCoords.containsKey(cache.getGeocode())) { + for (String geocode : searchResult.getGeocodes()) { + if (cidCoords.containsKey(geocode)) { + cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOADCACHEORDB); cgCoord coord = cidCoords.get(cache.getGeocode()); copyCoordToCache(coord, cache); |
