From e9036a056e072e93cd7002111c118165cb2189ba Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Tue, 30 Aug 2011 16:38:21 +0200 Subject: Step 1 of Performance Cut down number of selects per cache --- src/cgeo/geocaching/cgCache.java | 26 +--------------- src/cgeo/geocaching/cgData.java | 51 +++++++++++++++++++++----------- src/cgeo/geocaching/cgeoapplication.java | 12 ++++---- 3 files changed, 41 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java index 8de5a5d..f47150b 100644 --- a/src/cgeo/geocaching/cgCache.java +++ b/src/cgeo/geocaching/cgCache.java @@ -74,31 +74,7 @@ public class cgCache { public boolean statusCheckedView = false; public String directionImg = null; - public cgCache merge(cgData storage) { - - boolean loadA = true; - boolean loadW = true; - boolean loadS = true; - boolean loadL = true; - boolean loadI = true; - - if (attributes == null || attributes.isEmpty()) { - loadA = false; - } - if (waypoints == null || waypoints.isEmpty()) { - loadW = false; - } - if (spoilers == null || spoilers.isEmpty()) { - loadS = false; - } - if (logs == null || logs.isEmpty()) { - loadL = false; - } - if (inventory == null || inventory.isEmpty()) { - loadI = false; - } - - final cgCache oldCache = storage.loadCache(geocode, guid, loadA, loadW, loadS, loadL, loadI, false); + public cgCache merge(cgData storage, cgCache oldCache) { if (oldCache == null) { return this; diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index ab24864..fd6cf06 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -226,7 +226,7 @@ public class cgData { if (dbHelper == null) { dbHelper = new cgDbHelper(context); } - databaseRO = dbHelper.getReadableDatabase(); + databaseRO = dbHelper.getWritableDatabase(); if (databaseRO.needUpgrade(dbVersion)) { databaseRO = null; @@ -985,7 +985,9 @@ public class cgData { return false; } } - + + + @Deprecated public boolean isReliableLatLon(String geocode, String guid) { init(); @@ -1166,7 +1168,8 @@ public class cgData { values.put("distance", cache.distance); values.put("direction", cache.direction); // save coordinates - final boolean rel = isReliableLatLon(cache.geocode, cache.guid); + //FIXME Why isn't it loaded before + final boolean rel = cache.reliableLatLon;//isReliableLatLon(cache.geocode, cache.guid); if (cache.reliableLatLon) { // new cache has reliable coordinates, store values.put("latitude", cache.latitude); values.put("longitude", cache.longitude); @@ -1721,23 +1724,29 @@ public class cgData { ArrayList caches = new ArrayList(); try { - if (geocodes != null && geocodes.length > 0) { - StringBuilder all = new StringBuilder(); - for (Object one : geocodes) { - if (all.length() > 0) { - all.append(", "); + if (geocodes != null) { + if (geocodes.length == 1 && false) { + where.append("geocode == \""); + where.append(geocodes[0]); + where.append("\""); + } else if (geocodes.length > 0) { + StringBuilder all = new StringBuilder(); + for (Object one : geocodes) { + if (all.length() > 0) { + all.append(", "); + } + all.append("\""); + all.append((String) one); + all.append("\""); } - all.append("\""); - all.append((String) one); - all.append("\""); - } - if (where.length() > 0) { - where.append(" and "); + if (where.length() > 0) { + where.append(" and "); + } + where.append("geocode in ("); + where.append(all); + where.append(")"); } - where.append("geocode in ("); - where.append(all); - where.append(")"); } else if (guids != null && guids.length > 0) { StringBuilder all = new StringBuilder(); for (Object one : guids) { @@ -1792,7 +1801,7 @@ public class cgData { where.append(String.format((Locale) null, "%.6f", lonMax)); where.append(")"); } - + long start = System.currentTimeMillis(); cursor = databaseRO.query( dbTableCaches, new String[]{ @@ -1807,6 +1816,11 @@ public class cgData { null, null, null); + long end = System.currentTimeMillis(); + if((end-start)> 100) + { + System.out.println("" + (end-start) + where); + } if (cursor != null) { int index = 0; @@ -1883,6 +1897,7 @@ public class cgData { cache.favourite = cursor.getLong(cursor.getColumnIndex("favourite")) == 1l; cache.inventoryItems = (Integer) cursor.getInt(cursor.getColumnIndex("inventoryunknown")); cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1l; + cache.reliableLatLon = cursor.getInt(cursor.getColumnIndex("reliable_latlon"))>0; if (loadA) { ArrayList attributes = loadAttributes(cache.geocode); diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index e165c0f..e3ac9aa 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -691,11 +691,12 @@ public class cgeoapplication extends Application { cache.reason = reason; - if (storage.isThere(geocode, guid, false, false)) { - cgCache mergedCache = cache.merge(storage); + cgCache oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true); + if (oldCache!=null) { + cgCache mergedCache = cache.merge(storage,oldCache); storage.saveCache(mergedCache); } else { - // cache is not saved, new data are for storing + // cache is not saved, new data is for storing storage.saveCache(cache); } } @@ -720,10 +721,11 @@ public class cgeoapplication extends Application { boolean status = false; - if (storage.isThere(geocode, guid, false, false) == false || cache.reason >= 1) { // if for offline, do not merge + cgCache oldCache = null; + if (cache.reason >= 1 || (oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true)) !=null ) { // if for offline, do not merge status = storage.saveCache(cache); } else { - cgCache mergedCache = cache.merge(storage); + cgCache mergedCache = cache.merge(storage,oldCache); status = storage.saveCache(mergedCache); } -- cgit v1.1 From 6426de589cff816fa3f939be4e129843e62ed4fd Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Tue, 6 Sep 2011 20:43:36 +0200 Subject: Step 2 Removed Complex Where --- src/cgeo/geocaching/cgData.java | 212 ++++++++++++++++------------- src/cgeo/geocaching/cgeoapplication.java | 37 +++-- src/cgeo/geocaching/mapcommon/cgeomap.java | 6 +- 3 files changed, 146 insertions(+), 109 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index fd6cf06..239570e 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -29,12 +29,23 @@ import android.util.Log; public class cgData { + /**The list of fields needed for mapping.*/ + private static final String[] CACHE_COLUMNS = new String[]{ + "_id", "updated", "reason", "detailed", "detailedupdate", "visiteddate", "geocode", "cacheid", "guid", "type", "name", "own", "owner", "owner_real", "hidden", "hint", "size", + "difficulty", "distance", "direction", "terrain", "latlon", "latitude_string", "longitude_string", "location", "latitude", "longitude", "elevation", "shortdesc", + "description", "favourite_cnt", "rating", "votes", "myvote", "disabled", "archived", "members", "found", "favourite", "inventorycoins", "inventorytags", + "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon" + }; public cgCacheWrap caches; private Context context = null; private String path = null; private cgDbHelper dbHelper = null; - private SQLiteDatabase databaseRO = null; - private SQLiteDatabase databaseRW = null; + // Used when Profiling and loggin SELECTS +// private SQLiteDatabasePerformanceLoggingWrapper databaseRO = null; +// private SQLiteDatabasePerformanceLoggingWrapper databaseRW = null; + private SQLiteDatabase databaseRW; + private SQLiteDatabase databaseRO; + private static final int dbVersion = 55; private static final String dbName = "data"; private static final String dbTableCaches = "cg_caches"; @@ -205,6 +216,7 @@ public class cgData { if (dbHelper == null) { dbHelper = new cgDbHelper(context); } +// databaseRW = new SQLiteDatabasePerformanceLoggingWrapper(dbHelper.getWritableDatabase()); databaseRW = dbHelper.getWritableDatabase(); if (databaseRW != null && databaseRW.isOpen()) { @@ -226,7 +238,8 @@ public class cgData { if (dbHelper == null) { dbHelper = new cgDbHelper(context); } - databaseRO = dbHelper.getWritableDatabase(); +// databaseRO = new SQLiteDatabasePerformanceLoggingWrapper(dbHelper.getReadableDatabase()); + databaseRO = dbHelper.getReadableDatabase(); if (databaseRO.needUpgrade(dbVersion)) { databaseRO = null; @@ -1168,8 +1181,8 @@ public class cgData { values.put("distance", cache.distance); values.put("direction", cache.direction); // save coordinates - //FIXME Why isn't it loaded before - final boolean rel = cache.reliableLatLon;//isReliableLatLon(cache.geocode, cache.guid); + + final boolean rel = cache.reliableLatLon; if (cache.reliableLatLon) { // new cache has reliable coordinates, store values.put("latitude", cache.latitude); values.put("longitude", cache.longitude); @@ -1679,6 +1692,19 @@ public class cgData { public cgCache loadCache(String geocode, String guid) { return loadCache(geocode, guid, false, true, false, false, false, false); } + + /** + * Loads a single Cache. + * @param geocode The Geocode GCXXXX + * @param guid + * @param loadA + * @param loadW + * @param loadS + * @param loadL + * @param loadI + * @param loadO + * @return the loaded cache + */ public cgCache loadCache(String geocode, String guid, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) { Object[] geocodes = new Object[1]; @@ -1696,7 +1722,7 @@ public class cgData { guids = null; } - ArrayList caches = loadCaches(geocodes, guids, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO); + ArrayList caches = loadCaches(geocodes, null, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO); if (caches != null && caches.isEmpty() == false) { return caches.get(0); } @@ -1719,17 +1745,23 @@ public class cgData { public ArrayList loadCaches(Object[] geocodes, Object[] guids, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) { init(); + if (((geocodes != null && geocodes.length > 0) && (guids != null && guids.length > 0))) { + throw new IllegalArgumentException("Nur Entweder oder"); + } + if (((geocodes != null && geocodes.length > 0) || (guids != null && guids.length > 0)) + && centerLat != null + && centerLon != null + && spanLat != null + && spanLon != null) { + throw new IllegalArgumentException("Nur Entweder oder"); + } StringBuilder where = new StringBuilder(); Cursor cursor = null; ArrayList caches = new ArrayList(); try { if (geocodes != null) { - if (geocodes.length == 1 && false) { - where.append("geocode == \""); - where.append(geocodes[0]); - where.append("\""); - } else if (geocodes.length > 0) { + if (geocodes.length > 0) { StringBuilder all = new StringBuilder(); for (Object one : geocodes) { if (all.length() > 0) { @@ -1801,26 +1833,15 @@ public class cgData { where.append(String.format((Locale) null, "%.6f", lonMax)); where.append(")"); } - long start = System.currentTimeMillis(); cursor = databaseRO.query( dbTableCaches, - new String[]{ - "_id", "updated", "reason", "detailed", "detailedupdate", "visiteddate", "geocode", "cacheid", "guid", "type", "name", "own", "owner", "owner_real", "hidden", "hint", "size", - "difficulty", "distance", "direction", "terrain", "latlon", "latitude_string", "longitude_string", "location", "latitude", "longitude", "elevation", "shortdesc", - "description", "favourite_cnt", "rating", "votes", "myvote", "disabled", "archived", "members", "found", "favourite", "inventorycoins", "inventorytags", - "inventoryunknown", "onWatchlist", "personal_note" - }, + CACHE_COLUMNS, where.toString(), null, null, null, null, null); - long end = System.currentTimeMillis(); - if((end-start)> 100) - { - System.out.println("" + (end-start) + where); - } if (cursor != null) { int index = 0; @@ -1829,75 +1850,7 @@ public class cgData { cursor.moveToFirst(); do { - cgCache cache = new cgCache(); - - cache.updated = (long) cursor.getLong(cursor.getColumnIndex("updated")); - cache.reason = (int) cursor.getInt(cursor.getColumnIndex("reason")); - cache.detailed = cursor.getInt(cursor.getColumnIndex("detailed")) == 1; - cache.detailedUpdate = (Long) cursor.getLong(cursor.getColumnIndex("detailedupdate")); - cache.visitedDate = (Long) cursor.getLong(cursor.getColumnIndex("visiteddate")); - cache.geocode = (String) cursor.getString(cursor.getColumnIndex("geocode")); - cache.cacheid = (String) cursor.getString(cursor.getColumnIndex("cacheid")); - cache.guid = (String) cursor.getString(cursor.getColumnIndex("guid")); - cache.type = (String) cursor.getString(cursor.getColumnIndex("type")); - cache.name = (String) cursor.getString(cursor.getColumnIndex("name")); - cache.own = cursor.getInt(cursor.getColumnIndex("own")) == 1; - cache.owner = (String) cursor.getString(cursor.getColumnIndex("owner")); - cache.ownerReal = (String) cursor.getString(cursor.getColumnIndex("owner_real")); - cache.hidden = new Date((long) cursor.getLong(cursor.getColumnIndex("hidden"))); - cache.hint = (String) cursor.getString(cursor.getColumnIndex("hint")); - cache.size = (String) cursor.getString(cursor.getColumnIndex("size")); - cache.difficulty = (Float) cursor.getFloat(cursor.getColumnIndex("difficulty")); - index = cursor.getColumnIndex("direction"); - if (cursor.isNull(index)) { - cache.direction = null; - } else { - cache.direction = (Double) cursor.getDouble(index); - } - index = cursor.getColumnIndex("distance"); - if (cursor.isNull(index)) { - cache.distance = null; - } else { - cache.distance = (Double) cursor.getDouble(index); - } - cache.terrain = (Float) cursor.getFloat(cursor.getColumnIndex("terrain")); - cache.latlon = (String) cursor.getString(cursor.getColumnIndex("latlon")); - cache.latitudeString = (String) cursor.getString(cursor.getColumnIndex("latitude_string")); - cache.longitudeString = (String) cursor.getString(cursor.getColumnIndex("longitude_string")); - cache.location = (String) cursor.getString(cursor.getColumnIndex("location")); - index = cursor.getColumnIndex("latitude"); - if (cursor.isNull(index)) { - cache.latitude = null; - } else { - cache.latitude = (Double) cursor.getDouble(index); - } - index = cursor.getColumnIndex("longitude"); - if (cursor.isNull(index)) { - cache.longitude = null; - } else { - cache.longitude = (Double) cursor.getDouble(index); - } - index = cursor.getColumnIndex("elevation"); - if (cursor.isNull(index)) { - cache.elevation = null; - } else { - cache.elevation = (Double) cursor.getDouble(index); - } - cache.personalNote = (String) cursor.getString(cursor.getColumnIndex("personal_note")); - cache.shortdesc = (String) cursor.getString(cursor.getColumnIndex("shortdesc")); - cache.description = (String) cursor.getString(cursor.getColumnIndex("description")); - cache.favouriteCnt = (Integer) cursor.getInt(cursor.getColumnIndex("favourite_cnt")); - cache.rating = (Float) cursor.getFloat(cursor.getColumnIndex("rating")); - cache.votes = (Integer) cursor.getInt(cursor.getColumnIndex("votes")); - cache.myVote = (Float) cursor.getFloat(cursor.getColumnIndex("myvote")); - cache.disabled = cursor.getLong(cursor.getColumnIndex("disabled")) == 1l; - cache.archived = cursor.getLong(cursor.getColumnIndex("archived")) == 1l; - cache.members = cursor.getLong(cursor.getColumnIndex("members")) == 1l; - cache.found = cursor.getLong(cursor.getColumnIndex("found")) == 1l; - cache.favourite = cursor.getLong(cursor.getColumnIndex("favourite")) == 1l; - cache.inventoryItems = (Integer) cursor.getInt(cursor.getColumnIndex("inventoryunknown")); - cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1l; - cache.reliableLatLon = cursor.getInt(cursor.getColumnIndex("reliable_latlon"))>0; + cgCache cache = mapCache(cursor); if (loadA) { ArrayList attributes = loadAttributes(cache.geocode); @@ -1984,6 +1937,80 @@ public class cgData { return caches; } + private cgCache mapCache(Cursor cursor) { + int index; + cgCache cache = new cgCache(); + + cache.updated = (long) cursor.getLong(cursor.getColumnIndex("updated")); + cache.reason = (int) cursor.getInt(cursor.getColumnIndex("reason")); + cache.detailed = cursor.getInt(cursor.getColumnIndex("detailed")) == 1; + cache.detailedUpdate = (Long) cursor.getLong(cursor.getColumnIndex("detailedupdate")); + cache.visitedDate = (Long) cursor.getLong(cursor.getColumnIndex("visiteddate")); + cache.geocode = (String) cursor.getString(cursor.getColumnIndex("geocode")); + cache.cacheid = (String) cursor.getString(cursor.getColumnIndex("cacheid")); + cache.guid = (String) cursor.getString(cursor.getColumnIndex("guid")); + cache.type = (String) cursor.getString(cursor.getColumnIndex("type")); + cache.name = (String) cursor.getString(cursor.getColumnIndex("name")); + cache.own = cursor.getInt(cursor.getColumnIndex("own")) == 1; + cache.owner = (String) cursor.getString(cursor.getColumnIndex("owner")); + cache.ownerReal = (String) cursor.getString(cursor.getColumnIndex("owner_real")); + cache.hidden = new Date((long) cursor.getLong(cursor.getColumnIndex("hidden"))); + cache.hint = (String) cursor.getString(cursor.getColumnIndex("hint")); + cache.size = (String) cursor.getString(cursor.getColumnIndex("size")); + cache.difficulty = (Float) cursor.getFloat(cursor.getColumnIndex("difficulty")); + index = cursor.getColumnIndex("direction"); + if (cursor.isNull(index)) { + cache.direction = null; + } else { + cache.direction = (Double) cursor.getDouble(index); + } + index = cursor.getColumnIndex("distance"); + if (cursor.isNull(index)) { + cache.distance = null; + } else { + cache.distance = (Double) cursor.getDouble(index); + } + cache.terrain = (Float) cursor.getFloat(cursor.getColumnIndex("terrain")); + cache.latlon = (String) cursor.getString(cursor.getColumnIndex("latlon")); + cache.latitudeString = (String) cursor.getString(cursor.getColumnIndex("latitude_string")); + cache.longitudeString = (String) cursor.getString(cursor.getColumnIndex("longitude_string")); + cache.location = (String) cursor.getString(cursor.getColumnIndex("location")); + index = cursor.getColumnIndex("latitude"); + if (cursor.isNull(index)) { + cache.latitude = null; + } else { + cache.latitude = (Double) cursor.getDouble(index); + } + index = cursor.getColumnIndex("longitude"); + if (cursor.isNull(index)) { + cache.longitude = null; + } else { + cache.longitude = (Double) cursor.getDouble(index); + } + index = cursor.getColumnIndex("elevation"); + if (cursor.isNull(index)) { + cache.elevation = null; + } else { + cache.elevation = (Double) cursor.getDouble(index); + } + cache.personalNote = (String) cursor.getString(cursor.getColumnIndex("personal_note")); + cache.shortdesc = (String) cursor.getString(cursor.getColumnIndex("shortdesc")); + cache.description = (String) cursor.getString(cursor.getColumnIndex("description")); + cache.favouriteCnt = (Integer) cursor.getInt(cursor.getColumnIndex("favourite_cnt")); + cache.rating = (Float) cursor.getFloat(cursor.getColumnIndex("rating")); + cache.votes = (Integer) cursor.getInt(cursor.getColumnIndex("votes")); + cache.myVote = (Float) cursor.getFloat(cursor.getColumnIndex("myvote")); + cache.disabled = cursor.getLong(cursor.getColumnIndex("disabled")) == 1l; + cache.archived = cursor.getLong(cursor.getColumnIndex("archived")) == 1l; + cache.members = cursor.getLong(cursor.getColumnIndex("members")) == 1l; + cache.found = cursor.getLong(cursor.getColumnIndex("found")) == 1l; + cache.favourite = cursor.getLong(cursor.getColumnIndex("favourite")) == 1l; + cache.inventoryItems = (Integer) cursor.getInt(cursor.getColumnIndex("inventoryunknown")); + cache.onWatchlist = cursor.getLong(cursor.getColumnIndex("onWatchlist")) == 1l; + cache.reliableLatLon = cursor.getInt(cursor.getColumnIndex("reliable_latlon"))>0; + return cache; + } + public ArrayList loadAttributes(String geocode) { if (geocode == null || geocode.length() == 0) { return null; @@ -2240,6 +2267,7 @@ public class cgData { log.log = (String) cursor.getString(cursor.getColumnIndex("log")); log.date = (long) cursor.getLong(cursor.getColumnIndex("date")); log.found = (int) cursor.getInt(cursor.getColumnIndex("found")); + //TODO load Log Images in-line with join (much faster) log.logImages = loadLogImages(log.id); logs.add(log); diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index e3ac9aa..b208855 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -468,7 +468,8 @@ public class cgeoapplication extends Application { storage = new cgData(this); } - final ArrayList cachesPre = storage.loadCaches(geocodeList.toArray(), null, centerLat, centerLon, spanLat, spanLon, loadA, loadW, loadS, loadL, loadI, loadO); + // The list of geocodes is sufficient. more parameters generate an overly complex select. + final ArrayList cachesPre = storage.loadCaches(geocodeList.toArray(), null, null, null, null, null, loadA, loadW, loadS, loadL, loadI, loadO); if (cachesPre != null) { cachesOut.addAll(cachesPre); } @@ -691,14 +692,7 @@ public class cgeoapplication extends Application { cache.reason = reason; - cgCache oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true); - if (oldCache!=null) { - cgCache mergedCache = cache.merge(storage,oldCache); - storage.saveCache(mergedCache); - } else { - // cache is not saved, new data is for storing - storage.saveCache(cache); - } + boolean status = storeWithMerge(cache, false); } } @@ -721,19 +715,32 @@ public class cgeoapplication extends Application { boolean status = false; + status = storeWithMerge(cache, cache.reason >= 1); + + if (status) { + search.addGeocode(cache.geocode); + } + + return status; + } + + /** + * Checks if Cache is already in Database and if so does a merge. + * @param cache The cache to be saved + * @param forceSave override the check and persist the new state. + * @return + */ + + private boolean storeWithMerge(cgCache cache, boolean forceSave) { + boolean status; cgCache oldCache = null; - if (cache.reason >= 1 || (oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true)) !=null ) { // if for offline, do not merge + if (forceSave || (oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true)) !=null ) { // if for offline, do not merge status = storage.saveCache(cache); } else { cgCache mergedCache = cache.merge(storage,oldCache); status = storage.saveCache(mergedCache); } - - if (status) { - search.addGeocode(cache.geocode); - } - return status; } diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index 474b881..83266cf 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -760,8 +760,10 @@ public class cgeomap extends MapBase { if (followMyLocation) { myLocationInMiddle(); } else { - // move blue arrow - mapView.invalidate(); + if (mapView != null) { + // move blue arrow + mapView.invalidate(); + } } } -- cgit v1.1 From ef9b0aee12a5e5cb1a619706fa7f5a227a3d6573 Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Wed, 7 Sep 2011 07:09:50 +0200 Subject: Combined reading of logs and log images --- src/cgeo/geocaching/cgData.java | 88 +++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 239570e..99548c1 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -2246,32 +2246,40 @@ public class cgData { ArrayList logs = new ArrayList(); - Cursor cursor = databaseRO.query( - dbTableLogs, - new String[]{"_id", "type", "author", "log", "date", "found"}, - "geocode = \"" + geocode + "\"", - null, - null, - null, - "date desc, _id asc", - "100"); + Cursor cursor = databaseRO.rawQuery( + "SELECT cg_logs._id as cg_logs_id, type, author, log, date, found, " + dbTableLogImages + "._id as cg_logImages_id, log_id, title, url FROM " + + dbTableLogs + " LEFT OUTER JOIN " + dbTableLogImages + + " ON ( cg_logs._id = log_id ) WHERE geocode = ? ORDER BY date desc, cg_logs._id asc", new String[]{ geocode}); if (cursor != null && cursor.getCount() > 0) { - cursor.moveToFirst(); - - do { - cgLog log = new cgLog(); - log.id = (int) cursor.getInt(cursor.getColumnIndex("_id")); - log.type = (int) cursor.getInt(cursor.getColumnIndex("type")); - log.author = (String) cursor.getString(cursor.getColumnIndex("author")); - log.log = (String) cursor.getString(cursor.getColumnIndex("log")); - log.date = (long) cursor.getLong(cursor.getColumnIndex("date")); - log.found = (int) cursor.getInt(cursor.getColumnIndex("found")); - //TODO load Log Images in-line with join (much faster) - log.logImages = loadLogImages(log.id); - - logs.add(log); - } while (cursor.moveToNext()); + cgLog log = null; + while (cursor.moveToNext()) { + if (log == null || log.id != cursor.getInt(cursor.getColumnIndex("cg_logs_id"))) { + log = new cgLog(); + log.id = (int) cursor.getInt(cursor.getColumnIndex("cg_logs_id")); + log.type = (int) cursor.getInt(cursor.getColumnIndex("type")); + log.author = (String) cursor.getString(cursor.getColumnIndex("author")); + log.log = (String) cursor.getString(cursor.getColumnIndex("log")); + log.date = (long) cursor.getLong(cursor.getColumnIndex("date")); + log.found = (int) cursor.getInt(cursor.getColumnIndex("found")); + logs.add(log); + } + if (!cursor.isNull(cursor.getColumnIndex("cg_logImages_id"))) { + final cgImage log_img = new cgImage(); + log_img.title = (String) cursor.getString(cursor.getColumnIndex("title")); + if (log_img.title == null) { + log_img.title = ""; + } + log_img.url = (String) cursor.getString(cursor.getColumnIndex("url")); + if (log_img.url == null) { + log_img.url = ""; + } + if (log.logImages == null) { + log.logImages = new ArrayList(); + } + log.logImages.add(log_img); + } + } } if (cursor != null) { @@ -2318,38 +2326,6 @@ public class cgData { return logCounts; } - public ArrayList loadLogImages(int log_id) { - init(); - - ArrayList logImgList = new ArrayList(); - - Cursor cursor = databaseRO.query( - dbTableLogImages, - new String[]{"_id", "log_id", "title", "url"}, - "log_id = \"" + log_id + "\"", - null, - null, - null, - null, - "100"); - - if (cursor != null && cursor.getCount() > 0) { - cursor.moveToFirst(); - - do { - final cgImage log_img = new cgImage(); - log_img.title = (String)cursor.getString(cursor.getColumnIndex("title")); - log_img.url = (String)cursor.getString(cursor.getColumnIndex("url")); - logImgList.add(log_img); - } while (cursor.moveToNext()); - } - - if (cursor != null) { - cursor.close(); - } - - return logImgList; - } public ArrayList loadInventory(String geocode) { if (geocode == null || geocode.length() == 0) { -- cgit v1.1 From db63bd6960cc6023e1a73b6c54358089ef3bfc84 Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Wed, 7 Sep 2011 20:51:35 +0200 Subject: Limit to 100 --- src/cgeo/geocaching/cgData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 99548c1..16d21cb 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -2253,7 +2253,7 @@ public class cgData { if (cursor != null && cursor.getCount() > 0) { cgLog log = null; - while (cursor.moveToNext()) { + while (cursor.moveToNext() && logs.size() < 100) { if (log == null || log.id != cursor.getInt(cursor.getColumnIndex("cg_logs_id"))) { log = new cgLog(); log.id = (int) cursor.getInt(cursor.getColumnIndex("cg_logs_id")); -- cgit v1.1 From b8f828f9eeb3036771e47ecb74bb4494223a70cd Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Wed, 7 Sep 2011 21:25:39 +0200 Subject: Renamed Method and Comments --- src/cgeo/geocaching/cgData.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 16d21cb..70c7b4e 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -1744,16 +1744,16 @@ public class cgData { public ArrayList loadCaches(Object[] geocodes, Object[] guids, Long centerLat, Long centerLon, Long spanLat, Long spanLon, boolean loadA, boolean loadW, boolean loadS, boolean loadL, boolean loadI, boolean loadO) { init(); - +// Using more than one of the parametersets results in overly comlex wheres if (((geocodes != null && geocodes.length > 0) && (guids != null && guids.length > 0))) { - throw new IllegalArgumentException("Nur Entweder oder"); + throw new IllegalArgumentException("Please use only one parameter"); } if (((geocodes != null && geocodes.length > 0) || (guids != null && guids.length > 0)) && centerLat != null && centerLon != null && spanLat != null && spanLon != null) { - throw new IllegalArgumentException("Nur Entweder oder"); + throw new IllegalArgumentException("Please use only one parameter"); } StringBuilder where = new StringBuilder(); Cursor cursor = null; @@ -1844,13 +1844,12 @@ public class cgData { null); if (cursor != null) { - int index = 0; - if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - cgCache cache = mapCache(cursor); + //Extracted Method + cgCache cache = createCacheFromDatabaseContent(cursor); if (loadA) { ArrayList attributes = loadAttributes(cache.geocode); @@ -1936,8 +1935,14 @@ public class cgData { return caches; } + + /** + * maps a Cache from the cursor. Doesn't next. + * @param cursor + * @return + */ - private cgCache mapCache(Cursor cursor) { + private cgCache createCacheFromDatabaseContent(Cursor cursor) { int index; cgCache cache = new cgCache(); -- cgit v1.1 From c744be898807de15859e03e00ff0823df59b910b Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 7 Sep 2011 11:35:31 +0200 Subject: Do not try alternative pattern if primary one succeeds Also, remove useless try/catch block. --- src/cgeo/geocaching/cgBase.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index a0f1ac9..bd54ff7 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -1290,20 +1290,7 @@ public class cgBase { } // cache found - try - { - final Matcher matcherFound = patternFound.matcher(page); - final Matcher matcherFoundAlternative = patternFoundAlternative.matcher(page); - - if (matcherFound.find() || matcherFoundAlternative.find()) { - cache.found = true; - } - } - catch (Exception e) - { - // failed to parse found - Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse found"); - } + cache.found = patternFound.matcher(page).find() || patternFoundAlternative.matcher(page).find(); // cache type try { -- cgit v1.1 From f1b54a1dbe2619bab69f2cb008b12b0bb97c8789 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 8 Sep 2011 16:37:29 +0200 Subject: Remove ancient parameter from documentation --- src/cgeo/geocaching/cgBase.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index bd54ff7..d9b901e 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -5052,7 +5052,6 @@ public class cgBase { * Generate a time string according to system-wide settings (locale, 12/24 hour) * such as "13:24". * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5064,7 +5063,6 @@ public class cgBase { * Generate a date string according to system-wide settings (locale, date format) * such as "20 December" or "20 December 2010". The year will only be included when necessary. * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5077,7 +5075,6 @@ public class cgBase { * such as "20 December 2010". The year will always be included, making it suitable * to generate long-lived log entries. * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ @@ -5089,7 +5086,6 @@ public class cgBase { * Generate a numeric date string according to system-wide settings (locale, date format) * such as "10/20/2010". * - * @param context a context * @param date milliseconds since the epoch * @return the formatted string */ -- cgit v1.1 From 87ae47acb253ceffb0b4fa71f2b2b59e25021549 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 8 Sep 2011 16:37:41 +0200 Subject: Use localized date and time format for history This fixes #7 (reopened issue). --- src/cgeo/geocaching/cgBase.java | 12 ++++++++++++ src/cgeo/geocaching/cgeopoint.java | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index d9b901e..1b09bd0 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -5094,6 +5094,18 @@ public class cgBase { } /** + * Generate a numeric date and time string according to system-wide settings (locale, + * date format) such as "7 sept. à 12:35". + * + * @param context a Context + * @param date milliseconds since the epoch + * @return the formatted string + */ + public static String formatShortDateTime(Context context, long date) { + return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL); + } + + /** * TODO This method is only needed until the settings are a singleton * @return */ diff --git a/src/cgeo/geocaching/cgeopoint.java b/src/cgeo/geocaching/cgeopoint.java index dba015d..530f557 100644 --- a/src/cgeo/geocaching/cgeopoint.java +++ b/src/cgeo/geocaching/cgeopoint.java @@ -14,7 +14,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; -import android.text.format.DateFormat; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -66,9 +65,7 @@ public class cgeopoint extends AbstractActivity { longitude.setText(lonString); latitude.setText(latString); - CharSequence dateString = DateFormat.format("dd/MM/yy kk:mm", - loc.getDate()); - date.setText(dateString); + date.setText(cgBase.formatShortDateTime(getContext(), loc.getDate())); return convertView; } -- cgit v1.1 From d6337184d323b203fa17e381ee7bef4484379590 Mon Sep 17 00:00:00 2001 From: "keith.paterson" Date: Fri, 9 Sep 2011 11:37:43 +0200 Subject: Removed Performance Logging Code --- src/cgeo/geocaching/cgData.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 70c7b4e..934594b 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -41,8 +41,6 @@ public class cgData { private String path = null; private cgDbHelper dbHelper = null; // Used when Profiling and loggin SELECTS -// private SQLiteDatabasePerformanceLoggingWrapper databaseRO = null; -// private SQLiteDatabasePerformanceLoggingWrapper databaseRW = null; private SQLiteDatabase databaseRW; private SQLiteDatabase databaseRO; @@ -216,7 +214,6 @@ public class cgData { if (dbHelper == null) { dbHelper = new cgDbHelper(context); } -// databaseRW = new SQLiteDatabasePerformanceLoggingWrapper(dbHelper.getWritableDatabase()); databaseRW = dbHelper.getWritableDatabase(); if (databaseRW != null && databaseRW.isOpen()) { @@ -238,7 +235,6 @@ public class cgData { if (dbHelper == null) { dbHelper = new cgDbHelper(context); } -// databaseRO = new SQLiteDatabasePerformanceLoggingWrapper(dbHelper.getReadableDatabase()); databaseRO = dbHelper.getReadableDatabase(); if (databaseRO.needUpgrade(dbVersion)) { -- cgit v1.1