diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-07-01 21:01:05 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-07-01 21:01:05 +0200 |
| commit | d54d589484303dfd8a2f5d98ca69040bb84a9535 (patch) | |
| tree | a721c9bd3187302f9b603018999270d41eab86b9 /main/src/cgeo | |
| parent | e86317306d5b013d8d2b0efc4ea35fe11b6758ae (diff) | |
| download | cgeo-d54d589484303dfd8a2f5d98ca69040bb84a9535.zip cgeo-d54d589484303dfd8a2f5d98ca69040bb84a9535.tar.gz cgeo-d54d589484303dfd8a2f5d98ca69040bb84a9535.tar.bz2 | |
fix #1858: add start time to calendar entry
Diffstat (limited to 'main/src/cgeo')
| -rw-r--r-- | main/src/cgeo/calendar/ICalendar.java | 1 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 43 |
3 files changed, 45 insertions, 2 deletions
diff --git a/main/src/cgeo/calendar/ICalendar.java b/main/src/cgeo/calendar/ICalendar.java index 856de1a..933d248 100644 --- a/main/src/cgeo/calendar/ICalendar.java +++ b/main/src/cgeo/calendar/ICalendar.java @@ -15,4 +15,5 @@ public interface ICalendar { static final String PARAM_NAME = "name"; // cache name static final String PARAM_LOCATION = "location"; // cache location, or empty string static final String PARAM_COORDS = "coords"; // cache coords, or empty string + static final String PARAM_START_TIME_MINUTES = "time"; // time of start } diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index d1b0fde..93566c2 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -787,7 +787,8 @@ public class CacheDetailActivity extends AbstractActivity { ICalendar.PARAM_URL, StringUtils.defaultString(cache.getUrl()), 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_SHORT_DESC, StringUtils.defaultString(cache.getShortDescription()), + ICalendar.PARAM_START_TIME_MINUTES, StringUtils.defaultString(cache.guessEventTimeMinutes()) ); startActivity(new Intent(ICalendar.INTENT, diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index b889d3e..b8590e5 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -1550,4 +1550,45 @@ public class cgCache implements ICache, IWaypoint { return listId >= StoredList.STANDARD_LIST_ID; } -} + /** + * guess an event start time from the description + * + * @return start time in minutes after midnight + */ + public String guessEventTimeMinutes() { + if (!isEventCache()) { + return null; + } + // 12:34 + final Pattern time = Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b"); + final Matcher matcher = time.matcher(getDescription()); + while (matcher.find()) { + try { + final int hours = Integer.valueOf(matcher.group(1)); + final int minutes = Integer.valueOf(matcher.group(2)); + if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) { + return String.valueOf(hours * 60 + minutes); + } + } catch (NumberFormatException e) { + // cannot happen, but static code analysis doesn't know + } + } + // 12 o'clock + final String hourLocalized = cgeoapplication.getInstance().getString(R.string.cache_time_full_hours); + if (StringUtils.isNotBlank(hourLocalized)) { + final Pattern fullHours = Pattern.compile("\\b(\\d{1,2})\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE); + final Matcher matcherHours = fullHours.matcher(getDescription()); + if (matcherHours.find()) { + try { + final int hours = Integer.valueOf(matcherHours.group(1)); + if (hours >= 0 && hours < 24) { + return String.valueOf(hours * 60); + } + } catch (NumberFormatException e) { + // cannot happen, but static code analysis doesn't know + } + } + } + return null; + } +}
\ No newline at end of file |
