Skip to content

Commit

Permalink
Reworking compose tweet
Browse files Browse the repository at this point in the history
Merged sendTweet and composeTweet. Changed how optional parameters
(image and url attachments) are sent. Added additional examples for
creating tweets.
  • Loading branch information
brianantonelli authored and purplecabbage committed May 16, 2012
1 parent 4a84e46 commit 4c3fe75
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 39 deletions.
52 changes: 43 additions & 9 deletions iPhone/Twitter/example/www/demo.js
Expand Up @@ -17,7 +17,7 @@ TwitterDemo = {
},

setup:function(){
var tests = ["isAvailable", "isSetup", "tweet", "compose", "timeline", "mentions"];
var tests = ["isAvailable", "isSetup", "tweet1", "tweet2", "tweet3", "tweet4", "tweet5", "compose", "timeline", "mentions"];
for(var i=0, l=tests.length; i<l; i++){
this.$(tests[i]).onclick = this[tests[i]];
}
Expand All @@ -37,21 +37,55 @@ TwitterDemo = {
});
},

tweet:function(){
tweet1:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.sendTweet(
window.plugins.twitter.composeTweet(
function(s){ TwitterDemo.log("tweet success"); },
function(e){ TwitterDemo.log("tweet failure: " + e); },
"Tweety Poo",
"https://github.com/brianantonelli",
"http://zomgdinosaurs.com/zomg.jpg");
"Text, Image, URL",
{
urlAttach:"https://github.com/brianantonelli",
imageAttach:"http://zomgdinosaurs.com/zomg.jpg"
});
},

compose: function() {

tweet2:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.composeTweet(
function(s){ TwitterDemo.log("tweet success"); },
function(e){ TwitterDemo.log("tweet failure: " + e); },
"Text, Image",
{
imageAttach:"http://zomgdinosaurs.com/zomg.jpg"
});
},

tweet3:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.composeTweet(
function(s){ TwitterDemo.log("tweet success"); },
function(e){ TwitterDemo.log("tweet failure: " + e); },
"Text, URL",
{
urlAttach:"https://github.com/brianantonelli"
});
},

tweet4:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.composeTweet();
window.plugins.twitter.composeTweet(
function(s){ TwitterDemo.log("tweet success"); },
function(e){ TwitterDemo.log("tweet failure: " + e); },
"Text");
},

tweet5:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.composeTweet(
function(s){ TwitterDemo.log("tweet success"); },
function(e){ TwitterDemo.log("tweet failure: " + e); });
},

timeline:function(){
TwitterDemo.log("wait..");
window.plugins.twitter.getPublicTimeline(
Expand Down
7 changes: 5 additions & 2 deletions iPhone/Twitter/example/www/index.html
Expand Up @@ -17,8 +17,11 @@ <h1>Hey, it's Twitter on PhoneGap!</h1>
<ol>
<li><a href="#" id="isAvailable">isAvailable</a></li>
<li><a href="#" id="isSetup">isSetup</a></li>
<li><a href="#" id="tweet">tweet through API</a></li>
<li><a href="#" id="compose">compose new tweet popup</a></li>
<li><a href="#" id="tweet1">tweet (text, img, url)</a></li>
<li><a href="#" id="tweet2">tweet (text, img)</a></li>
<li><a href="#" id="tweet3">tweet (text, url)</a></li>
<li><a href="#" id="tweet4">tweet (text)</a></li>
<li><a href="#" id="tweet5">tweet (empty)</a></li>
<li><a href="#" id="timeline">timeline</a></li>
<li><a href="#" id="mentions">mentions</a></li>
</ol>
Expand Down
2 changes: 0 additions & 2 deletions iPhone/Twitter/native/ios/TwitterPlugin.h
Expand Up @@ -21,8 +21,6 @@

- (void) isTwitterSetup:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

- (void) sendTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

- (void) composeTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

- (void) getPublicTimeline:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
Expand Down
26 changes: 9 additions & 17 deletions iPhone/Twitter/native/ios/TwitterPlugin.m
Expand Up @@ -36,21 +36,23 @@ - (void) isTwitterSetup:(NSMutableArray*)arguments withDict:(NSMutableDictionary
[super writeJavascript:[[PluginResult resultWithStatus:PGCommandStatus_OK messageAsInt:canTweet ? 1 : 0] toSuccessCallbackString:callbackId]];
}

- (void) sendTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
- (void) composeTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
// arguments: callback, tweet text, url attachment, image attachment
NSString *callbackId = [arguments objectAtIndex:0];
NSString *tweetText = [arguments objectAtIndex:1];
NSString *urlAttach = [arguments objectAtIndex:2];
NSString *imageAttach = [arguments objectAtIndex:3];
NSString *tweetText = [options objectForKey:@"text"];
NSString *urlAttach = [options objectForKey:@"urlAttach"];
NSString *imageAttach = [options objectForKey:@"imageAttach"];

TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];

BOOL ok = YES;
NSString *errorMessage;

ok = [tweetViewController setInitialText:tweetText];
if(!ok){
errorMessage = @"Tweet is too long";
if(tweetText != nil){
ok = [tweetViewController setInitialText:tweetText];
if(!ok){
errorMessage = @"Tweet is too long";
}
}

if(urlAttach != nil){
Expand Down Expand Up @@ -98,16 +100,6 @@ - (void) sendTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)opt
[tweetViewController release];
}

- (void) composeTweet:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
TWTweetComposeViewController *tweetComposeViewController = [[TWTweetComposeViewController alloc] init];
[tweetComposeViewController setCompletionHandler: ^(TWTweetComposeViewControllerResult result) {
[[super appViewController] dismissModalViewControllerAnimated:YES];
}];

[[super appViewController] presentModalViewController:tweetComposeViewController animated:YES];
[tweetComposeViewController release];
}

- (void) getPublicTimeline:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options{
NSString *callbackId = [arguments objectAtIndex:0];
NSString *url = [NSString stringWithFormat:@"%@statuses/public_timeline.json", TWITTER_URL];
Expand Down
13 changes: 4 additions & 9 deletions iPhone/Twitter/www/TwitterPlugin.js
Expand Up @@ -8,15 +8,10 @@ Twitter.prototype.isTwitterSetup = function(response){
PhoneGap.exec(response, null, "com.phonegap.twitter", "isTwitterSetup", []);
};

Twitter.prototype.sendTweet = function(success, failure, tweetText, urlAttach, imageAttach){
if(typeof urlAttach === "undefined") urlAttach = "";
if(typeof imageAttach === "undefined") imageAttach = "";

PhoneGap.exec(success, failure, "com.phonegap.twitter", "sendTweet", [tweetText, urlAttach, imageAttach]);
};

Twitter.prototype.composeTweet = function() {
PhoneGap.exec(null, null, "com.phonegap.twitter", "composeTweet", []);
Twitter.prototype.composeTweet = function(success, failure, tweetText, options){
options = options || {};
options.text = tweetText;
PhoneGap.exec(success, failure, "com.phonegap.twitter", "composeTweet", [options]);
};

Twitter.prototype.getPublicTimeline = function(success, failure){
Expand Down

0 comments on commit 4c3fe75

Please sign in to comment.