aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/values/changelog_master.xml1
-rw-r--r--main/src/cgeo/calendar/CalendarAddon.java3
-rw-r--r--main/src/cgeo/geocaching/Geocache.java9
-rw-r--r--main/src/cgeo/geocaching/sorting/DateComparator.java16
-rw-r--r--main/src/cgeo/geocaching/sorting/EventDateComparator.java17
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java6
6 files changed, 37 insertions, 15 deletions
diff --git a/main/res/values/changelog_master.xml b/main/res/values/changelog_master.xml
index 200e50c..ca0ac4e 100644
--- a/main/res/values/changelog_master.xml
+++ b/main/res/values/changelog_master.xml
@@ -4,6 +4,7 @@
<string name="changelog_master" translatable="false">
<b>Next feature release:</b>\n
· New: confirmation on backup/restore\n
+ · New: sort events of same date by time (if recognized from cache description)\n
\n
</string>
</resources>
diff --git a/main/src/cgeo/calendar/CalendarAddon.java b/main/src/cgeo/calendar/CalendarAddon.java
index c5bb0a6..cce6bf7 100644
--- a/main/src/cgeo/calendar/CalendarAddon.java
+++ b/main/src/cgeo/calendar/CalendarAddon.java
@@ -32,6 +32,7 @@ public class CalendarAddon {
final Resources res = activity.getResources();
if (CalendarAddon.isAvailable()) {
final Date hiddenDate = cache.getHiddenDate();
+ final String startTime = cache.guessEventTimeMinutes() >= 0 ? String.valueOf(cache.guessEventTimeMinutes()) : StringUtils.EMPTY;
final Parameters params = new Parameters(
ICalendar.PARAM_NAME, cache.getName(),
ICalendar.PARAM_NOTE, StringUtils.defaultString(cache.getPersonalNote()),
@@ -40,7 +41,7 @@ public class CalendarAddon {
ICalendar.PARAM_COORDS, cache.getCoords() == null ? "" : cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW),
ICalendar.PARAM_LOCATION, StringUtils.defaultString(cache.getLocation()),
ICalendar.PARAM_SHORT_DESC, StringUtils.defaultString(cache.getShortDescription()),
- ICalendar.PARAM_START_TIME_MINUTES, StringUtils.defaultString(cache.guessEventTimeMinutes())
+ ICalendar.PARAM_START_TIME_MINUTES, startTime
);
activity.startActivity(new Intent(ICalendar.INTENT,
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 8e9485e..83a6d6e 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1631,10 +1631,9 @@ public class Geocache implements IWaypoint {
*
* @return start time in minutes after midnight
*/
- @Nullable
- public String guessEventTimeMinutes() {
+ public int guessEventTimeMinutes() {
if (!isEventCache()) {
- return null;
+ return -1;
}
final String hourLocalized = CgeoApplication.getInstance().getString(R.string.cache_time_full_hours);
@@ -1660,14 +1659,14 @@ public class Geocache implements IWaypoint {
minutes = Integer.parseInt(matcher.group(2));
}
if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
- return String.valueOf(hours * 60 + minutes);
+ return hours * 60 + minutes;
}
} catch (final NumberFormatException ignored) {
// cannot happen, but static code analysis doesn't know
}
}
}
- return null;
+ return -1;
}
public boolean hasStaticMap() {
diff --git a/main/src/cgeo/geocaching/sorting/DateComparator.java b/main/src/cgeo/geocaching/sorting/DateComparator.java
index af50213..347eb44 100644
--- a/main/src/cgeo/geocaching/sorting/DateComparator.java
+++ b/main/src/cgeo/geocaching/sorting/DateComparator.java
@@ -17,13 +17,8 @@ class DateComparator extends AbstractCacheComparator {
final Date date2 = cache2.getHiddenDate();
if (date1 != null && date2 != null) {
final int dateDifference = date1.compareTo(date2);
- // for equal dates, sort by distance
if (dateDifference == 0) {
- final ArrayList<Geocache> list = new ArrayList<>();
- list.add(cache1);
- list.add(cache2);
- final DistanceComparator distanceComparator = new DistanceComparator(Sensors.getInstance().currentGeo().getCoords(), list);
- return distanceComparator.compare(cache1, cache2);
+ return sortSameDate(cache1, cache2);
}
return dateDifference;
}
@@ -35,4 +30,13 @@ class DateComparator extends AbstractCacheComparator {
}
return 0;
}
+
+ @SuppressWarnings("static-method")
+ protected int sortSameDate(final Geocache cache1, final Geocache cache2) {
+ final ArrayList<Geocache> list = new ArrayList<>();
+ list.add(cache1);
+ list.add(cache2);
+ final DistanceComparator distanceComparator = new DistanceComparator(Sensors.getInstance().currentGeo().getCoords(), list);
+ return distanceComparator.compare(cache1, cache2);
+ }
}
diff --git a/main/src/cgeo/geocaching/sorting/EventDateComparator.java b/main/src/cgeo/geocaching/sorting/EventDateComparator.java
index 197946a..425ddbb 100644
--- a/main/src/cgeo/geocaching/sorting/EventDateComparator.java
+++ b/main/src/cgeo/geocaching/sorting/EventDateComparator.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.sorting;
+import cgeo.geocaching.Geocache;
+
/**
* Compares caches by date. Used only for event caches.
*/
@@ -7,4 +9,19 @@ public class EventDateComparator extends DateComparator {
final static public EventDateComparator singleton = new EventDateComparator();
+ @Override
+ protected int sortSameDate(final Geocache left, final Geocache right) {
+ return compare(left.guessEventTimeMinutes(), right.guessEventTimeMinutes());
+ }
+
+ /**
+ * copy of {@link Integer#compare(int, int)}, as that is not available on lower API levels
+ *
+ * @param left
+ * @param right
+ * @return
+ */
+ private static int compare(final int left, final int right) {
+ return left < right ? -1 : (left == right ? 0 : 1);
+ }
}
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index 37b6883..3e29bcf 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -302,7 +302,7 @@ public class GeocacheTest extends CGeoTestCase {
cache.setType(CacheType.EVENT);
cache.setDescription(StringUtils.EMPTY);
cache.setShortDescription("text 14:20 text");
- assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(14 * 60 + 20));
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(14 * 60 + 20);
}
private static void assertTime(final String description, final int hours, final int minutes) {
@@ -310,14 +310,14 @@ public class GeocacheTest extends CGeoTestCase {
cache.setDescription(description);
cache.setType(CacheType.EVENT);
final int minutesAfterMidnight = hours * 60 + minutes;
- assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(minutesAfterMidnight));
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(minutesAfterMidnight);
}
private static void assertNoTime(final String description) {
final Geocache cache = new Geocache();
cache.setDescription(description);
cache.setType(CacheType.EVENT);
- assertThat(cache.guessEventTimeMinutes()).isNull();
+ assertThat(cache.guessEventTimeMinutes()).isEqualTo(-1);
}
public static void testGetPossibleLogTypes() throws Exception {