Skip to content

Commit

Permalink
chat progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jkritikos committed Mar 6, 2014
1 parent bf91c6a commit e714039
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 116 deletions.
Binary file removed Resources/KS_nav_ui.png
Binary file not shown.
Binary file removed Resources/KS_nav_views.png
Binary file not shown.
60 changes: 52 additions & 8 deletions Resources/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
Ti.include('trading.js');
Ti.include('chat.js');
Ti.include('utils.js');

var IPHONE5 = false;
if(Ti.Platform.displayCaps.platformHeight == 568){
IPHONE5 = true;
}

//Webview - titanium event types
var EVENT_TRADE_INDEX = "app:trade_index";
var EVENT_TRADE = "app:trade";
var EVENT_CHAT = "app:chat";
var EVENT_FROM_CHAT = "app:from_chat";
var EVENT_FROM_TRADE = "app:from_trade";

//Colors
var COLOR_BG = '#f1f2f7';
var COLOR_BG = '#32323a';
var COLOR_LIGHT_BLUE = '#01aef0';
var COLOR_LIGHT_GREEN = '#a9d86e';
var COLOR_LIGHT_RED = '#ff6c60';
var COLOR_DARK_GRAY = 'black';

var username = 'Jason Kritikos';

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
Expand All @@ -12,31 +30,57 @@ Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();


Ti.App.addEventListener('app:fromWebView', function(e) {
Ti.API.info('webview says: '+JSON.stringify(e));
Ti.App.addEventListener(EVENT_TRADE_INDEX, function(e) {
//Ti.API.info('webview trade index: '+JSON.stringify(e));

var indexName = e.indexName;
var indexNameClean = e.indexNameClean;
var bid = e.bid;
var offer = e.offer;
createTradingRow(indexName, bid, offer);
});

Ti.App.addEventListener(EVENT_TRADE, function(e) {
//Ti.API.info('webview trade: '+JSON.stringify(e));
});

Ti.App.addEventListener(EVENT_CHAT, function(e) {
//Ti.API.info('webview chat: '+JSON.stringify(e));
Ti.API.info('webview chat: curently with '+chatTableView.data[0].rows.length+' rows');

createMessageRow(e.message, '2m ago', e.from, false);
//chatTableView.scrollToIndex(chatTableView.data[0].rows.length+1);
//chatTableView.scrollToIndex(chatTableView.data[0].rows.length+1);

chatTableView.scrollToIndex(chatTableView.data[0].rows.length-1);
});

// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
title:'Chat',
barColor:COLOR_LIGHT_BLUE,
statusBarStyle:Titanium.UI.iPhone.StatusBar.LIGHT_CONTENT,
backgroundColor:'#fff'
backgroundColor:COLOR_BG
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
icon:'images/iphone/tabs/email_circle.png',
title:'Chat',
window:win1
});

//webview handles all the comms
var webview = Ti.UI.createWebView({
url:'test_works.html',
visible:true
visible:false
});

//win1.add(buildChatView());
win1.add(buildChatView());
win1.add(webview);

createMessageRow('This is a test message', '2m ago', 'Christina Sigala', false);
createMessageRow('This is another test message', '2m ago', 'Christina Sigala', false);
createMessageRow('This is another test message, much longer this time, just to make sure that the label appears correctly!', '2m ago', 'Christina Sigala', false);

