aboutsummaryrefslogtreecommitdiffstats
path: root/Resources
diff options
context:
space:
mode:
Diffstat (limited to 'Resources')
-rw-r--r--Resources/search.js83
1 files changed, 63 insertions, 20 deletions
diff --git a/Resources/search.js b/Resources/search.js
index 973e448..af4fc3b 100644
--- a/Resources/search.js
+++ b/Resources/search.js
@@ -6,9 +6,6 @@ var win = Titanium.UI.currentWindow;
// 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);
@@ -25,16 +22,6 @@ var TSearch = {
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);
}
@@ -42,8 +29,6 @@ var TSearch = {
};
request.send();
-
- return row_data;
}
};
@@ -55,7 +40,11 @@ var search_input = Titanium.UI.createSearchBar({
top: 0
});
-var result_table = Titanium.UI.createTableView();
+var result_table = Titanium.UI.createTableView({
+ top: 43
+});
+var row_data = []; // an array to store our result rows in
+ // (this gets fed into the result_table)
search_input.addEventListener('return', function(e) {
@@ -66,15 +55,68 @@ search_input.addEventListener('return', function(e) {
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'));
+ // Construct a TableView to display our results
+
+ var tweet = results.fieldByName('tweet');
+ var user = results.fieldByName('user');
+ var avatar = results.fieldByName('avatar');
+
+ var row = Titanium.UI.createTableViewRow({
+ height: 'auto'
+ });
+ // tweet_view will contain our tweet elements for a customised TableRow
+ var tweet_view = Titanium.UI.createView({
+ height: 'auto',
+ top: 5,
+ right: 5,
+ bottom: 5,
+ left: 5
+ });
+ var avatar_image = Titanium.UI.createImageView({
+ image: avatar,
+ top: 0,
+ left: 0,
+ height: 45,
+ width: 45
+ });
+ var user_label = Titanium.UI.createLabel({
+ text: user,
+ height: 'auto',
+ font: {fontFamily: 'Helvetica Neue', fontSize: 16, fontWeight: 'bold'},
+ top: -5,
+ left: 50
+ });
+ var tweet_label = Titanium.UI.createLabel({
+ text: tweet,
+ height: 'auto',
+ font: {fontSize: 14},
+ top: 15,
+ left: 50
+ });
+
+
+ // Combine our UI elements
+ tweet_view.add(avatar_image);
+ tweet_view.add(user_label);
+ tweet_view.add(tweet_label);
+ row.add(tweet_view);
+
+ // Add our row to the row_data array
+ row_data.push(row);
results.next();
}
results.close();
db.close();
+
+ // Blur search field to hide on-screen keyboard
+ search_input.blur();
+
+ // Remove old rows from table
+ result_table.setData([]);
+ // Add our new rows to the result TableView
+ result_table.setData(row_data);
});
var label1 = Titanium.UI.createLabel({
@@ -87,4 +129,5 @@ var label1 = Titanium.UI.createLabel({
win.add(label1);
-win.add(search_input); \ No newline at end of file
+win.add(search_input);
+win.add(result_table);