diff options
| -rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 64 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 21 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/network/Network.java | 2 |
5 files changed, 72 insertions, 25 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 75faa49..03427c5 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -926,6 +926,12 @@ public final class Settings { return CacheType.getById(sharedPrefs.getString(KEY_CACHE_TYPE, CacheType.ALL.id)); } + /** + * The Threshold for the showing of child waypoints + * + * @return + */ + public static int getWayPointsThreshold() { return sharedPrefs.getInt(KEY_SHOW_WAYPOINTS_THRESHOLD, 0); } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index c437e72..2488dea 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -59,6 +59,8 @@ public class cgData { "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon", "coordsChanged", "finalDefined" // reason is replaced by listId in cgCache }; + /** The list of fields needed for mapping. */ + private static final String[] WAYPOINT_COLUMNS = new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }; /** Number of days (as ms) after temporarily saved caches are deleted */ private static long DAYS_AFTER_CACHE_IS_DELETED = 3 * 24 * 60 * 60 * 1000; @@ -1603,7 +1605,7 @@ public class cgData { // viewport limitation if (centerLat != null && centerLon != null && spanLat != null && spanLon != null) { - where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon); + where = buildCoordinateWhere(dbTableCaches, centerLat, centerLon, spanLat, spanLon); } else { @@ -1695,6 +1697,8 @@ public class cgData { /** * Builds a where for coordinates * + * @param dbtable + * * @param centerLat * @param centerLon * @param spanLat @@ -1702,7 +1706,7 @@ public class cgData { * @return */ - private static StringBuilder buildCoordinateWhere(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon) { + private static StringBuilder buildCoordinateWhere(String dbtable, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon) { StringBuilder where = new StringBuilder(); double latMin = (centerLat / 1e6) - ((spanLat / 1e6) / 2) - ((spanLat / 1e6) / 4); double latMax = (centerLat / 1e6) + ((spanLat / 1e6) / 2) + ((spanLat / 1e6) / 4); @@ -1721,13 +1725,25 @@ public class cgData { lonMin = llCache; } - where.append("(latitude >= "); + where.append("("); + where.append(dbtable); + where.append("."); + where.append("latitude >= "); where.append(String.format((Locale) null, "%.6f", latMin)); - where.append(" and latitude <= "); + where.append(" and "); + where.append(dbtable); + where.append("."); + where.append("latitude <= "); where.append(String.format((Locale) null, "%.6f", latMax)); - where.append(" and longitude >= "); + where.append(" and "); + where.append(dbtable); + where.append("."); + where.append("longitude >= "); where.append(String.format((Locale) null, "%.6f", lonMin)); - where.append(" and longitude <= "); + where.append(" and "); + where.append(dbtable); + where.append("."); + where.append("longitude <= "); where.append(String.format((Locale) null, "%.6f", lonMax)); where.append(')'); return where; @@ -1900,7 +1916,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }, + WAYPOINT_COLUMNS, "_id = ?", new String[] { Integer.toString(id) }, null, @@ -1934,7 +1950,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }, + WAYPOINT_COLUMNS, "geocode = ?", new String[] { geocode }, null, @@ -2481,7 +2497,7 @@ public class cgData { } // viewport limitation - StringBuilder where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon); + StringBuilder where = buildCoordinateWhere(dbTableCaches, centerLat, centerLon, spanLat, spanLon); // cacheType limitation if (cacheType != CacheType.ALL) { @@ -3139,24 +3155,32 @@ public class cgData { * @param centerLon * @param spanLat * @param spanLon + * @param excludeDisabled + * @param excludeMine * @return */ - public Collection<? extends cgWaypoint> loadWaypoints(long centerLat, long centerLon, long spanLat, long spanLon) { - StringBuilder where = buildCoordinateWhere(centerLat, centerLon, spanLat, spanLon); + public Collection<? extends cgWaypoint> loadWaypoints(long centerLat, long centerLon, long spanLat, long spanLon, boolean excludeMine, boolean excludeDisabled) { + StringBuilder where = buildCoordinateWhere(dbTableWaypoints, centerLat, centerLon, spanLat, spanLon); + if (excludeMine) + { + where.append("and " + dbTableCaches + ".own == 0 and " + dbTableCaches + ".found == 0 "); + } + if (excludeDisabled) + { + where.append("and " + dbTableCaches + ".disabled == 0 "); + } init(); List<cgWaypoint> waypoints = new ArrayList<cgWaypoint>(); - Cursor cursor = databaseRO.query( - dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }, - where.toString(), - null, - null, - null, - "_id", - "100"); + String query = "SELECT "; + for (int i = 0; i < WAYPOINT_COLUMNS.length; i++) { + query += (i > 0 ? ", " : "") + dbTableWaypoints + "." + WAYPOINT_COLUMNS[i] + " "; + } + query += " FROM " + dbTableWaypoints + ", " + dbTableCaches + " WHERE " + dbTableWaypoints + "._id == " + dbTableCaches + "._id and " + where; + Cursor cursor = databaseRO.rawQuery( + query, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index a8a62c3..3d7f630 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -524,8 +524,8 @@ public class cgeoapplication extends Application { storage.removeCaches(geocodes, removeFlags); } - public Collection<? extends cgWaypoint> getWaypointsInViewport(long centerLat, long centerLon, long spanLat, long spanLon) { - return storage.loadWaypoints(centerLat, centerLon, spanLat, spanLon); + public Collection<? extends cgWaypoint> getWaypointsInViewport(long centerLat, long centerLon, long spanLat, long spanLon, boolean excludeMine, boolean excludeDisabled) { + return storage.loadWaypoints(centerLat, centerLon, spanLat, spanLon, excludeMine, excludeDisabled); } } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index e5f8701..934a597 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1201,8 +1201,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto if (search != null) { downloaded = true; - caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_ONLY)); - waypoints.addAll(app.getWaypointsInViewport(centerLat, centerLon, spanLat, spanLon)); + Set<cgCache> cachesFromSearchResult = search.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS); + caches.addAll(cachesFromSearchResult); } if (live) { @@ -1217,6 +1217,23 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } } + countVisibleCaches(); + if (cachesCnt < Settings.getWayPointsThreshold()) + { + waypoints.clear(); + if (searchIntent == null && geocodeIntent == null) + { + //All visible waypoints + waypoints.addAll(app.getWaypointsInViewport(centerLat, centerLon, spanLat, spanLon, Settings.isExcludeMyCaches(), Settings.isExcludeDisabledCaches())); + } + else + { + //All waypoints from the viewed caches + for (cgCache c : caches.getAsList()) { + waypoints.addAll(c.getWaypoints()); + } + } + } //render displayExecutor.execute(new DisplayRunnable(centerLat, centerLon, spanLat, spanLon)); diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index 8aed160..bb5a949 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -278,7 +278,7 @@ public abstract class Network { } static public boolean isSuccess(final HttpResponse response) { - return response.getStatusLine().getStatusCode() == 200; + return response != null && response.getStatusLine().getStatusCode() == 200; } public static JSONObject requestJSON(final String uri, final Parameters params) { |
