Guest User

Untitled

a guest
Oct 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // this sets the background color of the master UIView (when there are no windows/tab groups on it)
  3. Titanium.UI.setBackgroundImage('Default.png');
  4.  
  5. /*globals Titanium, Ti, alert, JSON */
  6. Titanium.Facebook.appid = "171989632875493";
  7. Titanium.Facebook.permissions = ['publish_stream', 'read_stream'];
  8. // capture facebook login/out
  9. Titanium.Facebook.addEventListener('login', triggerFBLogin);
  10. Titanium.Facebook.addEventListener('logout', triggerFBLogout);
  11.  
  12. //deine windows to be used in application
  13. var pWin = Titanium.UI.createWindow({className:'pWin',zIndex: 1});
  14. var lWin = Titanium.UI.createWindow({
  15.     className:'lWin',
  16.     zIndex: 10,
  17.     backgroundImage:'images/loginbox.png',
  18.     height:118,
  19.     width:223,
  20.     bottom:32,
  21.     left: pWin.center.x-115,
  22. });
  23. var win1 = Titanium.UI.createWindow({className:'win1',zIndex: 5});
  24. var win2 = Titanium.UI.createWindow({className:'win2',zIndex: 5});
  25. var win3 = Titanium.UI.createWindow({className:'win3',zIndex: 5});
  26. var win4 = Titanium.UI.createWindow({className:'win4',zIndex: 5});
  27.  
  28. var loginLabel = Titanium.UI.createLabel({
  29.     text: 'Please login using Facebook to use MyCoCo...',
  30.     color: '#ffffff',
  31.     font: {fontSize:14},
  32.     width: 190,
  33.     height: 40,
  34.     top: 15,
  35.     left: 20
  36. });
  37. lWin.add(loginLabel);
  38.  
  39. // //global activity indicator
  40. var toolActInd = Titanium.UI.createActivityIndicator();
  41. toolActInd.style = Titanium.UI.iPhone.ActivityIndicatorStyle.PLAIN;
  42. toolActInd.font = {fontFamily:'Helvetica Neue', fontSize:15,fontWeight:'bold'};
  43. toolActInd.color = 'white';
  44. toolActInd.message = 'Loading...';
  45. pWin.setToolbar([toolActInd],{animated:true});
  46.  
  47. // Login Button
  48. lWin.add(Titanium.Facebook.createLoginButton({
  49.     style:'wide',
  50.     bottom:20
  51. }));
  52.  
  53.  
  54.  
  55. function checkLogin() {
  56.     if(Titanium.Facebook.loggedIn==false) {
  57.         MyCoCo.win_t1.close();
  58.         MyCoCo.win_t2.close();
  59.         MyCoCo.win_t3.close();
  60.         MyCoCo.win_t4.close();
  61.         MyCoCo.loginWin.open();
  62.     }
  63. }
  64.  
  65. function triggerFBLogin() {
  66.     MyCoCo.loginWin.close();
  67. }
  68.  
  69. function triggerFBLogout() {
  70.     MyCoCo.loginWin.open();
  71. }
  72.  
  73. //not really sure how to do this, so I'll try it this way, check every 10 seconds to ensure login is current
  74. checkLogin();
  75. setInterval('checkLogin',10000);
  76.  
  77. var bottomTabs = Titanium.UI.createTabGroup({
  78.     height: 40,
  79.     bottom: 0
  80. });
  81.  
  82.  
  83. // Create the individual tabs with titles and icons
  84. var tab1 = Titanium.UI.createTab({
  85.     window: win1,
  86.     icon: 'images/icons/112-group.png',
  87.     title:"FB Friends"
  88. });
  89.  
  90. var tab2 = Titanium.UI.createTab({
  91.     window: win2,
  92.     icon: 'images/icons/85-trophy.png',
  93.     title:"My CoCos"
  94. });
  95.  
  96. var tab3 = Titanium.UI.createTab({
  97.     window: win3,
  98.     icon: 'images/icons/86-camera.png',
  99.     title:"From Me"
  100. });
  101.  
  102. var tab4 = Titanium.UI.createTab({
  103.     window: win4,
  104.     icon: 'images/icons/20-gear2.png',
  105.     title:"Settings"
  106. });
  107.  
  108.  
  109. bottomTabs.addTab(tab1);
  110. bottomTabs.addTab(tab2);
  111. bottomTabs.addTab(tab3);
  112. bottomTabs.addTab(tab4);
  113. bottomTabs.open();
  114.  
  115. tab1.addEventListener('focus',function() {
  116.     win1.open();
  117.     toolActInd.show();
  118.    
  119.     var tableView = Titanium.UI.createTableView({minRowHeight:100});
  120.     win1.add(tableView);
  121.  
  122.     // create close button on window nav
  123.     var close = Titanium.UI.createButton({
  124.         title:'Close'
  125.     });
  126.     close.addEventListener('click', function()
  127.     {
  128.         win1.close();
  129.     });
  130.     if (Titanium.Platform.osname == 'iphone' || Titanium.Platform.osname == 'ipad') {
  131.         win1.setRightNavButton(close);
  132.     }
  133.  
  134.     // run query, populate table view and open window
  135.     var query = "SELECT uid, name, pic_square, status FROM user ";
  136.     query +=  "where uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + ")";
  137.     query += "order by last_name limit 20";
  138.     Titanium.API.info('user id ' + Titanium.Facebook.uid);
  139.     Titanium.Facebook.request('fql.query', {query: query},  function(r)
  140.     {
  141.         if (!r.success) {
  142.             if (r.error) {
  143.                 alert(r.error);
  144.             } else {
  145.                 alert("call was unsuccessful");
  146.             }
  147.             return;
  148.         }
  149.         var result = JSON.parse(r.result);
  150.         var data = [];
  151.         for (var c=0;c<result.length;c++)
  152.         {
  153.             var row = result[c];
  154.  
  155.             var tvRow = Titanium.UI.createTableViewRow({
  156.                 height:'auto',
  157.                 selectedBackgroundColor:'#fff',
  158.                 backgroundColor:'#fff'
  159.             });
  160.             var imageView;
  161.             imageView = Titanium.UI.createImageView({
  162.                 image:row.pic_square === null ? '../images/custom_tableview/user.png' : row.pic_square,
  163.                 left:10,
  164.                 width:50,
  165.                 height:50
  166.             });
  167.  
  168.             tvRow.add(imageView);
  169.  
  170.             var userLabel = Titanium.UI.createLabel({
  171.                 font:{fontSize:16, fontWeight:'bold'},
  172.                 left:70,
  173.                 top:5,
  174.                 right:5,
  175.                 height:20,
  176.                 color:'#576996',
  177.                 text:row.name
  178.             });
  179.             tvRow.add(userLabel);
  180.  
  181.             var statusLabel = Titanium.UI.createLabel({
  182.                 font:{fontSize:13},
  183.                 left:70,
  184.                 top:25,
  185.                 right:20,
  186.                 height:'auto',
  187.                 color:'#222',
  188.                 text:(!row.status || !row.status.message ? 'No status message' : row.status.message)
  189.             });
  190.             tvRow.add(statusLabel);
  191.  
  192.             tvRow.uid = row.uid;
  193.  
  194.             data[c] = tvRow;
  195.         }
  196.        
  197.         tableView.setData(data, { animationStyle : Titanium.UI.iPhone.RowAnimationStyle.DOWN });
  198.        
  199.         win1.open();
  200.     });
  201. })
Add Comment
Please, Sign In to add comment