aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 8e9485e..9d4e1b2 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -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);
@@ -1660,14 +1660,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() {
@@ -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)));
+ }
+
}