aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/LogTrackableActivity.java4
-rw-r--r--main/src/cgeo/geocaching/twitter/Twitter.java20
-rw-r--r--main/src/cgeo/geocaching/utils/LogTemplateProvider.java3
-rw-r--r--tests/src/cgeo/geocaching/twitter/TwitterTest.java16
4 files changed, 32 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/LogTrackableActivity.java b/main/src/cgeo/geocaching/LogTrackableActivity.java
index 2761658..dd3fa78 100644
--- a/main/src/cgeo/geocaching/LogTrackableActivity.java
+++ b/main/src/cgeo/geocaching/LogTrackableActivity.java
@@ -335,7 +335,7 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
if (status == StatusCode.NO_ERROR && Settings.isUseTwitter() &&
Settings.isTwitterLoginValid() &&
tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
- Twitter.postTweetTrackable(geocode);
+ Twitter.postTweetTrackable(geocode, new LogEntry(0, typeSelected, log));
}
return status;
@@ -356,6 +356,6 @@ public class LogTrackableActivity extends AbstractLoggingActivity implements Dat
@Override
protected LogContext getLogContext() {
- return new LogContext(trackable);
+ return new LogContext(trackable, null);
}
}
diff --git a/main/src/cgeo/geocaching/twitter/Twitter.java b/main/src/cgeo/geocaching/twitter/Twitter.java
index 39f3f83..7213789 100644
--- a/main/src/cgeo/geocaching/twitter/Twitter.java
+++ b/main/src/cgeo/geocaching/twitter/Twitter.java
@@ -19,19 +19,27 @@ import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import ch.boye.httpclientandroidlib.HttpResponse;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
public final class Twitter {
private static final String HASH_PREFIX_WITH_BLANK = " #";
private static final int MAX_TWEET_SIZE = 140;
- public static void postTweetCache(String geocode, LogEntry logEntry) {
+ public static void postTweetCache(String geocode, final @Nullable LogEntry logEntry) {
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ if (cache == null) {
+ return;
+ }
postTweet(CgeoApplication.getInstance(), getStatusMessage(cache, logEntry), null);
}
- public static void postTweetTrackable(String geocode) {
+ public static void postTweetTrackable(String geocode, final @Nullable LogEntry logEntry) {
final Trackable trackable = DataStore.loadTrackable(geocode);
- postTweet(CgeoApplication.getInstance(), getStatusMessage(trackable), null);
+ if (trackable == null) {
+ return;
+ }
+ postTweet(CgeoApplication.getInstance(), getStatusMessage(trackable, logEntry), null);
}
private static void postTweet(final CgeoApplication app, final String statusIn, final Geopoint coords) {
@@ -82,12 +90,12 @@ public final class Twitter {
}
}
- static String getStatusMessage(Geocache cache, LogEntry logEntry) {
+ static String getStatusMessage(final @NonNull Geocache cache, final @Nullable LogEntry logEntry) {
return appendHashTags(LogTemplateProvider.applyTemplates(Settings.getCacheTwitterMessage(), new LogContext(cache, logEntry)));
}
- static String getStatusMessage(Trackable trackable) {
- return appendHashTags(LogTemplateProvider.applyTemplates(Settings.getTrackableTwitterMessage(), new LogContext(trackable)));
+ static String getStatusMessage(final @NonNull Trackable trackable, final @Nullable LogEntry logEntry) {
+ return appendHashTags(LogTemplateProvider.applyTemplates(Settings.getTrackableTwitterMessage(), new LogContext(trackable, logEntry)));
}
private static String appendHashTags(final String status) {
diff --git a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
index af183f7..76fa0f7 100644
--- a/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/utils/LogTemplateProvider.java
@@ -42,8 +42,9 @@ public final class LogTemplateProvider {
this(cache, logEntry, false);
}
- public LogContext(final Trackable trackable) {
+ public LogContext(final Trackable trackable, final LogEntry logEntry) {
this.trackable = trackable;
+ this.logEntry = logEntry;
}
public LogContext(final boolean offline) {
diff --git a/tests/src/cgeo/geocaching/twitter/TwitterTest.java b/tests/src/cgeo/geocaching/twitter/TwitterTest.java
index 92bda71..9de5e2f 100644
--- a/tests/src/cgeo/geocaching/twitter/TwitterTest.java
+++ b/tests/src/cgeo/geocaching/twitter/TwitterTest.java
@@ -18,7 +18,7 @@ public class TwitterTest extends TestCase {
Trackable tb = new Trackable();
tb.setName("Travel bug");
tb.setGeocode("TB1234");
- assertEquals("I touched Travel bug (http://www.geocaching.com//track/details.aspx?tracker=TB1234). #cgeo #geocaching", Twitter.getStatusMessage(tb));
+ assertEquals("I touched Travel bug (http://www.geocaching.com//track/details.aspx?tracker=TB1234). #cgeo #geocaching", Twitter.getStatusMessage(tb, null));
} finally {
TestSettings.setTrackableTwitterMessage(oldMessage);
}
@@ -42,13 +42,25 @@ public class TwitterTest extends TestCase {
try {
TestSettings.setCacheTwitterMessage("[LOG]");
Geocache cache = new Geocache();
- LogEntry log = new LogEntry("me", 0, LogType.FOUND_IT, "log text");
+ LogEntry log = new LogEntry(0, LogType.FOUND_IT, "log text");
assertEquals("log text #cgeo #geocaching", Twitter.getStatusMessage(cache, log));
} finally {
TestSettings.setCacheTwitterMessage(oldMessage);
}
}
+ public static void testTrackableMessageWithLogContent() {
+ final String oldMessage = Settings.getCacheTwitterMessage();
+ try {
+ TestSettings.setTrackableTwitterMessage("[LOG]");
+ Trackable trackable = new Trackable();
+ LogEntry log = new LogEntry(0, LogType.FOUND_IT, "trackable log text");
+ assertEquals("trackable log text #cgeo #geocaching", Twitter.getStatusMessage(trackable, log));
+ } finally {
+ TestSettings.setTrackableTwitterMessage(oldMessage);
+ }
+ }
+
public static void testAvoidDuplicateTags() {
final String oldMessage = Settings.getCacheTwitterMessage();
try {