diff options
| -rw-r--r-- | main/res/layout/waypoint_new.xml | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 49 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 36 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgWaypoint.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeowaypointadd.java | 57 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/enumerations/WaypointType.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheListAdapter.java | 2 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgWaypointTest.java | 12 |
11 files changed, 154 insertions, 26 deletions
diff --git a/main/res/layout/waypoint_new.xml b/main/res/layout/waypoint_new.xml index dcd172c..0b3fdc8 100644 --- a/main/res/layout/waypoint_new.xml +++ b/main/res/layout/waypoint_new.xml @@ -60,6 +60,11 @@ android:id="@+id/name" style="@style/edittext" android:hint="@string/waypoint_name" /> + + <Spinner + android:id="@+id/type" + android:layout_width="fill_parent" + android:layout_height="wrap_content" /> <EditText android:id="@+id/note" diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index c833317..7c3f80f 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -1088,7 +1088,7 @@ public class cgBase { if (null != originalCoords) { // res is null during the unit tests - final cgWaypoint waypoint = new cgWaypoint(res != null ? res.getString(R.string.cache_coordinates_original) : "res = null", WaypointType.WAYPOINT); + final cgWaypoint waypoint = new cgWaypoint(res != null ? res.getString(R.string.cache_coordinates_original) : "res = null", WaypointType.WAYPOINT, false); waypoint.setCoords(new Geopoint(originalCoords)); cache.addWaypoint(waypoint); cache.setUserModifiedCoords(true); @@ -1138,7 +1138,7 @@ public class cgBase { // waypoint type final String resulttype = BaseUtils.getMatch(wp[3], GCConstants.PATTERN_WPTYPE, null); - final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.findById(resulttype)); + final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.findById(resulttype), false); // waypoint prefix waypoint.setPrefix(BaseUtils.getMatch(wp[4], GCConstants.PATTERN_WPPREFIXORLOOKUPORLATLON, true, 2, waypoint.getPrefix(), false)); diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 8b4e6ef..eafc908 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -97,6 +97,7 @@ public class cgCache implements ICache { private String directionImg = ""; private String nameForSorting; private final EnumSet<StorageLocation> storageLocation = EnumSet.of(StorageLocation.HEAP); + private boolean finalDefined = false; private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+"); @@ -123,6 +124,7 @@ public class cgCache implements ICache { favorite = other.favorite; onWatchlist = other.onWatchlist; logOffline = other.logOffline; + finalDefined = other.finalDefined; } /* @@ -312,7 +314,8 @@ public class cgCache implements ICache { logs == other.logs && inventory == other.inventory && logCounts == other.logCounts && - logOffline == other.logOffline) { + logOffline == other.logOffline && + finalDefined == other.finalDefined) { return true; } return false; @@ -889,9 +892,13 @@ public class cgCache implements ICache { public void setWaypoints(List<cgWaypoint> waypoints) { this.waypoints = waypoints; + finalDefined = false; if (waypoints != null) { for (cgWaypoint waypoint : waypoints) { waypoint.setGeocode(geocode); + if (isFinalWithCoords(waypoint)) { + finalDefined = true; + } } } } @@ -1094,12 +1101,41 @@ public class cgCache implements ICache { } waypoints.add(waypoint); waypoint.setGeocode(geocode); + if (isFinalWithCoords(waypoint)) { + finalDefined = true; + } } public boolean hasWaypoints() { return CollectionUtils.isNotEmpty(waypoints); } + public boolean hasFinalDefined() { + return finalDefined; + } + + // Only for loading + public void setFinalDefined(boolean finalDefined) { + this.finalDefined = finalDefined; + } + + /** + * Checks whether a given waypoint is a final and has coordinates + * + * @param waypoint + * Waypoint to check + * @return True - waypoint is final and has coordinates, False - otherwise + */ + private static boolean isFinalWithCoords(cgWaypoint waypoint) { + if (null != waypoint.getWaypointType() && WaypointType.FINAL == waypoint.getWaypointType()) { + if (null != waypoint.getCoords()) { + return true; + } + } + + return false; + } + public boolean hasUserModifiedCoords() { return userModifiedCoords; } @@ -1148,6 +1184,15 @@ public class cgCache implements ICache { waypoints.remove(index); cgeoapplication.getInstance().deleteWaypoint(waypoint.getId()); cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVECACHE)); + // Check status if Final is defined + if (isFinalWithCoords(waypoint)) { + finalDefined = false; + for (cgWaypoint wp : waypoints) { + if (isFinalWithCoords(wp)) { + finalDefined = true; + } + } + } return true; } return false; @@ -1192,7 +1237,7 @@ public class cgCache implements ICache { // coords must have non zero latitude and longitude and at least one part shall have fractional degrees if (point != null && point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0)) { final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count; - final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.WAYPOINT); + final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.WAYPOINT, false); waypoint.setCoords(point); addWaypoint(waypoint); count++; diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 17ed58e..7e63fb8 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -54,7 +54,7 @@ public class cgData { "_id", "updated", "reason", "detailed", "detailedupdate", "visiteddate", "geocode", "cacheid", "guid", "type", "name", "own", "owner", "owner_real", "hidden", "hint", "size", "difficulty", "distance", "direction", "terrain", "latlon", "location", "latitude", "longitude", "elevation", "shortdesc", "favourite_cnt", "rating", "votes", "myvote", "disabled", "archived", "members", "found", "favourite", "inventorycoins", "inventorytags", - "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon", "coordsChanged" + "inventoryunknown", "onWatchlist", "personal_note", "reliable_latlon", "coordsChanged", "finalDefined" // reason is replaced by listId in cgCache }; /** @@ -67,7 +67,7 @@ public class cgData { private cgDbHelper dbHelper = null; private SQLiteDatabase databaseRO = null; private SQLiteDatabase databaseRW = null; - private static final int dbVersion = 61; + private static final int dbVersion = 62; private static final String dbName = "data"; private static final String dbTableCaches = "cg_caches"; private static final String dbTableLists = "cg_lists"; @@ -125,7 +125,8 @@ public class cgData { + "inventorytags integer default 0, " + "inventoryunknown integer default 0, " + "onWatchlist integer default 0, " - + "coordsChanged integer default 0" + + "coordsChanged integer default 0, " + + "finalDefined integer default 0" + "); "; private static final String dbCreateLists = "" + "create table " + dbTableLists + " (" @@ -158,7 +159,8 @@ public class cgData { + "latlon text, " + "latitude double, " + "longitude double, " - + "note text " + + "note text, " + + "own integer default 0" + "); "; private static final String dbCreateSpoilers = "" + "create table " + dbTableSpoilers + " (" @@ -921,7 +923,17 @@ public class cgData { } } + // Introduces finalDefined on caches and own on waypoints + if (oldVersion < 62) { + try { + db.execSQL("alter table " + dbTableCaches + " add column finalDefined integer default 0"); + db.execSQL("alter table " + dbTableWaypoints + " add column own integer default 0"); + db.execSQL("update " + dbTableWaypoints + " set own = 1 where type = 'own'"); + } catch (Exception e) { + Log.e(Settings.tag, "Failed to upgrade to ver. 62: " + e.toString()); + } + } } db.setTransactionSuccessful(); @@ -1300,6 +1312,7 @@ public class cgData { values.put("inventoryunknown", cache.getInventoryItems()); values.put("onWatchlist", cache.isOnWatchlist() ? 1 : 0); values.put("coordsChanged", cache.hasUserModifiedCoords() ? 1 : 0); + values.put("finalDefined", cache.hasFinalDefined() ? 1 : 0); boolean statusOk = true; @@ -1451,7 +1464,7 @@ public class cgData { databaseRW.beginTransaction(); try { if (drop) { - databaseRW.delete(dbTableWaypoints, "geocode = ? and type <> ?", new String[] { geocode, "own" }); + databaseRW.delete(dbTableWaypoints, "geocode = ? and type <> ? and own = 0", new String[] { geocode, "own" }); } if (!waypoints.isEmpty()) { @@ -1472,6 +1485,7 @@ public class cgData { values.put("latlon", oneWaypoint.getLatlon()); putCoords(values, oneWaypoint.getCoords()); values.put("note", oneWaypoint.getNote()); + values.put("own", oneWaypoint.isUserDefined() ? 1 : 0); final long rowId = databaseRW.insert(dbTableWaypoints, null, values); oneWaypoint.setId((int) rowId); @@ -1539,6 +1553,7 @@ public class cgData { values.put("latlon", waypoint.getLatlon()); putCoords(values, waypoint.getCoords()); values.put("note", waypoint.getNote()); + values.put("own", waypoint.isUserDefined() ? 1 : 0); if (id <= 0) { final long rowId = databaseRW.insert(dbTableWaypoints, null, values); @@ -2017,7 +2032,7 @@ public class cgData { cgCache cache = new cgCache(); if (cacheColumnIndex == null) { - int[] local_cci = new int[40]; // use a local variable to avoid having the not yet fully initialized array be visible to other threads + int[] local_cci = new int[41]; // use a local variable to avoid having the not yet fully initialized array be visible to other threads local_cci[0] = cursor.getColumnIndex("updated"); local_cci[1] = cursor.getColumnIndex("reason"); local_cci[2] = cursor.getColumnIndex("detailed"); @@ -2058,6 +2073,7 @@ public class cgData { local_cci[37] = cursor.getColumnIndex("coordsChanged"); local_cci[38] = cursor.getColumnIndex("latitude"); local_cci[39] = cursor.getColumnIndex("longitude"); + local_cci[40] = cursor.getColumnIndex("finalDefined"); cacheColumnIndex = local_cci; } @@ -2119,6 +2135,7 @@ public class cgData { cache.setOnWatchlist(cursor.getInt(cacheColumnIndex[35]) == 1); cache.setReliableLatLon(cursor.getInt(cacheColumnIndex[36]) > 0); cache.setUserModifiedCoords(cursor.getInt(cacheColumnIndex[37]) > 0); + cache.setFinalDefined(cursor.getInt(cacheColumnIndex[40]) > 0); Log.d(Settings.tag, "Loading " + cache.toString() + " (" + cache.getListId() + ") from DB"); @@ -2171,7 +2188,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note" }, + new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }, "_id = ?", new String[] { Integer.toString(id) }, null, @@ -2205,7 +2222,7 @@ public class cgData { Cursor cursor = databaseRO.query( dbTableWaypoints, - new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note" }, + new String[] { "_id", "geocode", "updated", "type", "prefix", "lookup", "name", "latlon", "latitude", "longitude", "note", "own" }, "geocode = ?", new String[] { geocode }, null, @@ -2234,7 +2251,8 @@ public class cgData { private static cgWaypoint createWaypointFromDatabaseContent(Cursor cursor) { String name = cursor.getString(cursor.getColumnIndex("name")); WaypointType type = WaypointType.findById(cursor.getString(cursor.getColumnIndex("type"))); - cgWaypoint waypoint = new cgWaypoint(name, type); + boolean own = cursor.getInt(cursor.getColumnIndex("own")) != 0; + cgWaypoint waypoint = new cgWaypoint(name, type, own); waypoint.setId(cursor.getInt(cursor.getColumnIndex("_id"))); waypoint.setGeocode(cursor.getString(cursor.getColumnIndex("geocode"))); diff --git a/main/src/cgeo/geocaching/cgWaypoint.java b/main/src/cgeo/geocaching/cgWaypoint.java index c3e2d2b..bdc2fe4 100644 --- a/main/src/cgeo/geocaching/cgWaypoint.java +++ b/main/src/cgeo/geocaching/cgWaypoint.java @@ -24,6 +24,7 @@ public class cgWaypoint implements IWaypoint, Comparable<cgWaypoint> { private Geopoint coords = null; private String note = ""; private int cachedOrder = ORDER_UNDEFINED; + private boolean own = false; /** * require name and type for every waypoint @@ -31,9 +32,10 @@ public class cgWaypoint implements IWaypoint, Comparable<cgWaypoint> { * @param name * @param type */ - public cgWaypoint(final String name, final WaypointType type) { + public cgWaypoint(final String name, final WaypointType type, final boolean own) { this.name = name; this.waypointType = type; + this.own = own; } /** @@ -104,11 +106,11 @@ public class cgWaypoint implements IWaypoint, Comparable<cgWaypoint> { } public boolean isUserDefined() { - return waypointType == WaypointType.OWN; + return own || WaypointType.OWN == waypointType; } public void setUserDefined() { - waypointType = WaypointType.OWN; + own = true; setPrefix(PREFIX_OWN); } diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java index fd5ba91..5eac0bf 100644 --- a/main/src/cgeo/geocaching/cgeowaypointadd.java +++ b/main/src/cgeo/geocaching/cgeowaypointadd.java @@ -18,10 +18,13 @@ import android.os.Message; import android.text.Html; import android.util.Log; import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; +import android.widget.Spinner; import java.util.ArrayList; import java.util.List; @@ -37,6 +40,9 @@ public class cgeowaypointadd extends AbstractActivity { private WaypointType type = WaypointType.OWN; private String prefix = "OWN"; private String lookup = "---"; + private boolean own = true; + ArrayList<WaypointType> wpTypes = null; + /** * number of waypoints that the corresponding cache has until now */ @@ -58,6 +64,7 @@ public class cgeowaypointadd extends AbstractActivity { type = waypoint.getWaypointType(); prefix = waypoint.getPrefix(); lookup = waypoint.getLookup(); + own = waypoint.isUserDefined(); app.setAction(geocode); @@ -73,6 +80,10 @@ public class cgeowaypointadd extends AbstractActivity { waitDialog = null; } } + + if (own) { + initializeWaypointTypeSelector(); + } } catch (Exception e) { if (waitDialog != null) { waitDialog.dismiss(); @@ -134,10 +145,15 @@ public class cgeowaypointadd extends AbstractActivity { textView.setAdapter(adapter); if (id > 0) { + Spinner waypointTypeSelector = (Spinner) findViewById(R.id.type); + waypointTypeSelector.setVisibility(View.GONE); + waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true); waitDialog.setCancelable(true); (new loadWaypoint()).start(); + } else { + initializeWaypointTypeSelector(); } disableSuggestions((EditText) findViewById(R.id.distance)); @@ -189,6 +205,21 @@ public class cgeowaypointadd extends AbstractActivity { super.onPause(); } + private void initializeWaypointTypeSelector() { + + Spinner waypointTypeSelector = (Spinner) findViewById(R.id.type); + + wpTypes = new ArrayList<WaypointType>(WaypointType.ALL_TYPES_EXCEPT_OWN.keySet()); + ArrayAdapter<WaypointType> wpAdapter = new ArrayAdapter<WaypointType>(this, android.R.layout.simple_spinner_item, wpTypes.toArray(new WaypointType[] {})); + wpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + waypointTypeSelector.setAdapter(wpAdapter); + + waypointTypeSelector.setSelection(wpTypes.indexOf(type)); + waypointTypeSelector.setOnItemSelectedListener(new changeWaypointType(this)); + + waypointTypeSelector.setVisibility(View.VISIBLE); + } + private class update implements UpdateLocationCallback { @Override @@ -247,6 +278,30 @@ public class cgeowaypointadd extends AbstractActivity { } } + private class changeWaypointType implements OnItemSelectedListener { + + private changeWaypointType(cgeowaypointadd wpView) { + this.wpView = wpView; + } + + private cgeowaypointadd wpView; + + @Override + public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, + long arg3) { + if (null != wpView.wpTypes) { + wpView.type = wpView.wpTypes.get(arg2); + } + } + + @Override + public void onNothingSelected(AdapterView<?> arg0) { + if (null != wpView.wpTypes) { + arg0.setSelection(wpView.wpTypes.indexOf(wpView.type)); + } + } + } + private class coordsListener implements View.OnClickListener { public void onClick(View arg0) { @@ -313,7 +368,7 @@ public class cgeowaypointadd extends AbstractActivity { } final String note = ((EditText) findViewById(R.id.note)).getText().toString().trim(); - final cgWaypoint waypoint = new cgWaypoint(name, type); + final cgWaypoint waypoint = new cgWaypoint(name, type, own); waypoint.setGeocode(geocode); waypoint.setPrefix(prefix); waypoint.setLookup(lookup); diff --git a/main/src/cgeo/geocaching/enumerations/WaypointType.java b/main/src/cgeo/geocaching/enumerations/WaypointType.java index d5b1333..551ee19 100644 --- a/main/src/cgeo/geocaching/enumerations/WaypointType.java +++ b/main/src/cgeo/geocaching/enumerations/WaypointType.java @@ -76,4 +76,7 @@ public enum WaypointType { } } + public final String toString() { + return getL10n(); + } } diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 79e790c..081a28a 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -307,7 +307,7 @@ public abstract class GPXParser extends FileParser { // lookup cache for waypoint in already parsed caches final cgCache cacheForWaypoint = result.get(cacheGeocodeForWaypoint); if (cacheForWaypoint != null) { - final cgWaypoint waypoint = new cgWaypoint(cache.getShortdesc(), convertWaypointSym2Type(sym)); + final cgWaypoint waypoint = new cgWaypoint(cache.getShortdesc(), convertWaypointSym2Type(sym), false); waypoint.setId(-1); waypoint.setGeocode(cacheGeocodeForWaypoint); waypoint.setPrefix(cache.getName().substring(0, 2)); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 893ca8d..8132bfd 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1510,7 +1510,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory coord.setCoords(coordsIntent); coord.setName("some place"); - final cgWaypoint waypoint = new cgWaypoint("some place", waypointTypeIntent != null ? waypointTypeIntent : WaypointType.WAYPOINT); + final cgWaypoint waypoint = new cgWaypoint("some place", waypointTypeIntent != null ? waypointTypeIntent : WaypointType.WAYPOINT, false); final CachesOverlayItemImpl item = getItem(coord, null, waypoint); overlayCaches.updateItems(item); diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 77544fb..9ff3eb3 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -481,7 +481,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { holder.text.setText(cache.getNameSp(), TextView.BufferType.SPANNABLE); int hashCode = new HashCodeBuilder() - .append(cache.getType()).append(cache.hasUserModifiedCoords()).toHashCode(); + .append(cache.getType()).append(cache.hasUserModifiedCoords() || cache.hasFinalDefined()).toHashCode(); if (gcIconDrawables.containsKey(hashCode)) { // cache icon holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(hashCode), null, null, null); } else { // unknown cache type, "mystery" icon diff --git a/tests/src/cgeo/geocaching/cgWaypointTest.java b/tests/src/cgeo/geocaching/cgWaypointTest.java index 54ebb02..324d562 100644 --- a/tests/src/cgeo/geocaching/cgWaypointTest.java +++ b/tests/src/cgeo/geocaching/cgWaypointTest.java @@ -7,12 +7,12 @@ import android.test.AndroidTestCase; public class cgWaypointTest extends AndroidTestCase { public static void testOrder() { - final cgWaypoint cache = new cgWaypoint("Final", WaypointType.FINAL); - final cgWaypoint trailhead = new cgWaypoint("Trail head", WaypointType.TRAILHEAD); - final cgWaypoint stage = new cgWaypoint("stage", WaypointType.STAGE); - final cgWaypoint puzzle = new cgWaypoint("puzzle", WaypointType.PUZZLE); - final cgWaypoint own = new cgWaypoint("own", WaypointType.OWN); - final cgWaypoint parking = new cgWaypoint("parking", WaypointType.PARKING); + final cgWaypoint cache = new cgWaypoint("Final", WaypointType.FINAL, false); + final cgWaypoint trailhead = new cgWaypoint("Trail head", WaypointType.TRAILHEAD, false); + final cgWaypoint stage = new cgWaypoint("stage", WaypointType.STAGE, false); + final cgWaypoint puzzle = new cgWaypoint("puzzle", WaypointType.PUZZLE, false); + final cgWaypoint own = new cgWaypoint("own", WaypointType.OWN, true); + final cgWaypoint parking = new cgWaypoint("parking", WaypointType.PARKING, false); assertTrue(trailhead.compareTo(puzzle) < 0); assertTrue(trailhead.compareTo(stage) < 0); |