// create controls tab and root window
var win2 = Titanium.UI.createWindow({
title:'Trading',
Expand All @@ -48,7 +92,7 @@ var win2 = Titanium.UI.createWindow({
win2.add(buildTradingView());

var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
icon:'images/iphone/tabs/chart_up.png',
title:'Trading',
window:win2
});
Expand Down
51 changes: 51 additions & 0 deletions Resources/app_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var win = Titanium.UI.createWindow({
title : 'Win 1',
backgroundColor : '#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window: win
});

var intContentCount = 0;

var scrollView = Ti.UI.createScrollView({
backgroundColor: 'orange',
contentHeight: 'auto',
contentWidth: 'auto',
height: Ti.UI.FILL,
showHorizontalScrollIndicator: true,
showVerticalScrollIndicator: true,
width: Ti.UI.FILL
});
win.add(scrollView);

var view = Ti.UI.createView({
backgroundColor: 'yellow',
bottom: 0,
height: Ti.UI.SIZE,
layout: 'vertical',
width: Ti.UI.FILL
});
scrollView.add(view);

var btnTest = Ti.UI.createButton({
title: 'add another'
});
btnTest.addEventListener('click', function (e) {
intContentCount = intContentCount + 1;
// just adding a label here but your could add
// a view and put a label and button inside if you wish
var lbl = Ti.UI.createLabel({
height: Ti.UI.SIZE,
text: 'Example Content: ' + intContentCount,
width: Ti.UI.FILL
});
view.add(lbl);
scrollView.scrollToBottom();
});
win.setRightNavButton(btnTest);
var tabGroup = Titanium.UI.createTabGroup();
tabGroup.addTab(tab1);
tabGroup.open();
205 changes: 187 additions & 18 deletions Resources/chat.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,203 @@
//UI components
var chatTableView, chatView, messageField, messageSendButton = null;

function buildChatView(){
var chatView = Ti.UI.createScrollView({
top:0,
bottom:0
chatView = Ti.UI.createView({
//top:0,
//bottom:0
});

var tableView = Ti.UI.createTableView({
top:10,
bottom:20,
chatTableView = Ti.UI.createTableView({
top:5,
height:IPHONE5 ? 421 : 324,
width:'95%',
separatorStyle:Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
backgroundColor:'transparent'
selectionStyle:Ti.UI.iPhone.TableViewCellSelectionStyle.NONE,
backgroundColor:'transparent',
minRowHeight:75
});

chatTableView.footerView = Ti.UI.createView({
height: 1,
backgroundColor: 'transparent'
});

var messageField = Ti.UI.createTextField({
backgroundColor:'#fafafa',
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
value:'',
hintText:'Enter your message',
messageField = Ti.UI.createTextField({
hintText:'Send a message',
paddingLeft:5,
width:252,
height:30,
bottom:1,
left:10,
height:25,
width:'80%',
bottom:15,
font:{fontSize:14, fontWeight:'regular', fontFamily:'Calibri'}
backgroundColor:'white',
borderWidth:1,
borderRadius:3,
borderColor:'c5c5c5',
font:{fontSize:14, fontWeight:'bold', fontFamily:'Calibri'}
});

messageField.addEventListener('focus', handleChatFieldFocus);
messageField.addEventListener('blur', handleChatFieldBlur);

messageSendButton = Ti.UI.createButton({
title:'Send',
tintColor:COLOR_LIGHT_GREEN,
bottom:1,
right:10
});

chatView.add(tableView);
messageSendButton.addEventListener('click', handleChatMessageSubmition);

chatView.add(messageSendButton);
chatView.add(chatTableView);
chatView.add(messageField);

return chatView;
}

function createMessageRow(msg, time, name){
function handleChatMessageSubmition(e){
Ti.App.fireEvent(EVENT_FROM_CHAT, {from:username, message:messageField.value});

messageField.value = '';
messageField.blur();

chatView.animate({bottom:0, duration:200});
chatTableView.animate({height:IPHONE5 ? 421 : 324, duration:200});

//used setTimeout because sometimes, it wouldn't respond
var t = setTimeout(function(){
chatTableView.scrollToIndex(chatTableView.data[0].rows.length - 1);
},50);
}

function handleChatFieldFocus(){
chatView.animate({bottom:180, duration:300});
chatTableView.animate({height:IPHONE5 ? 236 : 140, duration:200});

//used setTimeout because sometimes, it wouldn't respond
var t = setTimeout(function(){
chatTableView.scrollToIndex(chatTableView.data[0].rows.length - 1);
},50);
}

function handleChatFieldBlur(){
chatView.animate({bottom:0, duration:200});
chatTableView.animate({height:IPHONE5 ? 421 : 324, duration:200});

//used setTimeout because sometimes, it wouldn't respond
var t = setTimeout(function(){
chatTableView.scrollToIndex(chatTableView.data[0].rows.length - 1);
},50);
}

function createMessageRow(msg, time, name, myMessage){
if(name == username){
myMessage = true;
}

var row = Ti.UI.createTableViewRow({
//height:75,
backgroundColor:'transparent',
width:'90%'
});

var photoView, messageView, timeLabel, msgLabel = null;

if(myMessage){
photoView = Ti.UI.createView({
right:2,
top:20,
backgroundColor:'white',
width:40,
height:40
});

timeLabel = Ti.UI.createLabel({
text:'2m ago',
color:'white',
top:65,
right:5,
textAlign:'center',
font:{fontSize:10, fontWeight:'bold', fontFamily:'Calibri'}
});

var msgLabelContainer = Titanium.UI.createView({
backgroundColor:COLOR_LIGHT_GREEN,
top:20,
bottom:15,
right:53,
width:Titanium.UI.SIZE,//214
height:Titanium.UI.SIZE,
borderWidth:1,
borderColor:COLOR_LIGHT_GREEN,
borderRadius:5
});

msgLabel = Ti.UI.createLabel({
text:msg,
color:'white',
top:5,
bottom:5,
left:10,
right:10,
color:'black',
height:'auto',
width:'auto',//184
textAlign:'left',
opacity:0.7,
font:{fontSize:12, fontWeight:'regular', fontFamily:'Calibri'}
});
} else {
photoView = Ti.UI.createView({
left:2,
top:20,
backgroundColor:'white',
width:40,
height:40
});

timeLabel = Ti.UI.createLabel({
text:'2m ago',
color:'white',
top:65,
left:5,
textAlign:'center',
font:{fontSize:10, fontWeight:'bold', fontFamily:'Calibri'}
});

var msgLabelContainer = Titanium.UI.createView({
backgroundColor:COLOR_LIGHT_RED,
top:20,
bottom:15,
left:53,
width:Titanium.UI.SIZE,//214
height:Titanium.UI.SIZE,
borderWidth:1,
borderColor:COLOR_LIGHT_RED,
borderRadius:5
});

msgLabel = Ti.UI.createLabel({
text:msg,
color:'white',
top:5,
bottom:5,
left:10,
right:10,
color:'black',
height:'auto',
width:'auto',//184
textAlign:'left',
opacity:0.7,
font:{fontSize:12, fontWeight:'regular', fontFamily:'Calibri'}
});
}

msgLabelContainer.add(msgLabel);

row.add(photoView);
row.add(timeLabel);
row.add(msgLabelContainer);

chatTableView.appendRow(row);
}
Binary file added Resources/images/iphone/tabs/chart_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/iphone/tabs/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/iphone/tabs/email_circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/images/iphone/tabs/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e714039

Please sign in to comment.