aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-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
4 files changed, 33 insertions, 12 deletions
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);
+ }
}