diff options
Diffstat (limited to 'main/src/cgeo/geocaching/cgeoapplication.java')
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 338 |
1 files changed, 7 insertions, 331 deletions
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 9e221cd..1371a00 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -1,21 +1,10 @@ package cgeo.geocaching; -import cgeo.geocaching.cgData.StorageLocation; import cgeo.geocaching.activity.ActivityMixin; -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; import cgeo.geocaching.network.StatusUpdater; import cgeo.geocaching.utils.IObserver; import cgeo.geocaching.utils.Log; -import org.apache.commons.lang3.StringUtils; - import android.app.Activity; import android.app.Application; import android.app.ProgressDialog; @@ -23,27 +12,17 @@ import android.content.res.Resources; import android.os.Handler; import android.os.Message; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; public class cgeoapplication extends Application { - final private cgData storage = new cgData(); private volatile GeoDataProvider geo; private volatile DirectionProvider dir; public boolean firstRun = true; // c:geo is just launched public boolean showLoginToast = true; //login toast shown just once. - private boolean databaseCleaned = false; // database was cleaned private boolean liveMapHintShown = false; // livemap hint has been shown final private StatusUpdater statusUpdater = new StatusUpdater(); - private static cgeoapplication instance = null; + private static cgeoapplication instance; public cgeoapplication() { instance = this; @@ -61,29 +40,21 @@ public class cgeoapplication extends Application { @Override public void onLowMemory() { Log.i("Cleaning applications cache."); - removeAllFromCache(); - } - - public void removeAllFromCache() { - storage.removeAllFromCache(); + cgData.removeAllFromCache(); } @Override public void onTerminate() { Log.d("Terminating c:geo…"); - storage.clean(); - storage.closeDb(); + cgData.clean(); + cgData.closeDb(); super.onTerminate(); } - public String backupDatabase() { - return storage.backupDatabase(); - } - /** - * Move the database to/from external storage in a new thread, + * Move the database to/from external cgdata in a new thread, * showing a progress window * * @param fromActivity @@ -105,18 +76,13 @@ public class cgeoapplication extends Application { @Override public void run() { - atomic.set(storage.moveDatabase()); + atomic.set(cgData.moveDatabase()); handler.sendMessage(handler.obtainMessage()); } }; moveThread.start(); } - - public static File isRestoreFile() { - return cgData.isRestoreFile(); - } - /** * restore the database in a new thread, showing a progress window * @@ -140,7 +106,7 @@ public class cgeoapplication extends Application { @Override public void run() { - atomic.set(storage.restoreDatabase()); + atomic.set(cgData.restoreDatabase()); handler.sendMessage(handler.obtainMessage()); } }; @@ -203,280 +169,6 @@ public class cgeoapplication extends Application { return statusUpdater; } - public boolean storageStatus() { - return storage.status(); - } - - public void cleanDatabase(boolean more) { - if (databaseCleaned) { - return; - } - - storage.clean(more); - databaseCleaned = true; - } - - /** {@link cgData#isThere(String, String, boolean, boolean)} */ - public boolean isThere(String geocode, String guid, boolean detailed, boolean checkTime) { - return storage.isThere(geocode, guid, detailed, checkTime); - } - - /** {@link cgData#isOffline(String, String)} */ - public boolean isOffline(String geocode, String guid) { - return storage.isOffline(geocode, guid); - } - - /** {@link cgData#getGeocodeForGuid(String)} */ - public String getGeocode(String guid) { - return storage.getGeocodeForGuid(guid); - } - - /** {@link cgData#getCacheidForGeocode(String)} */ - public String getCacheid(String geocode) { - return storage.getCacheidForGeocode(geocode); - } - - public boolean hasUnsavedCaches(final SearchResult search) { - if (search == null) { - return false; - } - - for (final String geocode : search.getGeocodes()) { - if (!isOffline(geocode, null)) { - return true; - } - } - return false; - } - - public cgTrackable getTrackableByGeocode(String geocode) { - if (StringUtils.isBlank(geocode)) { - return null; - } - - return storage.loadTrackable(geocode); - } - - /** {@link cgData#allDetailedThere()} */ - public String[] geocodesInCache() { - return storage.allDetailedThere(); - } - - public Viewport getBounds(String geocode) { - if (geocode == null) { - return null; - } - - return getBounds(Collections.singleton(geocode)); - } - - /** {@link cgData#getBounds(Set)} */ - public Viewport getBounds(final Set<String> geocodes) { - return storage.getBounds(geocodes); - } - - /** {@link cgData#loadBatchOfStoredGeocodes(boolean, Geopoint, CacheType, int)} */ - public SearchResult getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cacheType, final int listId) { - final Set<String> geocodes = storage.loadBatchOfStoredGeocodes(detailedOnly, coords, cacheType, listId); - return new SearchResult(geocodes, getAllStoredCachesCount(true, cacheType, listId)); - } - - /** {@link cgData#loadHistoryOfSearchedLocations()} */ - public List<Destination> getHistoryOfSearchedLocations() { - return storage.loadHistoryOfSearchedLocations(); - } - - public SearchResult getHistoryOfCaches(final boolean detailedOnly, final CacheType cacheType) { - final Set<String> geocodes = storage.loadBatchOfHistoricGeocodes(detailedOnly, cacheType); - return new SearchResult(geocodes, getAllHistoricCachesCount()); - } - - /** {@link cgData#loadCachedInViewport(Viewport, CacheType)} */ - public SearchResult getCachedInViewport(final Viewport viewport, final CacheType cacheType) { - final Set<String> geocodes = storage.loadCachedInViewport(viewport, cacheType); - return new SearchResult(geocodes); - } - - /** {@link cgData#loadStoredInViewport(Viewport, CacheType)} */ - public SearchResult getStoredInViewport(final Viewport viewport, final CacheType cacheType) { - final Set<String> geocodes = storage.loadStoredInViewport(viewport, cacheType); - return new SearchResult(geocodes); - } - - /** {@link cgData#getAllStoredCachesCount(boolean, CacheType, int)} */ - public int getAllStoredCachesCount(final boolean detailedOnly, final CacheType cacheType) { - return storage.getAllStoredCachesCount(detailedOnly, cacheType, 0); - } - - /** {@link cgData#getAllStoredCachesCount(boolean, CacheType, int)} */ - public int getAllStoredCachesCount(final boolean detailedOnly, final CacheType cacheType, final Integer list) { - return storage.getAllStoredCachesCount(detailedOnly, cacheType, list); - } - - /** {@link cgData#getAllHistoricCachesCount()} */ - public int getAllHistoricCachesCount() { - return storage.getAllHistoricCachesCount(); - } - - /** {@link cgData#moveToList(List, int)} */ - public void markStored(List<cgCache> caches, int listId) { - storage.moveToList(caches, listId); - } - - /** {@link cgData#moveToList(List, int)} */ - public void markDropped(List<cgCache> caches) { - storage.moveToList(caches, StoredList.TEMPORARY_LIST_ID); - } - - /** {@link cgData#clearSearchedDestinations()} */ - public boolean clearSearchedDestinations() { - return storage.clearSearchedDestinations(); - } - - /** {@link cgData#saveSearchedDestination(Destination)} */ - public void saveSearchedDestination(Destination destination) { - storage.saveSearchedDestination(destination); - } - - /** {@link cgData#saveWaypoints(cgCache)} */ - public boolean saveWaypoints(final cgCache cache) { - return storage.saveWaypoints(cache); - } - - public boolean saveWaypoint(int id, String geocode, cgWaypoint waypoint) { - if (storage.saveWaypoint(id, geocode, waypoint)) { - this.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); - return true; - } - return false; - } - - /** {@link cgData#deleteWaypoint(int)} */ - public boolean deleteWaypoint(int id) { - return storage.deleteWaypoint(id); - } - - public boolean saveTrackable(cgTrackable trackable) { - return storage.saveTrackable(trackable); - } - - /** {@link cgData#loadLogCounts(String)} */ - public Map<LogType, Integer> loadLogCounts(String geocode) { - return storage.loadLogCounts(geocode); - } - - /** {@link cgData#loadWaypoint(int)} */ - public cgWaypoint loadWaypoint(int id) { - return storage.loadWaypoint(id); - } - - /** {@link cgData#saveLogOffline(String, Date, LogType, String)} */ - public boolean saveLogOffline(String geocode, Date date, LogType logtype, String log) { - return storage.saveLogOffline(geocode, date, logtype, log); - } - - /** {@link cgData#loadLogOffline(String)} */ - public LogEntry loadLogOffline(String geocode) { - return storage.loadLogOffline(geocode); - } - - /** {@link cgData#clearLogOffline(String)} */ - public void clearLogOffline(String geocode) { - storage.clearLogOffline(geocode); - } - - /** {@link cgData#setVisitDate(List, long)} */ - public void saveVisitDate(String geocode) { - storage.setVisitDate(Collections.singletonList(geocode), System.currentTimeMillis()); - } - - /** {@link cgData#setVisitDate(List, long)} */ - public void clearVisitDate(List<cgCache> caches) { - ArrayList<String> geocodes = new ArrayList<String>(caches.size()); - for (cgCache cache : caches) { - geocodes.add(cache.getGeocode()); - } - storage.setVisitDate(geocodes, 0); - } - - /** {@link cgData#getLists(Resources)} */ - public List<StoredList> getLists() { - return storage.getLists(getResources()); - } - - /** {@link cgData#getList(int, Resources)} */ - public StoredList getList(int id) { - return storage.getList(id, getResources()); - } - - /** {@link cgData#createList(String)} */ - public int createList(String title) { - return storage.createList(title); - } - - /** {@link cgData#renameList(int, String)} */ - public int renameList(final int listId, final String title) { - return storage.renameList(listId, title); - } - - /** {@link cgData#removeList(int)} */ - public boolean removeList(int id) { - return storage.removeList(id); - } - - /** {@link cgData#removeSearchedDestination(Destination)} */ - public boolean removeSearchedDestinations(Destination destination) { - return storage.removeSearchedDestination(destination); - } - - /** {@link cgData#moveToList(List, int)} */ - public void moveToList(List<cgCache> caches, int listId) { - storage.moveToList(caches, listId); - } - - /** {@link cgData#getCacheDescription(String)} */ - public String getCacheDescription(String geocode) { - return storage.getCacheDescription(geocode); - } - - /** {@link cgData#loadCaches} */ - public cgCache loadCache(final String geocode, final EnumSet<LoadFlag> loadFlags) { - return storage.loadCache(geocode, loadFlags); - } - - /** {@link cgData#loadCaches} */ - public Set<cgCache> loadCaches(final Set<String> geocodes, final EnumSet<LoadFlag> loadFlags) { - 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.getStorageLocation().contains(StorageLocation.DATABASE) ? 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); - } - - /** {@link cgData#removeCache} */ - public void removeCache(String geocode, EnumSet<LoadFlags.RemoveFlag> removeFlags) { - storage.removeCache(geocode, removeFlags); - } - - /** {@link cgData#removeCaches} */ - public void removeCaches(final Set<String> geocodes, EnumSet<LoadFlags.RemoveFlag> removeFlags) { - storage.removeCaches(geocodes, removeFlags); - } - - public Set<cgWaypoint> getWaypointsInViewport(final Viewport viewport, boolean excludeMine, boolean excludeDisabled, CacheType type) { - return storage.loadWaypoints(viewport, excludeMine, excludeDisabled, type); - } - public boolean isLiveMapHintShown() { return liveMapHintShown; } @@ -485,20 +177,4 @@ public class cgeoapplication extends Application { liveMapHintShown = true; } - public String[] getTrackableCodes() { - return storage.getTrackableCodes(); - } - - public List<LogEntry> loadLogs(final String geocode) { - return storage.loadLogs(geocode); - } - - public List<String> loadAttributes(final String geocode) { - return storage.loadAttributes(geocode); - } - - public List<cgWaypoint> loadWaypoints(final String geocode) { - return storage.loadWaypoints(geocode); - } - } |
