Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-15731] style and syntax updates #8

Merged
merged 2 commits into from
Nov 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ else {
var osname = Ti.Platform.osname,
height = Ti.Platform.displayCaps.platformHeight,
width = Ti.Platform.displayCaps.platformWidth;

//considering tablet to have one dimension over 900px - can define your own
var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));

var Window;
if (isTablet) {
Window = require('ui/tablet/ApplicationWindow');
Expand Down
20 changes: 10 additions & 10 deletions Resources/services/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ var MONTH_MAP = {
};

var getRssText = function(item, key) {
return osname === 'mobileweb' ?
item.getElementsByTagName(key).item(0).textContent : //childNodes[0].nodeValue :
item.getElementsByTagName(key).item(0).text;
}
return osname === 'mobileweb'
? item.getElementsByTagName(key).item(0).textContent
: item.getElementsByTagName(key).item(0).text;
};

var parseDate = function(dateString) {
var dateParts = dateString.split(' ');
var timeParts = dateParts[4].split(':');
return MONTH_MAP[dateParts[2].toUpperCase()] + '/' + dateParts[1] + ' ' + timeParts[0] + ':' + timeParts[1];
}
};

exports.loadRssFeed = function(o, tries) {
var xhr = Titanium.Network.createHTTPClient();
Expand All @@ -35,7 +35,7 @@ exports.loadRssFeed = function(o, tries) {
var xml = this.responseXML;
if (xml === null || xml.documentElement === null) {
if (tries < 3) {
tries++
tries++;
exports.loadRssFeed(o, tries);
return;
} else {
Expand All @@ -47,15 +47,15 @@ exports.loadRssFeed = function(o, tries) {
}
}

var items = xml.documentElement.getElementsByTagName("item");
var items = xml.documentElement.getElementsByTagName('item');
var data = [];

for (var i = 0; i < items.length; i++) {
var item = items.item(i);
try {
var url = item.getElementsByTagName('mash:thumbnail').item(0).text;
var src = url.match(/src="([^\"]*)"/gim);
var image = src[0].replace(/src=|"/gim, "");
var url = item.getElementsByTagName('mash:thumbnail').item(0).text;
var src = url.match(/src="([^\"]*)"/gim);
var image = src[0].replace(/src=|"/gim, '');
} catch (e) {
image = '';
}
Expand Down
6 changes: 4 additions & 2 deletions Resources/ui/common/MasterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ var createRssRow = function(item) {
//Master View Component Constructor
function MasterView() {
var self = Ti.UI.createView({
backgroundColor:'#fff'
backgroundColor: '#fff'
});

var table = Ti.UI.createTableView();
self.add(table);
table.addEventListener('click', function(e) {
self.fireEvent('itemSelected', { link: e.row.link });
self.fireEvent('itemSelected', {
link: e.row.link
});
});

self.refreshRssTable = function(data) {
Expand Down
60 changes: 33 additions & 27 deletions Resources/ui/handheld/android/ApplicationWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ function ApplicationWindow() {

//create object instance
var self = Ti.UI.createWindow({
title:'RSS Reader',
backgroundColor:'#fff',
exitOnClose:true,
navBarHidden:false,
title: 'RSS Reader',
backgroundColor: '#fff',
exitOnClose: true,
navBarHidden: false,
activity: {
onCreateOptionsMenu: function(e) {
var menu = e.menu;
var menuItem = menu.add({ title: "Refresh" });
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
refreshRSS();
});
var menu = e.menu;
var menuItem = menu.add({
title: "Refresh"
});
menuItem.setIcon("images/refresh_icon.png");
menuItem.addEventListener("click", function(e) {
refreshRSS();
});
}
}
});

var masterView = new MasterView();
var actInd = Ti.UI.createActivityIndicator({
message: 'Loading...',
Expand All @@ -37,45 +39,49 @@ function ApplicationWindow() {
var detailContainerWindow = Ti.UI.createWindow({
title: 'View Article',
navBarHidden: false,
backgroundColor:'#fff'
backgroundColor: '#fff'
});
detailContainerWindow.add(detailView);

// Show an activity dialog in the status bar while the article loads
var pb;
detailContainerWindow.addEventListener('open', function() {
pb = Titanium.UI.createActivityIndicator({
location: Ti.UI.ActivityIndicator.STATUS_BAR,
type: Ti.UI.ActivityIndicator.DETERMINANT,
message:'Loading article...',
message: 'Loading article...',
});
pb.show();
});
detailView.addEventListener('articleLoaded', function() {
pb.hide();
});

detailView.showArticle(e.link);

detailContainerWindow.open();
});

function refreshRSS() {
rss.loadRssFeed({
start: function() { actInd.show(); },
error: function() { actInd.hide(); },
success: function(data) {
masterView.refreshRssTable(data);
actInd.hide();
}
});
start: function() {
actInd.show();
},
error: function() {
actInd.hide();
},
success: function(data) {
masterView.refreshRssTable(data);
actInd.hide();
}
});
}

// refresh RSS when ApplicationWindow opens
self.addEventListener('open', function() {
refreshRSS();
});

return self;
};
}
module.exports = ApplicationWindow;
28 changes: 11 additions & 17 deletions Resources/ui/handheld/ios/ApplicationWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ function ApplicationWindow() {
MasterView = require('ui/common/MasterView'),
DetailView = require('ui/common/DetailView');

//create object instance
var self = Ti.UI.createWindow({
backgroundColor:'#ffffff'
});

//construct UI
var masterView = new MasterView(),
detailView = new DetailView();

//create master view container
var masterContainerWindow = Ti.UI.createWindow({
title:'RSS Reader'
title: 'RSS Reader'
});
var button = Ti.UI.createButton({
systemButton: Ti.UI.iPhone.SystemButton.REFRESH
Expand All @@ -32,28 +27,27 @@ function ApplicationWindow() {
detailContainerWindow.add(detailView);

//create iOS specific NavGroup UI
var navGroup = Ti.UI.iPhone.createNavigationGroup({
window:masterContainerWindow
var navGroup = Ti.UI.iOS.createNavigationWindow({
window: masterContainerWindow
});
self.add(navGroup);

//add behavior for master view
masterView.addEventListener('itemSelected', function(e) {
detailView.showArticle(e.link);
navGroup.open(detailContainerWindow);
navGroup.openWindow(detailContainerWindow);
});

function refreshRSS() {
rss.loadRssFeed({
success: function(data) {
masterView.refreshRssTable(data);
}
masterView.refreshRssTable(data);
}
});
}

// load initial rss feed
refreshRSS();
return self;
};

return navGroup;
}
module.exports = ApplicationWindow;
18 changes: 9 additions & 9 deletions Resources/ui/handheld/mobileweb/ApplicationWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ApplicationWindow() {

//create object instance
var self = Ti.UI.createWindow({
backgroundColor:'#fff'
backgroundColor: '#fff'
});

//construct UI
Expand All @@ -16,7 +16,7 @@ function ApplicationWindow() {

//create master view container
var masterContainerWindow = Ti.UI.createWindow({
title:'RSS Reader',
title: 'RSS Reader',
layout: 'vertical'
});
var button = Ti.UI.createButton({
Expand All @@ -38,7 +38,7 @@ function ApplicationWindow() {

//create Mobile Web specific NavGroup UI
var navGroup = Ti.UI.MobileWeb.createNavigationGroup({
window:masterContainerWindow
window: masterContainerWindow
});
self.add(navGroup);

Expand All @@ -47,18 +47,18 @@ function ApplicationWindow() {
detailView.showArticle(e.link);
navGroup.open(detailContainerWindow);
});

function refreshRSS() {
rss.loadRssFeed({
success: function(data) {
masterView.refreshRssTable(data);
}
masterView.refreshRssTable(data);
}
});
}

// load initial rss feed
refreshRSS();

return self;
};
}
module.exports = ApplicationWindow;
28 changes: 14 additions & 14 deletions Resources/ui/tablet/ApplicationWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ApplicationWindow() {

//create object instance
var self = Ti.UI.createWindow({
backgroundColor:'#ffffff'
backgroundColor: '#ffffff'
});

//construct UI
Expand All @@ -25,7 +25,7 @@ function ApplicationWindow() {
color: '#fff',
font: {
fontSize: 32,
fontWeight: 'bold'
fontWeight: 'bold'
},
height: 'auto',
textAlign: 'center',
Expand All @@ -50,20 +50,20 @@ function ApplicationWindow() {

//create master view container
var masterContainer = Ti.UI.createView({
top:50,
bottom:0,
left:0,
width:240
top: 50,
bottom: 0,
left: 0,
width: 240
});
masterContainer.add(masterView);
self.add(masterContainer);

//create detail view container
var detailContainer = Ti.UI.createView({
top:50,
bottom:0,
right:0,
left:240
top: 50,
bottom: 0,
right: 0,
left: 240
});
detailContainer.add(detailView);
self.add(detailContainer);
Expand All @@ -72,15 +72,15 @@ function ApplicationWindow() {
masterView.addEventListener('itemSelected', function(e) {
detailView.showArticle(e.link);
});

function refreshRSS() {
rss.loadRssFeed({
success: function(data) {
masterView.refreshRssTable(data);
}
masterView.refreshRssTable(data);
}
});
}

// load initial rss feed
refreshRSS();

Expand Down
1 change: 0 additions & 1 deletion tiapp.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
<sdk-version>3.1.3.GA</sdk-version>
<deployment-targets>
<target device="tizen">false</target>
<target device="mobileweb">true</target>
Expand Down