From b297de18e81872e9725867ba4da4a9481aedfcbf Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 10 Mar 2012 07:37:59 +0100 Subject: 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 --- main/src/cgeo/geocaching/twitter/Twitter.java | 45 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'main/src/cgeo/geocaching/twitter/Twitter.java') 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); + } } -- cgit v1.1