aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/DataStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/DataStore.java')
-rw-r--r--main/src/cgeo/geocaching/DataStore.java56
1 files changed, 15 insertions, 41 deletions
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java
index 02f48a0..b7ca577 100644
--- a/main/src/cgeo/geocaching/DataStore.java
+++ b/main/src/cgeo/geocaching/DataStore.java
@@ -39,7 +39,6 @@ import rx.functions.Action1;
import rx.functions.Func0;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
-import rx.util.async.Async;
import android.app.Activity;
import android.app.ProgressDialog;
@@ -403,16 +402,15 @@ public class DataStore {
* Move the database to/from external cgdata in a new thread,
* showing a progress window
*
- * @param fromActivity
*/
public static void moveDatabase(final Activity fromActivity) {
final ProgressDialog dialog = ProgressDialog.show(fromActivity, fromActivity.getString(R.string.init_dbmove_dbmove), fromActivity.getString(R.string.init_dbmove_running), true, false);
- AppObservable.bindActivity(fromActivity, Async.fromCallable(new Func0<Boolean>() {
+ AppObservable.bindActivity(fromActivity, Observable.defer(new Func0<Observable<Boolean>>() {
@Override
- public Boolean call() {
+ public Observable<Boolean> call() {
if (!LocalStorage.isExternalStorageAvailable()) {
Log.w("Database was not moved: external memory not available");
- return false;
+ return Observable.just(false);
}
closeDb();
@@ -421,7 +419,7 @@ public class DataStore {
if (!LocalStorage.copy(source, target)) {
Log.e("Database could not be moved to " + target);
init();
- return false;
+ return Observable.just(false);
}
if (!FileUtils.delete(source)) {
Log.e("Original database could not be deleted during move");
@@ -430,7 +428,7 @@ public class DataStore {
Log.i("Database was moved to " + target);
init();
- return true;
+ return Observable.just(true);
}
})).subscribeOn(Schedulers.io()).subscribe(new Action1<Boolean>() {
@Override
@@ -884,7 +882,7 @@ public class DataStore {
final File[] files = LocalStorage.getStorage().listFiles();
if (ArrayUtils.isNotEmpty(files)) {
final Pattern oldFilePattern = Pattern.compile("^[GC|TB|EC|GK|O][A-Z0-9]{4,7}$");
- final SQLiteStatement select = db.compileStatement("select count(*) from " + dbTableCaches + " where geocode = ?");
+ final SQLiteStatement select = PreparedStatement.CHECK_IF_PRESENT.getStatement();
final ArrayList<File> toRemove = new ArrayList<>(files.length);
for (final File file : files) {
if (file.isDirectory()) {
@@ -907,7 +905,7 @@ public class DataStore {
public void call() {
for (final File dir : toRemove) {
Log.i("Removing obsolete cache directory for " + dir.getName());
- LocalStorage.deleteDirectory(dir);
+ FileUtils.deleteDirectory(dir);
}
}
});
@@ -1062,7 +1060,6 @@ public class DataStore {
*
* @param cache
* the Cache to save in the CacheCache/DB
- * @param saveFlags
*
*/
public static void saveCache(final Geocache cache, final Set<LoadFlags.SaveFlag> saveFlags) {
@@ -1074,7 +1071,6 @@ public class DataStore {
*
* @param caches
* the caches to save in the CacheCache/DB
- * @param saveFlags
*
*/
public static void saveCaches(final Collection<Geocache> caches, final Set<LoadFlags.SaveFlag> saveFlags) {
@@ -1313,7 +1309,6 @@ public class DataStore {
/**
* remove all waypoints of the given cache, where the id is not in the given list
*
- * @param cache
* @param remainingWaypointIds
* ids of waypoints which shall not be deleted
*/
@@ -1563,7 +1558,6 @@ public class DataStore {
/**
* Load caches.
*
- * @param geocodes
* @return Set of loaded caches. Never null.
*/
@NonNull
@@ -1619,8 +1613,6 @@ public class DataStore {
/**
* Load caches.
*
- * @param geocodes
- * @param loadFlags
* @return Set of loaded caches. Never null.
*/
@NonNull
@@ -1710,9 +1702,6 @@ public class DataStore {
/**
* Builds a where for a viewport with the size enhanced by 50%.
*
- * @param dbTable
- * @param viewport
- * @return
*/
@NonNull
@@ -1723,7 +1712,6 @@ public class DataStore {
/**
* creates a Cache from the cursor. Doesn't next.
*
- * @param cursor
* @return Cache from DB
*/
@NonNull
@@ -1939,7 +1927,6 @@ public class DataStore {
}
/**
- * @param geocode
* @return an immutable, non null list of logs
*/
@NonNull
@@ -2089,9 +2076,6 @@ public class DataStore {
/**
* Number of caches stored for a given type and/or list
*
- * @param cacheType
- * @param list
- * @return
*/
public static int getAllStoredCachesCount(final CacheType cacheType, final int list) {
if (cacheType == null) {
@@ -2177,8 +2161,6 @@ public class DataStore {
*
* @param coords
* the current coordinates to sort by distance, or null to sort by geocode
- * @param cacheType
- * @param listId
* @return a non-null set of geocodes
*/
@NonNull
@@ -2374,7 +2356,7 @@ public class DataStore {
database.delete(dbTableLogImages, "log_id NOT IN (SELECT _id FROM " + dbTableLogs + ")", null);
// Remove the obsolete "_others" directory where the user avatar used to be stored.
- LocalStorage.deleteDirectory(LocalStorage.getStorageDir("_others"));
+ FileUtils.deleteDirectory(LocalStorage.getStorageDir("_others"));
if (version > -1) {
Settings.setVersion(version);
@@ -2391,8 +2373,6 @@ public class DataStore {
/**
* remove all geocodes from the given list of geocodes where an offline log exists
*
- * @param geocodes
- * @return
*/
@NonNull
private static Set<String> exceptCachesWithOfflineLog(@NonNull final Set<String> geocodes) {
@@ -2472,7 +2452,7 @@ public class DataStore {
// Delete cache directories
for (final String geocode : geocodes) {
- LocalStorage.deleteDirectory(LocalStorage.getStorageDir(geocode));
+ FileUtils.deleteDirectory(LocalStorage.getStorageDir(geocode));
}
}
}
@@ -2739,7 +2719,6 @@ public class DataStore {
/**
* Remove a list. Caches in the list are moved to the standard list.
*
- * @param listId
* @return true if the list got deleted, false else
*/
public static boolean removeList(final int listId) {
@@ -2831,8 +2810,6 @@ public class DataStore {
/**
* Load the lazily initialized fields of a cache and return them as partial cache (all other fields unset).
*
- * @param geocode
- * @return
*/
@NonNull
public static Geocache loadCacheTexts(final String geocode) {
@@ -2909,10 +2886,6 @@ public class DataStore {
/**
* Loads all Waypoints in the coordinate rectangle.
*
- * @param excludeDisabled
- * @param excludeMine
- * @param type
- * @return
*/
@NonNull
@@ -2951,7 +2924,7 @@ public class DataStore {
private static enum PreparedStatement {
- HISTORY_COUNT("select count(_id) from " + dbTableCaches + " where visiteddate > 0"),
+ HISTORY_COUNT("SELECT COUNT(_id) FROM " + dbTableCaches + " WHERE visiteddate > 0"),
MOVE_TO_STANDARD_LIST("UPDATE " + dbTableCaches + " SET reason = " + StoredList.STANDARD_LIST_ID + " WHERE reason = ?"),
MOVE_TO_LIST("UPDATE " + dbTableCaches + " SET reason = ? WHERE geocode = ?"),
UPDATE_VISIT_DATE("UPDATE " + dbTableCaches + " SET visiteddate = ? WHERE geocode = ?"),
@@ -2967,10 +2940,11 @@ public class DataStore {
LIST_ID_OF_GUID("SELECT reason FROM " + dbTableCaches + " WHERE guid = ?"),
GEOCODE_OF_GUID("SELECT geocode FROM " + dbTableCaches + " WHERE guid = ?"),
INSERT_SEARCH_DESTINATION("INSERT INTO " + dbTableSearchDestinationHistory + " (date, latitude, longitude) VALUES (?, ?, ?)"),
- COUNT_TYPE_ALL_LIST("select count(_id) from " + dbTableCaches + " where detailed = 1 and type = ? and reason > 0"), // See use of COUNT_TYPE_LIST for synchronization
- COUNT_ALL_TYPES_ALL_LIST("select count(_id) from " + dbTableCaches + " where detailed = 1 and reason > 0"), // See use of COUNT_TYPE_LIST for synchronization
- COUNT_TYPE_LIST("select count(_id) from " + dbTableCaches + " where detailed = 1 and type = ? and reason = ?"),
- COUNT_ALL_TYPES_LIST("select count(_id) from " + dbTableCaches + " where detailed = 1 and reason = ?"); // See use of COUNT_TYPE_LIST for synchronization
+ COUNT_TYPE_ALL_LIST("SELECT COUNT(_id) FROM " + dbTableCaches + " WHERE detailed = 1 AND type = ? AND reason > 0"), // See use of COUNT_TYPE_LIST for synchronization
+ COUNT_ALL_TYPES_ALL_LIST("SELECT COUNT(_id) FROM " + dbTableCaches + " WHERE detailed = 1 AND reason > 0"), // See use of COUNT_TYPE_LIST for synchronization
+ COUNT_TYPE_LIST("SELECT COUNT(_id) FROM " + dbTableCaches + " WHERE detailed = 1 AND type = ? AND reason = ?"),
+ COUNT_ALL_TYPES_LIST("SELECT COUNT(_id) FROM " + dbTableCaches + " WHERE detailed = 1 AND reason = ?"), // See use of COUNT_TYPE_LIST for synchronization
+ CHECK_IF_PRESENT("SELECT COUNT(*) FROM " + dbTableCaches + " WHERE geocode = ?");
private static final List<PreparedStatement> statements = new ArrayList<>();