aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Keppler <michael.keppler@gmx.de>2014-04-22 11:03:23 +0200
committerMichael Keppler <michael.keppler@gmx.de>2014-04-22 11:03:23 +0200
commit0e1262604f3a06469724b334a6f6268414e91fb8 (patch)
tree63e1b22e5dc4e9f5f76d1c29deda6fd01719463f
parent8589d41a6a84c33bf0a4d6752483928aa3e5df67 (diff)
downloadcgeo-0e1262604f3a06469724b334a6f6268414e91fb8.zip
cgeo-0e1262604f3a06469724b334a6f6268414e91fb8.tar.gz
cgeo-0e1262604f3a06469724b334a6f6268414e91fb8.tar.bz2
fix #3697: have attended as log type on day of event
-rw-r--r--main/src/cgeo/geocaching/Geocache.java20
-rw-r--r--main/src/cgeo/geocaching/LogCacheActivity.java24
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java25
3 files changed, 49 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index fa25576..1ed699e 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -25,6 +25,7 @@ import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.DateUtils;
import cgeo.geocaching.utils.ImageUtils;
import cgeo.geocaching.utils.LazyInitializedList;
import cgeo.geocaching.utils.Log;
@@ -1808,4 +1809,23 @@ public class Geocache implements ICache, IWaypoint {
return (getType().applyDistanceRule() || hasUserModifiedCoords()) && getConnector() == GCConnector.getInstance();
}
+ public LogType getDefaultLogType() {
+ if (isEventCache()) {
+ final Date eventDate = getHiddenDate();
+ boolean expired = DateUtils.isPastEvent(this);
+
+ if (hasOwnLog(LogType.WILL_ATTEND) || expired || (eventDate != null && DateUtils.daysSince(eventDate.getTime()) == 0)) {
+ return hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED;
+ }
+ return LogType.WILL_ATTEND;
+ }
+ if (isFound()) {
+ return LogType.NOTE;
+ }
+ if (getType() == CacheType.WEBCAM) {
+ return LogType.WEBCAM_PHOTO_TAKEN;
+ }
+ return LogType.FOUND_IT;
+ }
+
}
diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java
index 0f65a1d..a1368cc 100644
--- a/main/src/cgeo/geocaching/LogCacheActivity.java
+++ b/main/src/cgeo/geocaching/LogCacheActivity.java
@@ -3,7 +3,6 @@ package cgeo.geocaching;
import cgeo.geocaching.connector.ILoggingManager;
import cgeo.geocaching.connector.ImageResult;
import cgeo.geocaching.connector.LogResult;
-import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.LogTypeTrackable;
@@ -341,25 +340,10 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia
private void setDefaultValues() {
date = Calendar.getInstance();
rating = GCVote.NO_RATING;
- if (cache.isEventCache()) {
- final Date eventDate = cache.getHiddenDate();
- boolean expired = DateUtils.isPastEvent(cache);
-
- if (cache.hasOwnLog(LogType.WILL_ATTEND) || expired) {
- typeSelected = cache.hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED;
- } else {
- typeSelected = LogType.WILL_ATTEND;
- }
- // it this is an attended event log, use the event date by default instead of the current date
- if (expired && typeSelected == LogType.ATTENDED) {
- date.setTime(eventDate);
- }
- } else {
- if (cache.isFound()) {
- typeSelected = LogType.NOTE;
- } else {
- typeSelected = cache.getType() == CacheType.WEBCAM ? LogType.WEBCAM_PHOTO_TAKEN : LogType.FOUND_IT;
- }
+ typeSelected = cache.getDefaultLogType();
+ // it this is an attended event log, use the event date by default instead of the current date
+ if (cache.isEventCache() && DateUtils.isPastEvent(cache) && typeSelected == LogType.ATTENDED) {
+ date.setTime(cache.getHiddenDate());
}
text = null;
imageCaption = StringUtils.EMPTY;
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index b49048b..020cf6c 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -9,6 +9,7 @@ import cgeo.geocaching.list.StoredList;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -285,4 +286,28 @@ public class GeocacheTest extends CGeoTestCase {
assertFalse("A traditional cache cannot have a webcam log", ocCache.getPossibleLogTypes().contains(LogType.WEBCAM_PHOTO_TAKEN));
assertFalse("OC caches have no maintenance log type", ocCache.getPossibleLogTypes().contains(LogType.NEEDS_MAINTENANCE));
}
+
+ public static void testLogTypeEventPast() throws Exception {
+ Calendar today = Calendar.getInstance();
+ today.add(Calendar.DAY_OF_MONTH, -1);
+ assertEquals(LogType.ATTENDED, createEventCache(today).getDefaultLogType());
+ }
+
+ public static void testLogTypeEventToday() throws Exception {
+ Calendar today = Calendar.getInstance();
+ assertEquals(LogType.ATTENDED, createEventCache(today).getDefaultLogType());
+ }
+
+ public static void testLogTypeEventFuture() throws Exception {
+ Calendar today = Calendar.getInstance();
+ today.add(Calendar.DAY_OF_MONTH, 1);
+ assertEquals(LogType.WILL_ATTEND, createEventCache(today).getDefaultLogType());
+ }
+
+ private static Geocache createEventCache(Calendar calendar) {
+ Geocache cache = new Geocache();
+ cache.setType(CacheType.EVENT);
+ cache.setHidden(calendar.getTime());
+ return cache;
+ }
}