diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-28 16:17:44 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-28 16:17:44 +0200 |
| commit | 742831d726d2065eafeec94172d0c3a0faccf47a (patch) | |
| tree | bb34477c5df7ec1d8ae87caddeac17fbb5a5656b /main | |
| parent | b7b78d477c13ca2bdacdfbe8ccfb5e573f0536f8 (diff) | |
| download | cgeo-742831d726d2065eafeec94172d0c3a0faccf47a.zip cgeo-742831d726d2065eafeec94172d0c3a0faccf47a.tar.gz cgeo-742831d726d2065eafeec94172d0c3a0faccf47a.tar.bz2 | |
Remove latitudeString and longitudeString fields
Those fields can be resynthesized if needed from the cache coordinates.
Diffstat (limited to 'main')
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 134 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgWaypoint.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeodetail.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeowaypointadd.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/FileParser.java | 3 |
8 files changed, 108 insertions, 65 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index f44023d..0d2f2c7 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -1282,8 +1282,6 @@ public class cgBase { Map<String, Object> tmp = cgBase.parseLatlon(cache.latlon); if (tmp.size() > 0) { cache.coords = new Geopoint((Double) tmp.get("latitude"), (Double) tmp.get("longitude")); - cache.latitudeString = (String) tmp.get("latitudeString"); - cache.longitudeString = (String) tmp.get("longitudeString"); cache.reliableLatLon = true; } tmp = null; @@ -1601,8 +1599,6 @@ public class cgBase { final Map<String, Object> tmp = cgBase.parseLatlon(waypoint.latlon); if (tmp.size() > 0) { waypoint.coords = new Geopoint((Double) tmp.get("latitude"), (Double) tmp.get("longitude")); - waypoint.latitudeString = (String) tmp.get("latitudeString"); - waypoint.longitudeString = (String) tmp.get("longitudeString"); } } } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 0b82da9..c821e28 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -53,8 +53,6 @@ public class cgCache implements ICache { public Float direction = null; public Float distance = null; public String latlon = ""; - public String latitudeString = ""; - public String longitudeString = ""; public String location = ""; public Geopoint coords = null; public boolean reliableLatLon = false; @@ -157,12 +155,6 @@ public class cgCache implements ICache { if (StringUtils.isBlank(latlon)) { latlon = other.latlon; } - if (StringUtils.isBlank(latitudeString)) { - latitudeString = other.latitudeString; - } - if (StringUtils.isBlank(longitudeString)) { - longitudeString = other.longitudeString; - } if (StringUtils.isBlank(location)) { location = other.location; } @@ -387,12 +379,12 @@ public class cgCache implements ICache { @Override public String getLatitude() { - return latitudeString; + return coords != null ? cgBase.formatLatitude(coords.getLatitude(), true) : null; } @Override public String getLongitude() { - return longitudeString; + return coords != null ? cgBase.formatLongitude(coords.getLongitude(), true) : null; } @Override diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index f51d276..afd1c4e 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -41,7 +41,7 @@ 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", + "difficulty", "distance", "direction", "terrain", "latlon", "location", "latitude", "longitude", "elevation", "shortdesc", "description", "favourite_cnt", "rating", "votes", "myvote", "disabled", "archived", "members", "found", "favourite", "inventorycoins", "inventorytags", "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon" }; @@ -51,7 +51,7 @@ public class cgData { private cgDbHelper dbHelper = null; private SQLiteDatabase databaseRO = null; private SQLiteDatabase databaseRW = null; - private static final int dbVersion = 57; + private static final int dbVersion = 58; private static final String dbName = "data"; private static final String dbTableCaches = "cg_caches"; private static final String dbTableLists = "cg_lists"; @@ -86,8 +86,6 @@ public class cgData { + "difficulty float, " + "terrain float, " + "latlon text, " - + "latitude_string text, " - + "longitude_string text, " + "location text, " + "direction double, " + "distance double, " @@ -141,8 +139,6 @@ public class cgData { + "lookup text, " + "name text, " + "latlon text, " - + "latitude_string text, " - + "longitude_string text, " + "latitude double, " + "longitude double, " + "note text " @@ -474,6 +470,10 @@ public class cgData { db.execSQL(dbCreateTrackables); db.execSQL(dbCreateSearchDestinationHistory); + createIndices(db); + } + + static private void createIndices(final SQLiteDatabase db) { db.execSQL("create index if not exists in_caches_geo on " + dbTableCaches + " (geocode)"); db.execSQL("create index if not exists in_caches_guid on " + dbTableCaches + " (guid)"); db.execSQL("create index if not exists in_caches_reason on " + dbTableCaches + " (reason)"); @@ -835,24 +835,104 @@ public class cgData { db.execSQL("drop index in_d"); db.execSQL("drop index in_e"); db.execSQL("drop index in_f"); - db.execSQL("create index if not exists in_caches_geo on " + dbTableCaches + " (geocode)"); - db.execSQL("create index if not exists in_caches_guid on " + dbTableCaches + " (guid)"); - db.execSQL("create index if not exists in_caches_reason on " + dbTableCaches + " (reason)"); - db.execSQL("create index if not exists in_caches_detailed on " + dbTableCaches + " (detailed)"); - db.execSQL("create index if not exists in_caches_type on " + dbTableCaches + " (type)"); - db.execSQL("create index if not exists in_caches_visit_detail on " + dbTableCaches + " (visiteddate, detailedupdate)"); - db.execSQL("create index if not exists in_attr_geo on " + dbTableAttributes + " (geocode)"); - db.execSQL("create index if not exists in_wpts_geo on " + dbTableWaypoints + " (geocode)"); - db.execSQL("create index if not exists in_wpts_geo_type on " + dbTableWaypoints + " (geocode, type)"); - db.execSQL("create index if not exists in_spoil_geo on " + dbTableSpoilers + " (geocode)"); - db.execSQL("create index if not exists in_logs_geo on " + dbTableLogs + " (geocode)"); - db.execSQL("create index if not exists in_logcount_geo on " + dbTableLogCount + " (geocode)"); - db.execSQL("create index if not exists in_logsoff_geo on " + dbTableLogsOffline + " (geocode)"); - db.execSQL("create index if not exists in_trck_geo on " + dbTableTrackables + " (geocode)"); + createIndices(db); } catch (Exception e) { Log.e(cgSettings.tag, "Failed to upgrade to ver. 57: " + e.toString()); } } + + if (oldVersion < 58) { // upgrade to 58 + try { + db.beginTransaction(); + + final String dbTableCachesTemp = dbTableCaches + "_temp"; + final String dbCreateCachesTemp = "" + + "create table " + dbTableCachesTemp + " (" + + "_id integer primary key autoincrement, " + + "updated long not null, " + + "detailed integer not null default 0, " + + "detailedupdate long, " + + "visiteddate long, " + + "geocode text unique not null, " + + "reason integer not null default 0, " + + "cacheid text, " + + "guid text, " + + "type text, " + + "name text, " + + "own integer not null default 0, " + + "owner text, " + + "owner_real text, " + + "hidden long, " + + "hint text, " + + "size text, " + + "difficulty float, " + + "terrain float, " + + "latlon text, " + + "location text, " + + "direction double, " + + "distance double, " + + "latitude double, " + + "longitude double, " + + "reliable_latlon integer, " + + "elevation double, " + + "personal_note text, " + + "shortdesc text, " + + "description text, " + + "favourite_cnt integer, " + + "rating float, " + + "votes integer, " + + "myvote float, " + + "disabled integer not null default 0, " + + "archived integer not null default 0, " + + "members integer not null default 0, " + + "found integer not null default 0, " + + "favourite integer not null default 0, " + + "inventorycoins integer default 0, " + + "inventorytags integer default 0, " + + "inventoryunknown integer default 0, " + + "onWatchlist integer default 0 " + + "); "; + + db.execSQL(dbCreateCachesTemp); + db.execSQL("insert into " + dbTableCachesTemp + " select _id,updated,detailed,detailedupdate,visiteddate,geocode,reason,cacheid,guid,type,name,own,owner,owner_real," + + "hidden,hint,size,difficulty,terrain,latlon,location,direction,distance,latitude,longitude,reliable_latlon,elevation," + + "personal_note,shortdesc,description,favourite_cnt,rating,votes,myvote,disabled,archived,members,found,favourite,inventorycoins," + + "inventorytags,inventoryunknown,onWatchlist from " + dbTableCaches); + db.execSQL("drop table " + dbTableCaches); + db.execSQL("alter table " + dbTableCachesTemp + " rename to " + dbTableCaches); + + final String dbTableWaypointsTemp = dbTableWaypoints + "_temp"; + final String dbCreateWaypointsTemp = "" + + "create table " + dbTableWaypointsTemp + " (" + + "_id integer primary key autoincrement, " + + "geocode text not null, " + + "updated long not null, " // date of save + + "type text not null default 'waypoint', " + + "prefix text, " + + "lookup text, " + + "name text, " + + "latlon text, " + + "latitude double, " + + "longitude double, " + + "note text " + + "); "; + db.execSQL(dbCreateWaypointsTemp); + db.execSQL("insert into " + dbTableWaypointsTemp + " select _id, geocode, updated, type, prefix, lookup, name, latlon, latitude, longitude, note from " + dbTableWaypoints); + db.execSQL("drop table " + dbTableWaypoints); + db.execSQL("alter table " + dbTableWaypointsTemp + " rename to " + dbTableWaypoints); + + createIndices(db); + + db.setTransactionSuccessful(); + + Log.i(cgSettings.tag, "Removed latitude_string and longitude_string columns"); + } catch (Exception e) { + Log.e(cgSettings.tag, "Failed to upgrade to ver. 58: " + e.toString()); + } finally { + db.endTransaction(); + } + } + } db.setTransactionSuccessful(); @@ -1174,8 +1254,6 @@ public class cgData { values.put("difficulty", cache.difficulty); values.put("terrain", cache.terrain); values.put("latlon", cache.latlon); - values.put("latitude_string", cache.latitudeString); - values.put("longitude_string", cache.longitudeString); values.put("location", cache.location); values.put("distance", cache.distance); values.put("direction", cache.direction); @@ -1369,8 +1447,6 @@ public class cgData { values.put("lookup", oneWaypoint.lookup); values.put("name", oneWaypoint.name); values.put("latlon", oneWaypoint.latlon); - values.put("latitude_string", oneWaypoint.latitudeString); - values.put("longitude_string", oneWaypoint.longitudeString); putCoords(values, oneWaypoint.coords); values.put("note", oneWaypoint.note); @@ -1457,8 +1533,6 @@ public class cgData { values.put("lookup", waypoint.lookup); values.put("name", waypoint.name); values.put("latlon", waypoint.latlon); - values.put("latitude_string", waypoint.latitudeString); - values.put("longitude_string", waypoint.longitudeString); putCoords(values, waypoint.coords); values.put("note", waypoint.note); @@ -2023,8 +2097,6 @@ public class cgData { } 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")); cache.coords = getCoords(cursor); index = cursor.getColumnIndex("elevation"); @@ -2097,7 +2169,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude_string", "longitude_string", "latitude", "longitude", "note" }, + new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note" }, "_id = " + id, null, null, @@ -2129,7 +2201,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude_string", "longitude_string", "latitude", "longitude", "note" }, + new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note" }, "geocode = \"" + geocode + "\"", null, null, @@ -2164,8 +2236,6 @@ public class cgData { waypoint.lookup = (String) cursor.getString(cursor.getColumnIndex("lookup")); waypoint.name = (String) cursor.getString(cursor.getColumnIndex("name")); waypoint.latlon = (String) cursor.getString(cursor.getColumnIndex("latlon")); - waypoint.latitudeString = (String) cursor.getString(cursor.getColumnIndex("latitude_string")); - waypoint.longitudeString = (String) cursor.getString(cursor.getColumnIndex("longitude_string")); waypoint.coords = getCoords(cursor); waypoint.note = (String) cursor.getString(cursor.getColumnIndex("note")); diff --git a/main/src/cgeo/geocaching/cgWaypoint.java b/main/src/cgeo/geocaching/cgWaypoint.java index b57f8ce..6fc59d7 100644 --- a/main/src/cgeo/geocaching/cgWaypoint.java +++ b/main/src/cgeo/geocaching/cgWaypoint.java @@ -17,8 +17,6 @@ public class cgWaypoint implements Comparable<cgWaypoint> { public String lookup = ""; public String name = ""; public String latlon = ""; - public String latitudeString = ""; - public String longitudeString = ""; public Geopoint coords = null; public String note = ""; private Integer cachedOrder = null; @@ -47,12 +45,6 @@ public class cgWaypoint implements Comparable<cgWaypoint> { if (StringUtils.isBlank(latlon) || latlon.startsWith("?")) { // there are waypoints containing "???" latlon = old.latlon; } - if (StringUtils.isBlank(latitudeString)) { - latitudeString = old.latitudeString; - } - if (StringUtils.isBlank(longitudeString)) { - longitudeString = old.longitudeString; - } if (coords == null) { coords = old.coords; } diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java index 3f05c82..1df6994 100644 --- a/main/src/cgeo/geocaching/cgeodetail.java +++ b/main/src/cgeo/geocaching/cgeodetail.java @@ -834,7 +834,7 @@ public class cgeodetail extends AbstractActivity { itemValue = (TextView) itemLayout.findViewById(R.id.value); itemName.setText(res.getString(R.string.cache_coordinates)); - itemValue.setText(cache.latitudeString + " | " + cache.longitudeString); + itemValue.setText(cache.getLatitude() + " | " + cache.getLongitude()); detailsList.addView(itemLayout); } @@ -1525,8 +1525,8 @@ public class cgeodetail extends AbstractActivity { event.put("title", Html.fromHtml(cache.name).toString()); event.put("description", description.toString()); String location = ""; - if (StringUtils.isNotBlank(cache.latitudeString) && StringUtils.isNotBlank(cache.longitudeString)) { - location += cache.latitudeString + " " + cache.longitudeString; + if (cache.coords != null) { + location += cache.getLatitude() + " " + cache.getLongitude(); } if (StringUtils.isNotBlank(cache.location)) { boolean addParenteses = false; diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java index 0ffaa2b..e53ae0a 100644 --- a/main/src/cgeo/geocaching/cgeowaypointadd.java +++ b/main/src/cgeo/geocaching/cgeowaypointadd.java @@ -335,8 +335,6 @@ public class cgeowaypointadd extends AbstractActivity { waypoint.lookup = lookup; waypoint.name = name; waypoint.coords = new Geopoint(coords.get(0), coords.get(1)); - waypoint.latitudeString = cgBase.formatLatitude(coords.get(0), true); - waypoint.longitudeString = cgBase.formatLongitude(coords.get(1), true); waypoint.note = note; if (app.saveOwnWaypoint(id, geocode, waypoint)) { diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index fffbc20..bd0ddac 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -201,10 +201,8 @@ final public class OkapiClient { private static void setLocation(final cgCache cache, final String location) { final String latitude = StringUtils.substringBefore(location, "|"); final String longitude = StringUtils.substringAfter(location, "|"); - // FIXME: the next lines should be a setter at cgCache + // FIXME: the next line should be a setter at cgCache cache.coords = GeopointParser.parse(latitude, longitude); - cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true); - cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true); } private static CacheSize getCacheSize(final JSONObject response) { diff --git a/main/src/cgeo/geocaching/files/FileParser.java b/main/src/cgeo/geocaching/files/FileParser.java index c92b6d2..7785363 100644 --- a/main/src/cgeo/geocaching/files/FileParser.java +++ b/main/src/cgeo/geocaching/files/FileParser.java @@ -1,6 +1,5 @@ package cgeo.geocaching.files; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import android.os.Handler; @@ -38,8 +37,6 @@ public abstract class FileParser { } protected static void fixCache(cgCache cache) { - cache.latitudeString = cgBase.formatLatitude(cache.coords.getLatitude(), true); - cache.longitudeString = cgBase.formatLongitude(cache.coords.getLongitude(), true); if (cache.inventory != null) { cache.inventoryItems = cache.inventory.size(); } else { |
