diff options
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 8e9485e..e2eed56 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -24,8 +24,8 @@ import cgeo.geocaching.list.StoredList; import cgeo.geocaching.location.Geopoint; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.settings.Settings; +import cgeo.geocaching.utils.CalendarUtils; 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; @@ -85,6 +85,8 @@ public class Geocache implements IWaypoint { private long visitedDate = 0; private int listId = StoredList.TEMPORARY_LIST.id; private boolean detailed = false; + + @NonNull private String geocode = ""; private String cacheId = ""; private String guid = ""; @@ -484,6 +486,9 @@ public class Geocache implements IWaypoint { } public void openInBrowser(final Activity fromActivity) { + if (getUrl() == null) { + return; + } final Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getLongUrl())); // Check if cgeo is the default, show the chooser to let the user choose a browser @@ -696,11 +701,7 @@ public class Geocache implements IWaypoint { return getConnector() instanceof ISearchByCenter; } - public void shareCache(final Activity fromActivity, final Resources res) { - if (geocode == null) { - return; - } - + public void shareCache(@NonNull final Activity fromActivity, final Resources res) { final Intent intent = getShareIntent(); fromActivity.startActivity(Intent.createChooser(intent, res.getText(R.string.cache_menu_share))); @@ -717,22 +718,22 @@ public class Geocache implements IWaypoint { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, subject.toString()); - intent.putExtra(Intent.EXTRA_TEXT, getUrl()); + intent.putExtra(Intent.EXTRA_TEXT, StringUtils.defaultString(getUrl())); return intent; } - @NonNull + @Nullable public String getUrl() { return getConnector().getCacheUrl(this); } - @NonNull + @Nullable public String getLongUrl() { return getConnector().getLongCacheUrl(this); } - @NonNull + @Nullable public String getCgeoUrl() { return getConnector().getCacheUrl(this); } @@ -1060,7 +1061,7 @@ public class Geocache implements IWaypoint { this.directionImg = directionImg; } - public void setGeocode(final String geocode) { + public void setGeocode(@NonNull final String geocode) { this.geocode = StringUtils.upperCase(geocode); } @@ -1631,10 +1632,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); @@ -1646,7 +1646,7 @@ public class Geocache implements IWaypoint { // 17 - 20 o'clock patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?" + "\\s*(?:-|[a-z]+)\\s*" + "(?:\\d{1,2})(?:\\.00)?" + "\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE)); // 12 o'clock, 12.00 o'clock - patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE)); + patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.(00|15|30|45))?\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE)); } final String searchText = getShortDescription() + ' ' + getDescription(); @@ -1656,18 +1656,18 @@ public class Geocache implements IWaypoint { try { final int hours = Integer.parseInt(matcher.group(1)); int minutes = 0; - if (matcher.groupCount() >= 2) { + if (matcher.groupCount() >= 2 && !StringUtils.isEmpty(matcher.group(2))) { 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() { @@ -1771,9 +1771,9 @@ public class Geocache implements IWaypoint { public LogType getDefaultLogType() { if (isEventCache()) { final Date eventDate = getHiddenDate(); - final boolean expired = DateUtils.isPastEvent(this); + final boolean expired = CalendarUtils.isPastEvent(this); - if (hasOwnLog(LogType.WILL_ATTEND) || expired || (eventDate != null && DateUtils.daysSince(eventDate.getTime()) == 0)) { + if (hasOwnLog(LogType.WILL_ATTEND) || expired || (eventDate != null && CalendarUtils.daysSince(eventDate.getTime()) == 0)) { return hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED; } return LogType.WILL_ATTEND; @@ -1805,4 +1805,12 @@ public class Geocache implements IWaypoint { return geocodes; } + /** + * Show the hint as toast message. If no hint is available, a default "no hint available" will be shown instead. + */ + public void showHintToast(final Activity activity) { + final String hint = getHint(); + ActivityMixin.showToast(activity, StringUtils.defaultIfBlank(hint, activity.getString(R.string.cache_hint_not_available))); + } + } |
