aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2013-01-23 12:13:47 +0100
committerSamuel Tardieu <sam@rfc1149.net>2013-01-23 13:12:28 +0100
commit66aa9e5341c73819eb3c0e53330d4e8144f268e2 (patch)
treeccd0ba514d61f7ed53e6f128d7c8a5b456555e5b /main/src
parent2253e295e5a6fc1fb40c5dfaed1ce8e00c1e8088 (diff)
downloadcgeo-66aa9e5341c73819eb3c0e53330d4e8144f268e2.zip
cgeo-66aa9e5341c73819eb3c0e53330d4e8144f268e2.tar.gz
cgeo-66aa9e5341c73819eb3c0e53330d4e8144f268e2.tar.bz2
fix #2322: GPX imported caches not marked as owned
The "isOwner()" property (previously named "isOwn()") is now synthesized by comparing the username with the cache owner name.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java6
-rw-r--r--main/src/cgeo/geocaching/ICache.java2
-rw-r--r--main/src/cgeo/geocaching/SearchResult.java2
-rw-r--r--main/src/cgeo/geocaching/cgCache.java19
-rw-r--r--main/src/cgeo/geocaching/cgData.java10
-rw-r--r--main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java6
-rw-r--r--main/src/cgeo/geocaching/connector/GeopeitusConnector.java6
-rw-r--r--main/src/cgeo/geocaching/connector/IConnector.java8
-rw-r--r--main/src/cgeo/geocaching/connector/UnknownConnector.java6
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCConnector.java8
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java5
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OCConnector.java6
-rw-r--r--main/src/cgeo/geocaching/connector/ox/OXConnector.java6
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java6
15 files changed, 65 insertions, 33 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index ff01ab3..67a9544 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -1728,7 +1728,7 @@ public class CacheDetailActivity extends AbstractActivity {
Button buttonRemove = (Button) view.findViewById(R.id.remove_from_watchlist);
TextView text = (TextView) view.findViewById(R.id.watchlist_text);
- if (cache.isOnWatchlist() || cache.isOwn()) {
+ if (cache.isOnWatchlist() || cache.isOwner()) {
buttonAdd.setVisibility(View.GONE);
buttonRemove.setVisibility(View.VISIBLE);
text.setText(R.string.cache_watchlist_on);
@@ -1739,7 +1739,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
// the owner of a cache has it always on his watchlist. Adding causes an error
- if (cache.isOwn()) {
+ if (cache.isOwner()) {
buttonAdd.setEnabled(false);
buttonAdd.setVisibility(View.GONE);
buttonRemove.setEnabled(false);
@@ -1755,7 +1755,7 @@ public class CacheDetailActivity extends AbstractActivity {
LinearLayout layout = (LinearLayout) view.findViewById(R.id.favpoint_box);
boolean supportsFavoritePoints = cache.supportsFavoritePoints();
layout.setVisibility(supportsFavoritePoints ? View.VISIBLE : View.GONE);
- if (!supportsFavoritePoints || cache.isOwn() || !Settings.isPremiumMember()) {
+ if (!supportsFavoritePoints || cache.isOwner() || !Settings.isPremiumMember()) {
return;
}
Button buttonAdd = (Button) view.findViewById(R.id.add_to_favpoint);
diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java
index 8f8baf9..9870534 100644
--- a/main/src/cgeo/geocaching/ICache.java
+++ b/main/src/cgeo/geocaching/ICache.java
@@ -28,7 +28,7 @@ public interface ICache extends IBasicCache {
/**
* @return true if the user is the owner of the cache, false else
*/
- public boolean isOwn();
+ public boolean isOwner();
/**
* @return true is the cache is archived, false else
diff --git a/main/src/cgeo/geocaching/SearchResult.java b/main/src/cgeo/geocaching/SearchResult.java
index e21717d..ec558de 100644
--- a/main/src/cgeo/geocaching/SearchResult.java
+++ b/main/src/cgeo/geocaching/SearchResult.java
@@ -175,7 +175,7 @@ public class SearchResult implements Parcelable {
for (cgCache cache : caches) {
// Is there any reason to exclude the cache from the list?
final boolean excludeCache = (excludeDisabled && cache.isDisabled()) ||
- (excludeMine && (cache.isOwn() || cache.isFound())) ||
+ (excludeMine && (cache.isOwner() || cache.isFound())) ||
(cacheType != CacheType.ALL && cacheType != cache.getType());
if (!excludeCache) {
result.addCache(cache);
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 7035d65..cec482f 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -46,6 +46,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@@ -89,7 +90,6 @@ public class cgCache implements ICache, IWaypoint {
private boolean premiumMembersOnly = false;
private boolean found = false;
private boolean favorite = false;
- private boolean own = false;
private int favoritePoints = 0;
private float rating = 0; // valid ratings are larger than zero
private int votes = 0;
@@ -188,7 +188,6 @@ public class cgCache implements ICache, IWaypoint {
reliableLatLon = other.reliableLatLon;
archived = other.archived;
found = other.found;
- own = other.own;
disabled = other.disabled;
favorite = other.favorite;
onWatchlist = other.onWatchlist;
@@ -350,7 +349,6 @@ public class cgCache implements ICache, IWaypoint {
cacheType == other.cacheType &&
size == other.size &&
found == other.found &&
- own == other.own &&
premiumMembersOnly == other.premiumMembersOnly &&
difficulty == other.difficulty &&
terrain == other.terrain &&
@@ -473,14 +471,13 @@ public class cgCache implements ICache, IWaypoint {
}
public List<LogType> getPossibleLogTypes() {
- boolean isOwner = getOwnerUserId() != null && getOwnerUserId().equalsIgnoreCase(Settings.getUsername());
- List<LogType> logTypes = new ArrayList<LogType>();
+ final List<LogType> logTypes = new LinkedList<LogType>();
if (isEventCache()) {
logTypes.add(LogType.WILL_ATTEND);
logTypes.add(LogType.NOTE);
logTypes.add(LogType.ATTENDED);
logTypes.add(LogType.NEEDS_ARCHIVE);
- if (isOwner) {
+ if (isOwner()) {
logTypes.add(LogType.ANNOUNCEMENT);
}
} else if (CacheType.WEBCAM == cacheType) {
@@ -496,7 +493,7 @@ public class cgCache implements ICache, IWaypoint {
logTypes.add(LogType.NEEDS_ARCHIVE);
logTypes.add(LogType.NEEDS_MAINTENANCE);
}
- if (isOwner) {
+ if (isOwner()) {
logTypes.add(LogType.OWNER_MAINTENANCE);
logTypes.add(LogType.TEMP_DISABLE_LISTING);
logTypes.add(LogType.ENABLE_LISTING);
@@ -586,8 +583,8 @@ public class cgCache implements ICache, IWaypoint {
}
@Override
- public boolean isOwn() {
- return own;
+ public boolean isOwner() {
+ return getConnector().isOwner(this);
}
@Override
@@ -1079,10 +1076,6 @@ public class cgCache implements ICache, IWaypoint {
this.found = found;
}
- public void setOwn(boolean own) {
- this.own = own;
- }
-
public void setAttributes(List<String> attributes) {
this.attributes.set(attributes);
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index b080f7c..b81bbed 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -56,7 +56,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",
+ "_id", "updated", "reason", "detailed", "detailedupdate", "visiteddate", "geocode", "cacheid", "guid", "type", "name", "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", "finalDefined"
@@ -101,7 +101,7 @@ public class cgData {
+ "guid text, "
+ "type text, "
+ "name text, "
- + "own integer not null default 0, "
+ + "own integer not null default 0, " // TODO: remove this column during the next database upgrade
+ "owner text, "
+ "owner_real text, "
+ "hidden long, "
@@ -1028,7 +1028,6 @@ public class cgData {
values.put("guid", cache.getGuid());
values.put("type", cache.getType().id);
values.put("name", cache.getName());
- values.put("own", cache.isOwn() ? 1 : 0);
values.put("owner", cache.getOwnerDisplayName());
values.put("owner_real", cache.getOwnerUserId());
if (cache.getHiddenDate() == null) {
@@ -1618,7 +1617,7 @@ public class cgData {
local_cci[7] = cursor.getColumnIndex("guid");
local_cci[8] = cursor.getColumnIndex("type");
local_cci[9] = cursor.getColumnIndex("name");
- local_cci[10] = cursor.getColumnIndex("own");
+ // TODO: entry number 10 has been removed, all should be renumbered
local_cci[11] = cursor.getColumnIndex("owner");
local_cci[12] = cursor.getColumnIndex("owner_real");
local_cci[13] = cursor.getColumnIndex("hidden");
@@ -1662,7 +1661,6 @@ public class cgData {
cache.setGuid(cursor.getString(cacheColumnIndex[7]));
cache.setType(CacheType.getById(cursor.getString(cacheColumnIndex[8])));
cache.setName(cursor.getString(cacheColumnIndex[9]));
- cache.setOwn(cursor.getInt(cacheColumnIndex[10]) == 1);
cache.setOwnerDisplayName(cursor.getString(cacheColumnIndex[11]));
cache.setOwnerUserId(cursor.getString(cacheColumnIndex[12]));
long dateValue = cursor.getLong(cacheColumnIndex[13]);
@@ -2964,7 +2962,7 @@ public class cgData {
public Set<cgWaypoint> loadWaypoints(final Viewport viewport, boolean excludeMine, boolean excludeDisabled, CacheType type) {
final StringBuilder where = new StringBuilder(buildCoordinateWhere(dbTableWaypoints, viewport));
if (excludeMine) {
- where.append(" and ").append(dbTableCaches).append(".own == 0 and ").append(dbTableCaches).append(".found == 0");
+ where.append(" and ").append(dbTableCaches).append(".found == 0");
}
if (excludeDisabled) {
where.append(" and ").append(dbTableCaches).append(".disabled == 0");
diff --git a/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java b/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java
index 30d1a4b..15113da 100644
--- a/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java
+++ b/main/src/cgeo/geocaching/connector/GeocachingAustraliaConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.cgCache;
import org.apache.commons.lang3.StringUtils;
@@ -22,6 +23,11 @@ public class GeocachingAustraliaConnector extends AbstractConnector {
}
@Override
+ public boolean isOwner(final ICache cache) {
+ return false;
+ }
+
+ @Override
public boolean canHandle(final String geocode) {
return (StringUtils.startsWithIgnoreCase(geocode, "GA") || StringUtils.startsWithIgnoreCase(geocode, "TP")) && isNumericId(geocode.substring(2));
}
diff --git a/main/src/cgeo/geocaching/connector/GeopeitusConnector.java b/main/src/cgeo/geocaching/connector/GeopeitusConnector.java
index 6ef91db..c20b8f8 100644
--- a/main/src/cgeo/geocaching/connector/GeopeitusConnector.java
+++ b/main/src/cgeo/geocaching/connector/GeopeitusConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.cgCache;
import org.apache.commons.lang3.StringUtils;
@@ -22,6 +23,11 @@ public class GeopeitusConnector extends AbstractConnector {
}
@Override
+ public boolean isOwner(final ICache cache) {
+ return false;
+ }
+
+ @Override
public boolean canHandle(String geocode) {
return StringUtils.startsWith(geocode, "GE") && isNumericId(geocode.substring(2));
}
diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java
index d6ac2ff..371e5ed 100644
--- a/main/src/cgeo/geocaching/connector/IConnector.java
+++ b/main/src/cgeo/geocaching/connector/IConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.geopoint.Viewport;
@@ -112,4 +113,11 @@ public interface IConnector {
*/
public String getGeocodeFromUrl(final String url);
+ /**
+ * Check if the current user is the owner of the given cache.
+ *
+ * @param cache a cache that this connector must be able to handle
+ * @return <code>true</code> if the current user is the cache owner, <code>false</code> otherwise
+ */
+ public boolean isOwner(final ICache cache);
}
diff --git a/main/src/cgeo/geocaching/connector/UnknownConnector.java b/main/src/cgeo/geocaching/connector/UnknownConnector.java
index 991d31c..3edd8a6 100644
--- a/main/src/cgeo/geocaching/connector/UnknownConnector.java
+++ b/main/src/cgeo/geocaching/connector/UnknownConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.cgCache;
import org.apache.commons.lang3.StringUtils;
@@ -22,6 +23,11 @@ public class UnknownConnector extends AbstractConnector {
}
@Override
+ public boolean isOwner(final ICache cache) {
+ return false;
+ }
+
+ @Override
public boolean canHandle(final String geocode) {
return StringUtils.isNotBlank(geocode);
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
index 197d4e6..a81a4f4 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java
@@ -1,7 +1,9 @@
package cgeo.geocaching.connector.gc;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.connector.AbstractConnector;
@@ -126,6 +128,12 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode,
return cacheHasReliableLatLon;
}
+ @Override
+ public boolean isOwner(final ICache cache) {
+ return StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), Settings.getUsername());
+
+ }
+
public static boolean addToWatchlist(cgCache cache) {
final boolean added = GCParser.addToWatchlist(cache);
if (added) {
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index 681a1d7..7c7c683 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -205,7 +205,7 @@ public class GCMap {
cache.setType(CacheType.UNKNOWN);
}
boolean exclude = false;
- if (Settings.isExcludeMyCaches() && (cache.isFound() || cache.isOwn())) { // workaround for BM
+ if (Settings.isExcludeMyCaches() && (cache.isFound() || cache.isOwner())) { // workaround for BM
exclude = true;
}
if (Settings.isExcludeDisabledCaches() && cache.isDisabled()) {
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 158a201..04d93f0 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -202,9 +202,6 @@ public abstract class GCParser {
// found it
cache.setFound(row.contains("/images/icons/16/found.png"));
- // own it
- cache.setOwn(row.contains("/images/icons/16/placed.png"));
-
// id
String result = BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_ID, null);
if (null != result) {
@@ -385,8 +382,6 @@ public abstract class GCParser {
// owner real name
cache.setOwnerUserId(URLDecoder.decode(BaseUtils.getMatch(page, GCConstants.PATTERN_OWNER_USERID, true, cache.getOwnerUserId())));
- cache.setOwn(StringUtils.equalsIgnoreCase(cache.getOwnerUserId(), Settings.getUsername()));
-
String tableInside = page;
int pos = tableInside.indexOf(GCConstants.STRING_CACHEDETAILS);
diff --git a/main/src/cgeo/geocaching/connector/oc/OCConnector.java b/main/src/cgeo/geocaching/connector/oc/OCConnector.java
index c098d12..87d307f 100644
--- a/main/src/cgeo/geocaching/connector/oc/OCConnector.java
+++ b/main/src/cgeo/geocaching/connector/oc/OCConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector.oc;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.connector.AbstractConnector;
@@ -47,6 +48,11 @@ public class OCConnector extends AbstractConnector {
}
@Override
+ public boolean isOwner(final ICache cache) {
+ return false;
+ }
+
+ @Override
protected String getCacheUrlPrefix() {
return "http://" + host + "/viewcache.php?wp=";
}
diff --git a/main/src/cgeo/geocaching/connector/ox/OXConnector.java b/main/src/cgeo/geocaching/connector/ox/OXConnector.java
index 98b1656..17d8ab4 100644
--- a/main/src/cgeo/geocaching/connector/ox/OXConnector.java
+++ b/main/src/cgeo/geocaching/connector/ox/OXConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector.ox;
+import cgeo.geocaching.ICache;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
@@ -47,6 +48,11 @@ public class OXConnector extends AbstractConnector implements ISearchByCenter, I
}
@Override
+ public boolean isOwner(final ICache cache) {
+ return false;
+ }
+
+ @Override
public SearchResult searchByGeocode(String geocode, String guid, CancellableHandler handler) {
final cgCache cache = OpenCachingApi.searchByGeoCode(geocode);
if (cache == null) {
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index e48ca70..dcb225f 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -1151,7 +1151,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final List<cgCache> tempList = caches.getAsList();
for (cgCache cache : tempList) {
- if ((cache.isFound() && excludeMine) || (cache.isOwn() && excludeMine) || (cache.isDisabled() && excludeDisabled)) {
+ if ((cache.isFound() && excludeMine) || (cache.isOwner() && excludeMine) || (cache.isDisabled() && excludeDisabled)) {
caches.remove(cache);
}
}
@@ -1640,7 +1640,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
.append(cache.isReliableLatLon())
.append(cache.getType().id)
.append(cache.isDisabled() || cache.isArchived())
- .append(cache.isOwn())
+ .append(cache.isOwner())
.append(cache.isFound())
.append(cache.hasUserModifiedCoords())
.append(cache.getPersonalNote())
@@ -1671,7 +1671,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
layers.add(getResources().getDrawable(cache.getType().markerId));
insets.add(INSET_TYPE[resolution]);
// own
- if (cache.isOwn()) {
+ if (cache.isOwner()) {
layers.add(getResources().getDrawable(R.drawable.marker_own));
insets.add(INSET_OWN[resolution]);
// if not, checked if stored