aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java88
1 files changed, 42 insertions, 46 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 5d299d4..8dde37d 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -33,13 +33,16 @@ import cgeo.geocaching.utils.MatcherWrapper;
import cgeo.geocaching.utils.UncertainProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
+import rx.Scheduler;
+import rx.Scheduler.Inner;
+import rx.Subscription;
+import rx.functions.Action1;
import android.app.Activity;
import android.content.Intent;
@@ -164,7 +167,7 @@ public class Geocache implements ICache, IWaypoint {
*
* @param gpxParser
*/
- public Geocache(GPXParser gpxParser) {
+ public Geocache(@SuppressWarnings("unused") GPXParser gpxParser) {
setReliableLatLon(true);
setAttributes(Collections.<String> emptyList());
setWaypoints(Collections.<Waypoint> emptyList(), false);
@@ -369,6 +372,7 @@ public class Geocache implements ICache, IWaypoint {
* the other cache to compare this one to
* @return true if both caches have the same content
*/
+ @SuppressWarnings("deprecation")
@SuppressFBWarnings("FE_FLOATING_POINT_EQUALITY")
private boolean isEqualTo(final Geocache other) {
return detailed == other.detailed &&
@@ -437,22 +441,6 @@ public class Geocache implements ICache, IWaypoint {
return hidden.compareTo(cal.getTime()) >= 0;
}
- /**
- * Checks if a page contains the guid of a cache
- *
- * @param page
- * the page to search in, may be null
- * @return true if the page contains the guid of the cache, false otherwise
- */
- public boolean isGuidContainedInPage(final String page) {
- if (StringUtils.isBlank(page) || StringUtils.isBlank(guid)) {
- return false;
- }
- final Boolean found = Pattern.compile(guid, Pattern.CASE_INSENSITIVE).matcher(page).find();
- Log.i("Geocache.isGuidContainedInPage: guid '" + guid + "' " + (found ? "" : "not ") + "found");
- return found;
- }
-
public boolean isEventCache() {
return cacheType.getValue().isEvent();
}
@@ -816,13 +804,7 @@ public class Geocache implements ICache, IWaypoint {
}
public boolean showSize() {
- if (size == CacheSize.NOT_CHOSEN) {
- return false;
- }
- if (isEventCache() || isVirtual()) {
- return false;
- }
- return true;
+ return !(size == CacheSize.NOT_CHOSEN || isEventCache() || isVirtual());
}
public long getUpdated() {
@@ -1372,17 +1354,6 @@ public class Geocache implements ICache, IWaypoint {
}
/**
- * Retrieve a given waypoint.
- *
- * @param index
- * the index of the waypoint
- * @return waypoint or <code>null</code> if index is out of range
- */
- public Waypoint getWaypoint(final int index) {
- return index >= 0 && index < waypoints.size() ? waypoints.get(index) : null;
- }
-
- /**
* Lookup a waypoint by its id.
*
* @param id
@@ -1474,15 +1445,23 @@ public class Geocache implements ICache, IWaypoint {
return "cache";
}
- public void drop(Handler handler) {
- try {
- DataStore.markDropped(Collections.singletonList(this));
- DataStore.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ public Subscription drop(final Handler handler, final Scheduler scheduler) {
+ return scheduler.schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ try {
+ dropSynchronous();
+ handler.sendMessage(Message.obtain());
+ } catch (final Exception e) {
+ Log.e("cache.drop: ", e);
+ }
+ }
+ });
+ }
- handler.sendMessage(Message.obtain());
- } catch (final Exception e) {
- Log.e("cache.drop: ", e);
- }
+ public void dropSynchronous() {
+ DataStore.markDropped(Collections.singletonList(this));
+ DataStore.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
}
public void checkFields() {
@@ -1527,7 +1506,17 @@ public class Geocache implements ICache, IWaypoint {
}
}
- public void refresh(int newListId, CancellableHandler handler) {
+ public Subscription refresh(final int newListId, final CancellableHandler handler, final Scheduler scheduler) {
+ return scheduler.schedule(new Action1<Inner>() {
+ @Override
+ public void call(final Inner inner) {
+ refreshSynchronous(newListId, handler);
+ handler.sendEmptyMessage(CancellableHandler.DONE);
+ }
+ });
+ }
+
+ public void refreshSynchronous(final int newListId, final CancellableHandler handler) {
DataStore.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
storeCache(null, geocode, newListId, true, handler);
}
@@ -1612,6 +1601,8 @@ public class Geocache implements ICache, IWaypoint {
StaticMapsProvider.downloadMaps(cache);
+ imgGetter.waitForBackgroundLoading(handler);
+
if (handler != null) {
handler.sendMessage(Message.obtain());
}
@@ -1671,8 +1662,9 @@ public class Geocache implements ICache, IWaypoint {
patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE));
}
+ final String searchText = getShortDescription() + ' ' + getDescription();
for (Pattern pattern : patterns) {
- final MatcherWrapper matcher = new MatcherWrapper(pattern, getDescription());
+ final MatcherWrapper matcher = new MatcherWrapper(pattern, searchText);
while (matcher.find()) {
try {
final int hours = Integer.parseInt(matcher.group(1));
@@ -1783,4 +1775,8 @@ public class Geocache implements ICache, IWaypoint {
return 0;
}
+ public boolean applyDistanceRule() {
+ return (getType().applyDistanceRule() || hasUserModifiedCoords()) && getConnector() == GCConnector.getInstance();
+ }
+
}