aboutsummaryrefslogtreecommitdiffstats
path: root/Resources
diff options
context:
space:
mode:
Diffstat (limited to 'Resources')
-rw-r--r--Resources/app.js66
-rw-r--r--Resources/search.js90
2 files changed, 103 insertions, 53 deletions
diff --git a/Resources/app.js b/Resources/app.js
index b10ea40..2dba46e 100644
--- a/Resources/app.js
+++ b/Resources/app.js
@@ -1,64 +1,24 @@
-// this sets the background color of the master UIView (when there are no windows/tab groups on it)
-Titanium.UI.setBackgroundColor('#000');
-
-// create tab group
+// Create a tab group to contain our views
var tabGroup = Titanium.UI.createTabGroup();
-//
-// create base UI tab and root window
-//
-var win1 = Titanium.UI.createWindow({
- title:'Tab 1',
- backgroundColor:'#fff'
-});
-var tab1 = Titanium.UI.createTab({
- icon:'KS_nav_views.png',
- title:'Tab 1',
- window:win1
-});
-
-var label1 = Titanium.UI.createLabel({
- color:'#999',
- text:'I am Window 1',
- font:{fontSize:20,fontFamily:'Helvetica Neue'},
- textAlign:'center',
- width:'auto'
-});
-
-win1.add(label1);
-
-//
-// create controls tab and root window
-//
-var win2 = Titanium.UI.createWindow({
- title:'Tab 2',
- backgroundColor:'#fff'
-});
-var tab2 = Titanium.UI.createTab({
- icon:'KS_nav_ui.png',
- title:'Tab 2',
- window:win2
+// Create the main, root window
+var search_win = Titanium.UI.createWindow({
+ title: 'Search Twitter',
+ backgroundColor: '#fff',
+ tabBarHidden: true, // hide the tab bar
+ url: 'search.js' // create a new context for this window in 'search.js'
});
-
-var label2 = Titanium.UI.createLabel({
- color:'#999',
- text:'I am Window 2',
- font:{fontSize:20,fontFamily:'Helvetica Neue'},
- textAlign:'center',
- width:'auto'
+// Create the tab to contain our search window
+var search_tab = Titanium.UI.createTab({
+ title: 'Search',
+ icon: 'KS_nav_views.png',
+ window: search_win // use search_win in this tab
});
-win2.add(label2);
-
-
-//
// add tabs
-//
-tabGroup.addTab(tab1);
-tabGroup.addTab(tab2);
-
+tabGroup.addTab(search_tab);
// open tab group
tabGroup.open();
diff --git a/Resources/search.js b/Resources/search.js
new file mode 100644
index 0000000..973e448
--- /dev/null
+++ b/Resources/search.js
@@ -0,0 +1,90 @@
+// Create a reference to the current window
+var win = Titanium.UI.currentWindow;
+
+// Create an object to contain some useful functions
+// Namespacing can be useful for keeping code organised in Ti applications
+// In simple applications such as this, it's not exactly necessary
+var TSearch = {
+ s: function(query) {
+ var row_data = []; // an array to store our result rows in
+ // (this gets fed into the result_table)
+
+ var request = Titanium.Network.createHTTPClient();
+ request.open('GET', 'http://search.twitter.com/search.json?q=' + query);
+
+ request.onload = function() {
+ var results = (eval('(' + this.responseText + ')')).results;
+
+ // No result case?
+
+ // Open a database to store our result set (Ti uses asynchronous
+ // requests, so this is what I came up with to separate view
+ // and data code)
+ var db = Titanium.Database.open('twitsearch');
+ db.execute('CREATE TABLE IF NOT EXISTS "search_results" (tweet TEXT, user STRING, avatar STRING)');
+ db.execute('DELETE FROM "search_results"');
+
+ for (var i = 0; i < results.length; i++) {
+// var tweet = results[i].text; // Tweet text
+// var user = results[i].from_user; // Username
+// var avatar = results[i].profile_image_url; // Avatar URL
+
+// row_data[i] = {
+// tweet : results[i].text, // Tweet text
+// user : results[i].from_user, // Username
+// avatar : results[i].profile_image_url // Avatar URL
+// };
+
+ db.execute('INSERT INTO "search_results" (tweet, user, avatar) VALUES (?, ?, ?)', results[i].text, results[i].from_user, results[i].profile_image_url);
+ }
+
+ db.close();
+ };
+
+ request.send();
+
+ return row_data;
+ }
+};
+
+
+// Create a search input bar
+var search_input = Titanium.UI.createSearchBar({
+ hintText: 'Enter a search query', // let user know what to type
+ height: 43,
+ top: 0
+});
+
+var result_table = Titanium.UI.createTableView();
+
+
+search_input.addEventListener('return', function(e) {
+ TSearch.s(e.value);
+
+ var db = Titanium.Database.open('twitsearch');
+ //db.execute('CREATE TABLE IF NOT EXISTS "search_results" (tweet TEXT, user STRING, avatar STRING)');
+ var results = db.execute('SELECT * FROM "search_results"');
+
+ while (results.isValidRow()) {
+ Titanium.API.info(results.fieldByName('tweet'));
+ Titanium.API.info(results.fieldByName('user'));
+ Titanium.API.info(results.fieldByName('avatar'));
+
+ results.next();
+ }
+
+ results.close();
+ db.close();
+});
+
+var label1 = Titanium.UI.createLabel({
+ color:'#999',
+ text:'I am Window 1',
+ font:{fontSize:20,fontFamily:'Helvetica Neue'},
+ textAlign:'center',
+ width:'auto'
+});
+
+win.add(label1);
+
+win.add(search_input); \ No newline at end of file