aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgCache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/cgCache.java')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java103
1 files changed, 36 insertions, 67 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 7035d65..6978bfa 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -38,7 +38,6 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
-import android.text.Spannable;
import java.util.ArrayList;
import java.util.Calendar;
@@ -66,7 +65,6 @@ public class cgCache implements ICache, IWaypoint {
private String guid = "";
private CacheType cacheType = CacheType.UNKNOWN;
private String name = "";
- private Spannable nameSp = null;
private String ownerDisplayName = "";
private String ownerUserId = "";
private Date hidden = null;
@@ -99,20 +97,20 @@ public class cgCache implements ICache, IWaypoint {
private LazyInitializedList<String> attributes = new LazyInitializedList<String>() {
@Override
protected List<String> loadFromDatabase() {
- return cgeoapplication.getInstance().loadAttributes(geocode);
+ return cgData.loadAttributes(geocode);
}
};
private LazyInitializedList<cgWaypoint> waypoints = new LazyInitializedList<cgWaypoint>() {
@Override
protected List<cgWaypoint> loadFromDatabase() {
- return cgeoapplication.getInstance().loadWaypoints(geocode);
+ return cgData.loadWaypoints(geocode);
}
};
private List<cgImage> spoilers = null;
private LazyInitializedList<LogEntry> logs = new LazyInitializedList<LogEntry>() {
@Override
protected List<LogEntry> loadFromDatabase() {
- return cgeoapplication.getInstance().loadLogs(geocode);
+ return cgData.loadLogs(geocode);
}
};
private List<cgTrackable> inventory = null;
@@ -227,9 +225,6 @@ public class cgCache implements ICache, IWaypoint {
if (StringUtils.isBlank(name)) {
name = other.name;
}
- if (StringUtils.isBlank(nameSp)) {
- nameSp = other.nameSp;
- }
if (StringUtils.isBlank(ownerDisplayName)) {
ownerDisplayName = other.ownerDisplayName;
}
@@ -294,12 +289,12 @@ public class cgCache implements ICache, IWaypoint {
attributes.set(other.attributes);
}
if (waypoints.isEmpty()) {
- waypoints.set(other.waypoints);
+ this.setWaypoints(other.waypoints.asList(), false);
}
else {
ArrayList<cgWaypoint> newPoints = new ArrayList<cgWaypoint>(waypoints.asList());
- cgWaypoint.mergeWayPoints(newPoints, other.getWaypoints(), false);
- waypoints.set(newPoints);
+ cgWaypoint.mergeWayPoints(newPoints, other.waypoints.asList(), false);
+ this.setWaypoints(newPoints, false);
}
if (spoilers == null) {
spoilers = other.spoilers;
@@ -376,7 +371,6 @@ public class cgCache implements ICache, IWaypoint {
(direction != null ? direction.equals(other.direction) : null == other.direction) &&
(distance != null ? distance.equals(other.distance) : null == other.distance) &&
(elevation != null ? elevation.equals(other.elevation) : null == other.elevation) &&
- nameSp == other.nameSp &&
rating == other.rating &&
votes == other.votes &&
myVote == other.myVote &&
@@ -441,7 +435,7 @@ public class cgCache implements ICache, IWaypoint {
}
Intent logVisitIntent = new Intent((Activity) fromActivity, VisitCacheActivity.class);
logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_ID, cacheId);
- logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_GEOCODE, geocode.toUpperCase());
+ logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_GEOCODE, geocode);
logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_FOUND, found);
((Activity) fromActivity).startActivity(logVisitIntent);
@@ -457,13 +451,12 @@ public class cgCache implements ICache, IWaypoint {
if (logType == LogType.UNKNOWN) {
return;
}
- cgeoapplication app = (cgeoapplication) fromActivity.getApplication();
- final boolean status = app.saveLogOffline(geocode, date.getTime(), logType, log);
+ final boolean status = cgData.saveLogOffline(geocode, date.getTime(), logType, log);
Resources res = fromActivity.getResources();
if (status) {
ActivityMixin.showToast(fromActivity, res.getString(R.string.info_log_saved));
- app.saveVisitDate(geocode);
+ cgData.saveVisitDate(geocode);
logOffline = true;
notifyChange();
@@ -603,7 +596,7 @@ public class cgCache implements ICache, IWaypoint {
@Override
public String getDescription() {
if (description == null) {
- description = StringUtils.defaultString(cgeoapplication.getInstance().getCacheDescription(geocode));
+ description = StringUtils.defaultString(cgData.getCacheDescription(geocode));
}
return description;
}
@@ -661,7 +654,7 @@ public class cgCache implements ICache, IWaypoint {
}
StringBuilder subject = new StringBuilder("Geocache ");
- subject.append(geocode.toUpperCase());
+ subject.append(geocode);
if (StringUtils.isNotBlank(name)) {
subject.append(" - ").append(name);
}
@@ -809,14 +802,6 @@ public class cgCache implements ICache, IWaypoint {
this.detailed = detailed;
}
- public Spannable getNameSp() {
- return nameSp;
- }
-
- public void setNameSp(Spannable nameSp) {
- this.nameSp = nameSp;
- }
-
public void setHidden(final Date hidden) {
if (hidden == null) {
this.hidden = null;
@@ -958,8 +943,7 @@ public class cgCache implements ICache, IWaypoint {
}
}
}
-
- return saveToDatabase && cgeoapplication.getInstance().saveWaypoints(this);
+ return saveToDatabase && cgData.saveWaypoints(this);
}
/**
@@ -1015,7 +999,7 @@ public class cgCache implements ICache, IWaypoint {
}
public void setGeocode(String geocode) {
- this.geocode = geocode;
+ this.geocode = StringUtils.upperCase(geocode);
}
public void setCacheId(String cacheId) {
@@ -1166,8 +1150,7 @@ public class cgCache implements ICache, IWaypoint {
// when waypoint was edited, finalDefined may have changed
resetFinalDefined();
}
-
- return saveToDatabase && cgeoapplication.getInstance().saveWaypoint(waypoint.getId(), geocode, waypoint);
+ return saveToDatabase && cgData.saveWaypoint(waypoint.getId(), geocode, waypoint);
}
public boolean hasWaypoints() {
@@ -1206,38 +1189,42 @@ public class cgCache implements ICache, IWaypoint {
/**
* Duplicate a waypoint.
- *
- * @param index the waypoint to duplicate
+ *
+ * @param original
+ * the waypoint to duplicate
* @return <code>true</code> if the waypoint was duplicated, <code>false</code> otherwise (invalid index)
*/
- public boolean duplicateWaypoint(final int index) {
- final cgWaypoint original = getWaypoint(index);
+ public boolean duplicateWaypoint(final cgWaypoint original) {
if (original == null) {
return false;
}
+ final int index = getWaypointIndex(original);
final cgWaypoint copy = new cgWaypoint(original);
copy.setUserDefined();
copy.setName(cgeoapplication.getInstance().getString(R.string.waypoint_copy_of) + " " + copy.getName());
waypoints.add(index + 1, copy);
- return cgeoapplication.getInstance().saveWaypoint(-1, geocode, copy);
+ return cgData.saveWaypoint(-1, geocode, copy);
}
/**
* delete a user defined waypoint
*
- * @param index
- * of the waypoint in cache's waypoint list
+ * @param waypoint
+ * to be removed from cache
* @return <code>true</code>, if the waypoint was deleted
*/
- public boolean deleteWaypoint(final int index) {
- final cgWaypoint waypoint = getWaypoint(index);
+ public boolean deleteWaypoint(final cgWaypoint waypoint) {
if (waypoint == null) {
return false;
}
+ if (waypoint.getId() <= 0) {
+ return false;
+ }
if (waypoint.isUserDefined()) {
+ final int index = getWaypointIndex(waypoint);
waypoints.remove(index);
- cgeoapplication.getInstance().deleteWaypoint(waypoint.getId());
- cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ cgData.deleteWaypoint(waypoint.getId());
+ cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
// Check status if Final is defined
if (waypoint.isFinalWithCoords()) {
resetFinalDefined();
@@ -1248,22 +1235,6 @@ public class cgCache implements ICache, IWaypoint {
}
/**
- * delete a user defined waypoint
- *
- * @param waypoint
- * to be removed from cache
- * @return <code>true</code>, if the waypoint was deleted
- */
- public boolean deleteWaypoint(final cgWaypoint waypoint) {
- if (waypoint.getId() <= 0) {
- return false;
- }
-
- final int index = getWaypointIndex(waypoint);
- return index >= 0 && deleteWaypoint(index);
- }
-
- /**
* Find index of given <code>waypoint</code> in cache's <code>waypoints</code> list
*
* @param waypoint
@@ -1391,8 +1362,8 @@ public class cgCache implements ICache, IWaypoint {
public void drop(Handler handler) {
try {
- cgeoapplication.getInstance().markDropped(Collections.singletonList(this));
- cgeoapplication.getInstance().removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ cgData.markDropped(Collections.singletonList(this));
+ cgData.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
handler.sendMessage(Message.obtain());
} catch (Exception e) {
@@ -1443,7 +1414,7 @@ public class cgCache implements ICache, IWaypoint {
}
public void refresh(int newListId, CancellableHandler handler) {
- cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
storeCache(null, geocode, newListId, true, handler);
}
@@ -1516,7 +1487,7 @@ public class cgCache implements ICache, IWaypoint {
}
cache.setListId(listId);
- cgeoapplication.getInstance().saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
if (CancellableHandler.isCancelled(handler)) {
return;
@@ -1538,10 +1509,9 @@ public class cgCache implements ICache, IWaypoint {
return null;
}
- final cgeoapplication app = cgeoapplication.getInstance();
- if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (app.isOffline(geocode, guid) || app.isThere(geocode, guid, true, true))) {
+ if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (cgData.isOffline(geocode, guid) || cgData.isThere(geocode, guid, true, true))) {
final SearchResult search = new SearchResult();
- final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : app.getGeocode(guid);
+ final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : cgData.getGeocodeForGuid(guid);
search.addGeocode(realGeocode);
return search;
}
@@ -1613,8 +1583,7 @@ public class cgCache implements ICache, IWaypoint {
* @return
*/
public boolean hasAttribute(CacheAttribute attribute, boolean yes) {
- // lazy loading of attributes
- cgCache fullCache = cgeoapplication.getInstance().loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
+ cgCache fullCache = cgData.loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
if (fullCache == null) {
fullCache = this;
}