Created
July 4, 2011 01:59
app.js of urlreader
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
var TWITTER_USER_NAME = 'ikuyamada'; | |
function processTweets(data) { | |
var urls = []; | |
for (var i = 0; i < data.length; i++) { | |
var ret = data[i].text.match(/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+/); | |
if (ret) | |
urls = urls.concat(ret); | |
} | |
showUrlList(urls); | |
} | |
function showUrlList(urls) { | |
var tableView = Ti.UI.createTableView(); | |
listWin.add(tableView); | |
for (var i=0; i < urls.length; i++) { | |
(function(url) { | |
var row = Ti.UI.createTableViewRow({ | |
title: url, | |
hasChild: true | |
}); | |
row.addEventListener('click', function() { | |
var win = Ti.UI.createWindow({ | |
modal: true | |
}); | |
var browser = Ti.UI.createWebView({ | |
url: url | |
}); | |
win.add(browser); | |
var closeButton = Ti.UI.createButton({ | |
title: 'close', | |
height: 30 | |
}); | |
closeButton.addEventListener('click', function() { | |
win.close(); | |
}); | |
win.rightNavButton = closeButton; | |
win.open(); | |
}); | |
tableView.appendRow(row); | |
})(urls[i]); | |
} | |
} | |
var tabGroup = Ti.UI.createTabGroup(); | |
var listWin = Ti.UI.createWindow({ | |
title: 'List', | |
tabBarHidden: true | |
}); | |
var listTab = Ti.UI.createTab({ | |
window: listWin | |
}); | |
tabGroup.addTab(listTab); | |
tabGroup.open(); | |
var xhr = Ti.Network.createHTTPClient(); | |
var url = "http://api.twitter.com/1/statuses/user_timeline.json?count=200&screen_name=" + TWITTER_USER_NAME; | |
xhr.open('GET', url); | |
xhr.onload = function() { | |
processTweets(JSON.parse(this.responseText)); | |
}; | |
xhr.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment