diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-01-01 17:38:32 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-01-01 17:38:32 +0100 |
| commit | eaca5dc0993d22ff5390a2f90cbfd63447fe33b0 (patch) | |
| tree | f45671f7a3b654d49c8a9b45f2db63cdf75d041a | |
| parent | 415f3ce9871f727cadebc45a06769c99f0b7dd3c (diff) | |
| parent | c80b861a1072bd955c7ec51eab6bca0af19da137 (diff) | |
| download | cgeo-eaca5dc0993d22ff5390a2f90cbfd63447fe33b0.zip cgeo-eaca5dc0993d22ff5390a2f90cbfd63447fe33b0.tar.gz cgeo-eaca5dc0993d22ff5390a2f90cbfd63447fe33b0.tar.bz2 | |
Merge branch 'release' into upstream
| -rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 25 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java | 13 |
4 files changed, 42 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index a766470..e059bba 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -1344,8 +1344,9 @@ public final class Settings { } public static String getPreferencesName() { - // there is currently no Android API to get the file name of the shared preferences - return cgeoapplication.getInstance().getPackageName() + "_preferences"; + // There is currently no Android API to get the file name of the shared preferences. Let's hardcode + // it without needing a cgeoapplication instance. + return "cgeo.geocaching_preferences"; } public static boolean getPlainLogs() { diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 78611b8..e8865c7 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -372,6 +372,8 @@ public class cgData { private static class DbHelper extends SQLiteOpenHelper { + private static boolean firstRun = true; + DbHelper(Context context) { super(context, databasePath().getPath(), null, dbVersion); } @@ -665,6 +667,29 @@ public class cgData { Log.i("Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": completed"); } + @Override + public void onOpen(final SQLiteDatabase db) { + if (firstRun) { + sanityChecks(db); + firstRun = false; + } + } + + /** + * Execute sanity checks that should be performed once per application after the database has been + * opened. + * + * @param db the database to perform sanity checks against + */ + private static void sanityChecks(final SQLiteDatabase db) { + // Check that the history of searches is well formed as some dates seem to be missing according + // to NPE traces. + final int staleHistorySearches = db.delete(dbTableSearchDestionationHistory, "date is null", null); + if (staleHistorySearches > 0) { + Log.w(String.format("cgData.dbHelper.onOpen: removed %d bad search history entries", staleHistorySearches)); + } + } + /** * Method to remove static map files with double underscore due to issue#1670 * introduced with release on 2012-05-24. diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java index 294eb79..dc0dbf8 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapProvider.java @@ -93,7 +93,7 @@ public final class MapsforgeMapProvider extends AbstractMapProvider { } private static boolean isMapfile024(String mapFileIn) { - return org.mapsforge.android.mapsold.MapDatabase.isValidMapFile(mapFileIn); + return mapFileIn != null && org.mapsforge.android.mapsold.MapDatabase.isValidMapFile(mapFileIn); } @Override diff --git a/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java index 0df3289..aafce4f 100644 --- a/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java +++ b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java @@ -2,6 +2,7 @@ package cgeo.geocaching.utils; import java.util.AbstractSet; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -102,6 +103,18 @@ public class LeastRecentlyUsedSet<E> extends AbstractSet<E> } /** + * Synchronized removal of all elements contained in another collection. + */ + @Override + public synchronized boolean removeAll(final Collection<?> c) { + boolean changed = false; + for (final Object o: c) { + changed |= remove(o); + } + return changed; + } + + /** * Synchronized clearing of the set * Copy of the HashSet code if clear() * |
