aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2015-01-27 20:46:01 +0100
committerBananeweizen <bananeweizen@gmx.de>2015-01-27 20:46:01 +0100
commit6d0a2f562dae0a236b30b8e733410b44a4dcb7bd (patch)
treebb0fddc5bece5294c076f55cb7530905dc36913c /main/src/cgeo/geocaching
parentc9ec99080115f7d981e11f8573ae2cd874cd7b8b (diff)
downloadcgeo-6d0a2f562dae0a236b30b8e733410b44a4dcb7bd.zip
cgeo-6d0a2f562dae0a236b30b8e733410b44a4dcb7bd.tar.gz
cgeo-6d0a2f562dae0a236b30b8e733410b44a4dcb7bd.tar.bz2
refactoring: use null URL in UnknownConnector
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java10
-rw-r--r--main/src/cgeo/geocaching/Geocache.java11
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractActivity.java1
-rw-r--r--main/src/cgeo/geocaching/connector/AbstractConnector.java3
-rw-r--r--main/src/cgeo/geocaching/connector/IConnector.java5
-rw-r--r--main/src/cgeo/geocaching/connector/UnknownConnector.java5
-rw-r--r--main/src/cgeo/geocaching/export/GpxSerializer.java20
-rw-r--r--main/src/cgeo/geocaching/utils/LogTemplateProvider.java2
8 files changed, 36 insertions, 21 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 05c593c..9ebad8b 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -61,6 +61,7 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
+import org.eclipse.jdt.annotation.Nullable;
import rx.Observable;
import rx.Observable.OnSubscribe;
@@ -326,6 +327,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
@Override
+ @Nullable
public String getAndroidBeamUri() {
return cache != null ? cache.getCgeoUrl() : null;
}
@@ -1461,9 +1463,11 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (unknownTagsHandler.isProblematicDetected()) {
final int startPos = description.length();
final IConnector connector = ConnectorFactory.getConnector(cache);
- final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note, "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>"));
- ((Editable) description).append("\n\n").append(tableNote);
- ((Editable) description).setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ if (StringUtils.isNotEmpty(cache.getUrl())) {
+ final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note, "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>"));
+ ((Editable) description).append("\n\n").append(tableNote);
+ ((Editable) description).setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
}
}
/**
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 83a6d6e..92efbb6 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -484,6 +484,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
@@ -717,22 +720,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);
}
diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java
index 4cddfe6..7626ba8 100644
--- a/main/src/cgeo/geocaching/activity/AbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java
@@ -212,6 +212,7 @@ public abstract class AbstractActivity extends ActionBarActivity implements IAbs
public interface ActivitySharingInterface {
/** Return an URL that represent the current activity for sharing or null for no sharing. */
+ @Nullable
public String getAndroidBeamUri();
}
diff --git a/main/src/cgeo/geocaching/connector/AbstractConnector.java b/main/src/cgeo/geocaching/connector/AbstractConnector.java
index 4984273..7e21366 100644
--- a/main/src/cgeo/geocaching/connector/AbstractConnector.java
+++ b/main/src/cgeo/geocaching/connector/AbstractConnector.java
@@ -19,6 +19,7 @@ import cgeo.geocaching.location.Geopoint;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import rx.functions.Action1;
@@ -144,7 +145,7 @@ public abstract class AbstractConnector implements IConnector {
abstract protected String getCacheUrlPrefix();
@Override
- @NonNull
+ @Nullable
public String getLongCacheUrl(final @NonNull Geocache cache) {
return getCacheUrl(cache);
}
diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java
index 0863723..ce98605 100644
--- a/main/src/cgeo/geocaching/connector/IConnector.java
+++ b/main/src/cgeo/geocaching/connector/IConnector.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.location.Geopoint;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import java.util.Collection;
import java.util.List;
@@ -34,7 +35,7 @@ public interface IConnector {
* @param cache
* @return
*/
- @NonNull
+ @Nullable
public String getCacheUrl(final @NonNull Geocache cache);
/**
@@ -43,7 +44,7 @@ public interface IConnector {
* @param cache
* @return
*/
- @NonNull
+ @Nullable
public String getLongCacheUrl(final @NonNull Geocache cache);
/**
diff --git a/main/src/cgeo/geocaching/connector/UnknownConnector.java b/main/src/cgeo/geocaching/connector/UnknownConnector.java
index fcf1152..1ef1aff 100644
--- a/main/src/cgeo/geocaching/connector/UnknownConnector.java
+++ b/main/src/cgeo/geocaching/connector/UnknownConnector.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.Geocache;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
class UnknownConnector extends AbstractConnector {
@@ -14,9 +15,9 @@ class UnknownConnector extends AbstractConnector {
}
@Override
- @NonNull
+ @Nullable
public String getCacheUrl(@NonNull final Geocache cache) {
- return StringUtils.EMPTY;
+ return null;
}
@Override
diff --git a/main/src/cgeo/geocaching/export/GpxSerializer.java b/main/src/cgeo/geocaching/export/GpxSerializer.java
index fe53f37..f7c0602 100644
--- a/main/src/cgeo/geocaching/export/GpxSerializer.java
+++ b/main/src/cgeo/geocaching/export/GpxSerializer.java
@@ -55,7 +55,7 @@ public final class GpxSerializer {
}
- public void writeGPX(List<String> allGeocodesIn, Writer writer, final ProgressListener progressListener) throws IOException {
+ public void writeGPX(final List<String> allGeocodesIn, final Writer writer, final ProgressListener progressListener) throws IOException {
// create a copy of the geocode list, as we need to modify it, but it might be immutable
final ArrayList<String> allGeocodes = new ArrayList<>(allGeocodesIn);
@@ -88,7 +88,7 @@ public final class GpxSerializer {
gpx.endDocument();
}
- private void exportBatch(final XmlSerializer gpx, Collection<String> geocodesOfBatch) throws IOException {
+ private void exportBatch(final XmlSerializer gpx, final Collection<String> geocodesOfBatch) throws IOException {
final Set<Geocache> caches = DataStore.loadCaches(geocodesOfBatch, LoadFlags.LOAD_ALL_DB_ONLY);
for (final Geocache cache : caches) {
if (cache == null) {
@@ -110,7 +110,11 @@ public final class GpxSerializer {
XmlUtils.multipleTexts(gpx, PREFIX_GPX,
"name", cache.getGeocode(),
- "desc", cache.getName(),
+ "desc", cache.getName());
+ if (StringUtils.isNotEmpty(cache.getUrl())) {
+ gpx.attribute(PREFIX_GPX, "url", cache.getUrl());
+ }
+ XmlUtils.multipleTexts(gpx, PREFIX_GPX,
"url", cache.getUrl(),
"urlname", cache.getName(),
"sym", cache.isFound() ? "Geocache Found" : "Geocache",
@@ -178,7 +182,7 @@ public final class GpxSerializer {
* @return XML schema compliant boolean representation of the boolean flag. This must be either true, false, 0 or 1,
* but no other value (also not upper case True/False).
*/
- private static String gpxBoolean(boolean boolFlag) {
+ private static String gpxBoolean(final boolean boolFlag) {
return boolFlag ? "true" : "false";
}
@@ -255,7 +259,7 @@ public final class GpxSerializer {
}
private void writeLogs(final Geocache cache) throws IOException {
- List<LogEntry> logs = cache.getLogs();
+ final List<LogEntry> logs = cache.getLogs();
if (logs.isEmpty()) {
return;
}
@@ -291,7 +295,7 @@ public final class GpxSerializer {
}
private void writeTravelBugs(final Geocache cache) throws IOException {
- List<Trackable> inventory = cache.getInventory();
+ final List<Trackable> inventory = cache.getInventory();
if (CollectionUtils.isEmpty(inventory)) {
return;
}
@@ -338,7 +342,7 @@ public final class GpxSerializer {
return getLocationPart(cache, 0);
}
- private static String getLocationPart(final Geocache cache, int partIndex) {
+ private static String getLocationPart(final Geocache cache, final int partIndex) {
final String location = cache.getLocation();
if (StringUtils.contains(location, ", ")) {
final String[] parts = StringUtils.split(location, ',');
@@ -350,7 +354,7 @@ public final class GpxSerializer {
}
public static String getCountry(final Geocache cache) {
- String country = getLocationPart(cache, 1);
+ final String country = getLocationPart(cache, 1);
if (StringUtils.isNotEmpty(country)) {
return country;
}
diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
index ff4013c..1db3d5b 100644
--- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
@@ -215,7 +215,7 @@ public final class LogTemplateProvider {
}
final Geocache cache = context.getCache();
if (cache != null) {
- return cache.getUrl();
+ return StringUtils.defaultString(cache.getUrl());
}
return StringUtils.EMPTY;
}