diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-10-22 07:22:13 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-10-22 07:22:13 +0200 |
| commit | e8c6f33414de6b4cb429cd1bb03c95a9d01bbd51 (patch) | |
| tree | e54982ddf43984aa47638fc608864d3dce164011 /main/src | |
| parent | cb944d417dd7616f3b7d64f29787953339bd70c6 (diff) | |
| download | cgeo-e8c6f33414de6b4cb429cd1bb03c95a9d01bbd51.zip cgeo-e8c6f33414de6b4cb429cd1bb03c95a9d01bbd51.tar.gz cgeo-e8c6f33414de6b4cb429cd1bb03c95a9d01bbd51.tar.bz2 | |
#3367: limit twitter message again during status post
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/twitter/Twitter.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/twitter/Twitter.java b/main/src/cgeo/geocaching/twitter/Twitter.java index 670165e..39f3f83 100644 --- a/main/src/cgeo/geocaching/twitter/Twitter.java +++ b/main/src/cgeo/geocaching/twitter/Twitter.java @@ -34,12 +34,13 @@ public final class Twitter { postTweet(CgeoApplication.getInstance(), getStatusMessage(trackable), null); } - private static void postTweet(final CgeoApplication app, final String status, final Geopoint coords) { + private static void postTweet(final CgeoApplication app, final String statusIn, final Geopoint coords) { if (app == null || !Settings.isUseTwitter() || !Settings.isTwitterLoginValid()) { return; } try { + final String status = shortenToMaxSize(statusIn); Parameters parameters = new Parameters("status", status); if (coords != null) { parameters.put( @@ -64,6 +65,14 @@ public final class Twitter { } } + private static String shortenToMaxSize(final String status) { + String result = StringUtils.trim(status); + if (StringUtils.length(result) > MAX_TWEET_SIZE) { + return StringUtils.substring(result, 0, MAX_TWEET_SIZE - 1) + '…'; + } + return result; + } + private static void appendHashTag(final StringBuilder status, final String tag) { if (status.length() + HASH_PREFIX_WITH_BLANK.length() + tag.length() <= MAX_TWEET_SIZE) { final String tagWithPrefix = HASH_PREFIX_WITH_BLANK + tag; |
