diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-03-10 07:37:59 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-03-10 07:37:59 +0100 |
| commit | b297de18e81872e9725867ba4da4a9481aedfcbf (patch) | |
| tree | 80db5404f602577fdbf2d3e1bb34c36f850300d2 /main/src/cgeo/geocaching/twitter/Twitter.java | |
| parent | 5daaa3d454ff680e74fdbf8f673674d0eb339817 (diff) | |
| download | cgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.zip cgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.tar.gz cgeo-b297de18e81872e9725867ba4da4a9481aedfcbf.tar.bz2 | |
refactoring: first part of removing cgBase
* extract network stuff (non GC related)
* extract GC login stuff
* move UI related pieces to activities
* to do: move parsing and searching to better places, remove cgBase
completely afterwards
Diffstat (limited to 'main/src/cgeo/geocaching/twitter/Twitter.java')
| -rw-r--r-- | main/src/cgeo/geocaching/twitter/Twitter.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/twitter/Twitter.java b/main/src/cgeo/geocaching/twitter/Twitter.java index a47409f..fa1a39d 100644 --- a/main/src/cgeo/geocaching/twitter/Twitter.java +++ b/main/src/cgeo/geocaching/twitter/Twitter.java @@ -1,10 +1,13 @@ package cgeo.geocaching.twitter; import cgeo.geocaching.Settings; -import cgeo.geocaching.cgBase; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgTrackable; import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import cgeo.geocaching.network.Network; import cgeo.geocaching.network.OAuth; import cgeo.geocaching.network.Parameters; @@ -33,7 +36,7 @@ public final class Twitter { } OAuth.signOAuth("api.twitter.com", "/1/statuses/update.json", "POST", false, parameters, Settings.getTokenPublic(), Settings.getTokenSecret()); - final HttpResponse httpResponse = cgBase.postRequest("http://api.twitter.com/1/statuses/update.json", parameters); + final HttpResponse httpResponse = Network.postRequest("http://api.twitter.com/1/statuses/update.json", parameters); if (httpResponse != null && httpResponse.getStatusLine().getStatusCode() == 200) { Log.i(Settings.tag, "Tweet posted"); } else { @@ -51,4 +54,42 @@ public final class Twitter { } return result; } + + public static void postTweetCache(String geocode) { + final cgCache cache = cgeoapplication.getInstance().loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); + String status; + final String url = cache.getUrl(); + if (url.length() >= 100) { + status = "I found " + url; + } + else { + String name = cache.getName(); + status = "I found " + name + " (" + url + ")"; + if (status.length() > MAX_TWEET_SIZE) { + name = name.substring(0, name.length() - (status.length() - MAX_TWEET_SIZE) - 3) + "..."; + } + status = "I found " + name + " (" + url + ")"; + status = appendHashTag(status, "cgeo"); + status = appendHashTag(status, "geocaching"); + } + + postTweet(cgeoapplication.getInstance(), status, null); + } + + public static void postTweetTrackable(String geocode) { + final cgTrackable trackable = cgeoapplication.getInstance().getTrackableByGeocode(geocode); + String name = trackable.getName(); + if (name.length() > 82) { + name = name.substring(0, 79) + "..."; + } + StringBuilder builder = new StringBuilder("I touched "); + builder.append(name); + if (trackable.getUrl() != null) { + builder.append(" (").append(trackable.getUrl()).append(')'); + } + builder.append('!'); + String status = appendHashTag(builder.toString(), "cgeo"); + status = appendHashTag(status, "geocaching"); + postTweet(cgeoapplication.getInstance(), status, null); + } } |
