-
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.
Introduce ApplicationObject. Move Preferences and API object to this
class
- Loading branch information
1 parent
6cc742a
commit e65748e
Showing
5 changed files
with
61 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
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 |
---|---|---|
@@ -1,20 +1,30 @@ | ||
package com.marakana.utils | ||
|
||
import winterwell.jtwitter.Twitter | ||
import android.content.SharedPreferences | ||
|
||
class TwitterAPI | ||
{ | ||
var Twitter twitter | ||
|
||
new () | ||
|
||
new (String username, String password, String root) | ||
{ | ||
this.twitter = new Twitter(username, password) | ||
twitter.setAPIRootUrl(root) | ||
} | ||
|
||
def changeAccount(SharedPreferences prefs) | ||
{ | ||
this.twitter = new Twitter("student", "password") | ||
twitter.setAPIRootUrl("http://yamba.marakana.com/api") | ||
val username = prefs.getString("username", "student") | ||
val password = prefs.getString("password", "password") | ||
val root = prefs.getString("apiRoot", "http://yamba.marakana.com/api") | ||
this.twitter = new Twitter(username, password) | ||
twitter.setAPIRootUrl(root) | ||
} | ||
|
||
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
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,27 @@ | ||
package com.marakana.yambax | ||
|
||
import com.marakana.utils.TwitterAPI | ||
import android.content.SharedPreferences | ||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener | ||
import android.app.Application | ||
import android.preference.PreferenceManager | ||
|
||
class YambaApplication extends Application | ||
{ | ||
@Property TwitterAPI twitter | ||
|
||
var prefsChanged = [ SharedPreferences prefs, String s| | ||
twitter.changeAccount(prefs) ] as OnSharedPreferenceChangeListener | ||
|
||
override onCreate() | ||
{ | ||
super.onCreate | ||
twitter = new TwitterAPI("student", "password", "http://yamba.marakana.com/api") | ||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener = prefsChanged | ||
} | ||
|
||
override onTerminate() | ||
{ | ||
super.onTerminate | ||
} | ||
} |