-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TwitterAPI class to encapsulate background access
TwitterPoster class to run in background
- Loading branch information
1 parent
7bc6b7b
commit b5d3d14
Showing
3 changed files
with
69 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.marakana.utils | ||
|
||
import winterwell.jtwitter.Twitter | ||
|
||
class TwitterAPI | ||
{ | ||
var Twitter twitter | ||
|
||
new () | ||
{ | ||
this.twitter = new Twitter("student", "password") | ||
twitter.setAPIRootUrl("http://yamba.marakana.com/api") | ||
} | ||
|
||
def String updateStatus (String status) | ||
{ | ||
val result = twitter.updateStatus(status) | ||
result.text | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.marakana.yambax | ||
|
||
import android.os.AsyncTask | ||
import android.util.Log | ||
import winterwell.jtwitter.TwitterException | ||
import android.widget.Toast | ||
import android.app.Activity | ||
import com.marakana.utils.TwitterAPI | ||
|
||
class TwitterPoster extends AsyncTask<String, Integer, String> | ||
{ | ||
var TwitterAPI twitter | ||
var Activity activity | ||
|
||
new(TwitterAPI twitter, Activity activity) | ||
{ | ||
this.twitter = twitter | ||
this.activity = activity | ||
} | ||
|
||
override doInBackground(String... it) | ||
{ | ||
try | ||
{ | ||
var status = twitter.updateStatus(get(0)) | ||
status | ||
} | ||
catch (TwitterException e) | ||
{ | ||
Log.e("YAMBA", e.toString()); | ||
"Failed to post"; | ||
} | ||
} | ||
|
||
override onPostExecute(String result) | ||
{ | ||
Toast.makeText(activity, result, Toast.LENGTH_LONG).show(); | ||
} | ||
} |