From 4b92e87d0e33800ceb2b8c2de2b3ddab35512dc5 Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 03:26:48 -0400
Subject: Restoring info
---
Resources/friendship/ui/LikeList.js | 41 ++++---------------------------------
1 file changed, 4 insertions(+), 37 deletions(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index 93a7814..eb16bfc 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -19,10 +19,9 @@
pic_square: "images/fb_test_profile.jpg",
name: "Test Name",
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
- fan_count: "1000000000000000",
page_url: "http://www.google.com",
website: "http://www.google.com",
- type: "SHOW"
+ website: "http://www.google.com"
} )
);
@@ -33,8 +32,6 @@
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
fan_count: "2",
page_url: "http://www.google.com",
- website: "http://www.google.com",
- type: "BOOK"
} )
);
}
@@ -86,44 +83,16 @@
top: 0,
opacity:0.65,
left: 0,
- height:'12'
});
fan_c.top = 50-fan_c.height;
if( fan_c.width < 10 ) fan_c.width = 10;
-
- var item_type = Ti.UI.createLabel({
- text: " " + key.type + " ",
- font:{fontSize:11,fontWeight:'single'},
- color:'white',
- backgroundColor: '#b0d3a4',
- width:'auto',
- textAlign:'left',
- top:2,
- left: profile_icon.width + 2,
- height:'auto'
- });
-
- var liked_by = Ti.UI.createLabel({
- text: " Friend Bob ",
- font:{fontSize:11,fontWeight:'bold'},
- color: 'white',
- backgroundColor:"#d1d5e0",
- width:'auto',
- textAlign:'left',
- top:2,
- left: item_type.left + item_type.width + 2,
- height:'auto'
- });
-
var title = Ti.UI.createLabel({
text:key.name,
font:{fontSize:12,fontWeight:'bold'},
width:'auto',
textAlign:'left',
- top:item_type.height + 2,
- left: profile_icon.width + 4,
height:'auto',
wordWrap:'true'
});
@@ -136,20 +105,18 @@
font:{fontSize:12,fontWeight:'single'},
width:'auto',
textAlign:'left',
- top: title.top + title.height-5,
- left:profile_icon.width + 4
+ wordWrap:'true',
});
row.height = 50;
+ row.height = 'auto';
row.add( profile_icon );
// row.add( thumb_icon );
row.add(fan_c);
row.add( title );
- row.add(liked_by);
- row.add( item_type );
row.add( description );
return row;
@@ -157,11 +124,11 @@
fs.ui.createLikeList = function() {
var ll_view = Ti.UI.createTableView();
+ ll_view.maxRowHeight = 150;
var loading = fs.ui.createLoadingView();
ll_view.add(loading);
- add_test_data( ll_view );
//Ti.App.fireEvent('app:show.loader');
--
cgit v1.2.3
From 7d09ade1b740113be512b95cce9a4ed958ae7a27 Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 03:27:13 -0400
Subject: Again
---
Resources/friendship/ui/LikeList.js | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index eb16bfc..3978eb2 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -19,8 +19,8 @@
pic_square: "images/fb_test_profile.jpg",
name: "Test Name",
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
+ fan_count: "15",
page_url: "http://www.google.com",
- website: "http://www.google.com",
website: "http://www.google.com"
} )
);
@@ -32,6 +32,7 @@
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
fan_count: "2",
page_url: "http://www.google.com",
+ website: "http://www.google.com"
} )
);
}
@@ -83,6 +84,7 @@
top: 0,
opacity:0.65,
left: 0,
+ height:'auto'
});
fan_c.top = 50-fan_c.height;
@@ -93,11 +95,12 @@
font:{fontSize:12,fontWeight:'bold'},
width:'auto',
textAlign:'left',
+ top:2,
+ left: profile_icon.width + 2,
height:'auto',
wordWrap:'true'
});
-
key.description = key.description.replace(/<(?:.|\n)*?>/gm, '');
var description = Ti.UI.createLabel({
@@ -105,12 +108,15 @@
font:{fontSize:12,fontWeight:'single'},
width:'auto',
textAlign:'left',
+ top: title.height - 1,
+ left:profile_icon.width + 2,
+ height:36,
wordWrap:'true',
+ html:true
});
- row.height = 50;
row.height = 'auto';
row.add( profile_icon );
@@ -129,8 +135,7 @@
var loading = fs.ui.createLoadingView();
ll_view.add(loading);
-
- //Ti.App.fireEvent('app:show.loader');
+ // Ti.App.fireEvent('app:show.loader');
Ti.API.addEventListener("processPosts", function(d) {
for ( key in d.data ) {
--
cgit v1.2.3
From f5ea30dacb5c8c1681ad73454e6193b3d06da8bd Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 03:29:14 -0400
Subject: Revert "Again"
This reverts commit 7d09ade1b740113be512b95cce9a4ed958ae7a27.
---
Resources/friendship/ui/LikeList.js | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index 3978eb2..eb16bfc 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -19,8 +19,8 @@
pic_square: "images/fb_test_profile.jpg",
name: "Test Name",
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
- fan_count: "15",
page_url: "http://www.google.com",
+ website: "http://www.google.com",
website: "http://www.google.com"
} )
);
@@ -32,7 +32,6 @@
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
fan_count: "2",
page_url: "http://www.google.com",
- website: "http://www.google.com"
} )
);
}
@@ -84,7 +83,6 @@
top: 0,
opacity:0.65,
left: 0,
- height:'auto'
});
fan_c.top = 50-fan_c.height;
@@ -95,12 +93,11 @@
font:{fontSize:12,fontWeight:'bold'},
width:'auto',
textAlign:'left',
- top:2,
- left: profile_icon.width + 2,
height:'auto',
wordWrap:'true'
});
+
key.description = key.description.replace(/<(?:.|\n)*?>/gm, '');
var description = Ti.UI.createLabel({
@@ -108,15 +105,12 @@
font:{fontSize:12,fontWeight:'single'},
width:'auto',
textAlign:'left',
- top: title.height - 1,
- left:profile_icon.width + 2,
- height:36,
wordWrap:'true',
- html:true
});
+ row.height = 50;
row.height = 'auto';
row.add( profile_icon );
@@ -135,7 +129,8 @@
var loading = fs.ui.createLoadingView();
ll_view.add(loading);
- // Ti.App.fireEvent('app:show.loader');
+
+ //Ti.App.fireEvent('app:show.loader');
Ti.API.addEventListener("processPosts", function(d) {
for ( key in d.data ) {
--
cgit v1.2.3
From 5a3c15c887f1d13e6ad7a22abc1018cbb6ac1a97 Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 03:30:19 -0400
Subject: Revert "Restoring info"
This reverts commit 4b92e87d0e33800ceb2b8c2de2b3ddab35512dc5.
---
Resources/friendship/ui/LikeList.js | 41 +++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index eb16bfc..93a7814 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -19,9 +19,10 @@
pic_square: "images/fb_test_profile.jpg",
name: "Test Name",
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
+ fan_count: "1000000000000000",
page_url: "http://www.google.com",
website: "http://www.google.com",
- website: "http://www.google.com"
+ type: "SHOW"
} )
);
@@ -32,6 +33,8 @@
description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
fan_count: "2",
page_url: "http://www.google.com",
+ website: "http://www.google.com",
+ type: "BOOK"
} )
);
}
@@ -83,16 +86,44 @@
top: 0,
opacity:0.65,
left: 0,
+ height:'12'
});
fan_c.top = 50-fan_c.height;
if( fan_c.width < 10 ) fan_c.width = 10;
+
+ var item_type = Ti.UI.createLabel({
+ text: " " + key.type + " ",
+ font:{fontSize:11,fontWeight:'single'},
+ color:'white',
+ backgroundColor: '#b0d3a4',
+ width:'auto',
+ textAlign:'left',
+ top:2,
+ left: profile_icon.width + 2,
+ height:'auto'
+ });
+
+ var liked_by = Ti.UI.createLabel({
+ text: " Friend Bob ",
+ font:{fontSize:11,fontWeight:'bold'},
+ color: 'white',
+ backgroundColor:"#d1d5e0",
+ width:'auto',
+ textAlign:'left',
+ top:2,
+ left: item_type.left + item_type.width + 2,
+ height:'auto'
+ });
+
var title = Ti.UI.createLabel({
text:key.name,
font:{fontSize:12,fontWeight:'bold'},
width:'auto',
textAlign:'left',
+ top:item_type.height + 2,
+ left: profile_icon.width + 4,
height:'auto',
wordWrap:'true'
});
@@ -105,18 +136,20 @@
font:{fontSize:12,fontWeight:'single'},
width:'auto',
textAlign:'left',
- wordWrap:'true',
+ top: title.top + title.height-5,
+ left:profile_icon.width + 4
});
row.height = 50;
- row.height = 'auto';
row.add( profile_icon );
// row.add( thumb_icon );
row.add(fan_c);
row.add( title );
+ row.add(liked_by);
+ row.add( item_type );
row.add( description );
return row;
@@ -124,11 +157,11 @@
fs.ui.createLikeList = function() {
var ll_view = Ti.UI.createTableView();
- ll_view.maxRowHeight = 150;
var loading = fs.ui.createLoadingView();
ll_view.add(loading);
+ add_test_data( ll_view );
//Ti.App.fireEvent('app:show.loader');
--
cgit v1.2.3
From 1c456114ad34a952b7b7d54fec2240d187b7321b Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 03:30:55 -0400
Subject: Committing
---
Resources/friendship/ui/LikeList.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index 93a7814..c43d6e6 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -116,7 +116,7 @@
left: item_type.left + item_type.width + 2,
height:'auto'
});
-
+
var title = Ti.UI.createLabel({
text:key.name,
font:{fontSize:12,fontWeight:'bold'},
--
cgit v1.2.3
From 8e4f2232fb36024dc931bdc25389f92d55cdef7c Mon Sep 17 00:00:00 2001
From: Anqi Xu
Date: Sun, 24 Jun 2012 03:46:50 -0400
Subject: Started sequential FQL queries coding
---
Resources/friendship/core/FacebookFQL.js | 38 ++++++++++++++++++++--------
Resources/friendship/core/core.js | 2 ++
Resources/friendship/ui/ApplicationWindow.js | 14 +++++++++-
Resources/friendship/ui/LikeList.js | 27 +++++++++++++++-----
Resources/friendship/ui/LoginWindow.js | 5 ++--
5 files changed, 67 insertions(+), 19 deletions(-)
diff --git a/Resources/friendship/core/FacebookFQL.js b/Resources/friendship/core/FacebookFQL.js
index 2d04bcb..e93abb0 100644
--- a/Resources/friendship/core/FacebookFQL.js
+++ b/Resources/friendship/core/FacebookFQL.js
@@ -16,15 +16,33 @@
}
}; // TODO: find some way to handle timeout (via Ti.Facebook....)
- fs.core.handleAllFriendPostsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processPosts"); };
- fs.core.queryAllFriendPostsFQL = function() { // TODO: make a variant that takes in user list and other filter info
+ fs.core.handleFriendIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processFriendIDs"); };
+ fs.core.queryFriendIDsFQL = function() {
+ var query = "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")"
+ Ti.Facebook.request('fql.query', {query: query}, fs.core.handleFriendIDsFQLResponse);
+ };
+
+ fs.core.handleLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); };
+ fs.core.queryLikeIDsFQL = function(friend_ids) {
+ var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (" + friend_ids.join() + ")";
+ Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikeIDsFQLResponse);
+ };
+
+ fs.core.handleAllFriendLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); };
+ fs.core.queryAllFriendLikeIDsFQL = function() {
+ var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")";
+ Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendLikeIDsFQLResponse);
+ };
+
+ fs.core.handleLikesFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikes"); };
+ fs.core.queryLikesFQL = function(page_ids) {
+ //var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info ";
+ //query += "FROM page WHERE page_id ";
+ //query += "IN (SELECT page_id FROM page_fan WHERE uid ";
+ //query += "IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + "))";
+ //query += " limit 20";
var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info ";
- query += "FROM page WHERE page_id ";
- query += "IN (SELECT page_id FROM page_fan WHERE uid ";
- //query += "= " + Ti.Facebook.uid + ")";
- query += "IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + "))";
- query += " limit 20"; // TODO: remove the limit
- Ti.API.info(query); // TODO: remove debug printout
- Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendPostsFQLResponse);
- };
+ query += "FROM page WHERE page_id IN (" + page_ids.join() + ")";
+ Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikesFQLResponse);
+ };
})();
diff --git a/Resources/friendship/core/core.js b/Resources/friendship/core/core.js
index dd75086..a1f150c 100644
--- a/Resources/friendship/core/core.js
+++ b/Resources/friendship/core/core.js
@@ -1,5 +1,7 @@
(function() {
fs.core = {};
+ fs.data = {};
+ fs.data.friends = Array();
})();
Ti.include(
diff --git a/Resources/friendship/ui/ApplicationWindow.js b/Resources/friendship/ui/ApplicationWindow.js
index a88990d..b07838e 100644
--- a/Resources/friendship/ui/ApplicationWindow.js
+++ b/Resources/friendship/ui/ApplicationWindow.js
@@ -27,7 +27,19 @@
});
win.add(fs.ui.createLikeList());
- fs.ui.refreshLikeList();
+
+ Ti.API.addEventListener("processFQLError", function(e) {
+ alert(e.what);
+ });
+
+ Ti.API.addEventListener("refreshAllData", function(e) {
+ if (Ti.Facebook.loggedIn) {
+ Ti.App.fireEvent('app:show.loader');
+ fs.core.queryFriendIDsFQL();
+ }
+ })
+ Ti.API.fireEvent("refreshAllData");
+
tab_group.addTab(tab);
return tab_group;
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index 8440e01..775c408 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -136,11 +136,28 @@
// Ti.App.fireEvent('app:show.loader');
- Ti.API.addEventListener("processPosts", function(d) {
- for ( key in d.data ) {
- ll_view.appendRow( create_row( d.data[key] ) );
+ Ti.API.addEventListener("processFriendIDs", function(e) {
+ fs.data.friends = e.data;
+ fs.core.queryAllFriendLikeIDsFQL();
+ });
+
+ Ti.API.addEventListener("processLikeIDs", function(e) {
+ Ti.API.info("processLikeIDs");
+ Ti.API.info(e.data);
+ for ( key in e.data ) {
+ // TODO: 0 go through all the page_ids and insert into a hashset/dictionary; update with latest create_time, and also ++; sort by latest time <- pbly need priority set, or jus filter after fact
+ //e.data[key].page_id
+ //e.data[key].created_time
}
+ // TODO: disable the hide loader, and start slowly loading processLikes
+ Ti.App.fireEvent('app:hide.loader');
+ });
+
+ Ti.API.addEventListener("processLikes", function(e) {
+ for ( key in e.data ) {
+ ll_view.appendRow(create_row(e.data[key]));
+ }
Ti.App.fireEvent('app:hide.loader');
});
@@ -150,9 +167,7 @@
fs.ui.refreshLikeList = function(e) {
if (Ti.Facebook.loggedIn) {
Ti.App.fireEvent('app:show.loader');
- fs.core.queryAllFriendPostsFQL();
- } else {
- Ti.Facebook.fireEvent('login');
+ fs.core.queryAllFriendLikeIDsFQL(); // TODO: switch to friend_ids version of query
}
};
})();
diff --git a/Resources/friendship/ui/LoginWindow.js b/Resources/friendship/ui/LoginWindow.js
index c6103ff..4593f82 100644
--- a/Resources/friendship/ui/LoginWindow.js
+++ b/Resources/friendship/ui/LoginWindow.js
@@ -6,6 +6,7 @@
Ti.Facebook.addEventListener('login', function(e) {
if (e.success) {
fs.app.mainTabGroup.open();
+ Ti.API.fireEvent("refreshAllData");
} else {
alert('Could not log into Facebook');
}
@@ -40,6 +41,6 @@
win.add(view);
return tab_group;
- }
-
+ };
+
})();
--
cgit v1.2.3
From f611d5cb2985e70a23646b0c1e0883c9b7782137 Mon Sep 17 00:00:00 2001
From: Anqi Xu
Date: Sun, 24 Jun 2012 03:48:31 -0400
Subject: ignore this
---
tiapp.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tiapp.xml b/tiapp.xml
index 9cc4a2f..6c7786d 100644
--- a/tiapp.xml
+++ b/tiapp.xml
@@ -7,7 +7,7 @@
false
false
- 1.6.2
+ 2.0.2.GA
com.likefeed.LikeFeed
LikeFeed
1.0
--
cgit v1.2.3
From 8d7e851d37aef8599403670e3eaabb5745c2c567 Mon Sep 17 00:00:00 2001
From: Nikita Bernstein
Date: Sun, 24 Jun 2012 04:40:19 -0400
Subject: More formatting
---
Resources/friendship/ui/LikeList.js | 65 +++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 17 deletions(-)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index c00ccff..c9004f6 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -1,4 +1,20 @@
(function() {
+ var MAX_ROW_HEIGHT = 150;
+ var lookup = {
+ 'BOOK':'#b0d3a4',
+ 'SHOW':'#c7b0b5',
+ 'MUSICIAN/BAND':'#c7bbb0',
+ 'MOVIE':'#ccc399',
+ 'TV SHOW':'#5c9aa7'
+ };
+
+ function getTypeColor(type_str)
+ {
+ var r = lookup[type_str];
+ if( r ) return r;
+ return '#bbbbbb';
+ }
+
function addCommas(nStr)
{
nStr += '';
@@ -18,7 +34,7 @@
create_row( {
pic_square: "images/fb_test_profile.jpg",
name: "Test Name",
- description: "Description Description Description Description Description Description Description Description Description Description Description Description ",
+ description: "Description Description Description. Description Description Description Description Description Description Description Description Description ",
fan_count: "1000000000000000",
page_url: "http://www.google.com",
website: "http://www.google.com",
@@ -97,25 +113,13 @@
text: " " + key.type + " ",
font:{fontSize:11,fontWeight:'single'},
color:'white',
- backgroundColor: '#b0d3a4',
+ backgroundColor: getTypeColor( key.type ),
width:'auto',
textAlign:'left',
top:2,
left: profile_icon.width + 2,
height:'auto'
});
-
- var liked_by = Ti.UI.createLabel({
- text: " Friend Bob ",
- font:{fontSize:11,fontWeight:'bold'},
- color: 'white',
- backgroundColor:"#d1d5e0",
- width:'auto',
- textAlign:'left',
- top:2,
- left: item_type.left + item_type.width + 2,
- height:'auto'
- });
var title = Ti.UI.createLabel({
text:key.name,
@@ -128,21 +132,46 @@
wordWrap:'true'
});
+ var liked_by = Ti.UI.createLabel({
+ text: " Friend Bob ",
+ font:{fontSize:11,fontWeight:'single'},
+
+ //color: 'white',
+ //backgroundColor:"#d1d5e0",
+
+ color: '#aaaaaa',
+
+ width:'auto',
+ textAlign:'left',
+ top:2,
+ height:'auto'
+ });
+
+ liked_by.left = 320 - liked_by.width;
key.description = key.description.replace(/<(?:.|\n)*?>/gm, '');
+ if( key.description.indexOf('.') > 0 ){
+ key.description = key.description.substr( 0, key.description.indexOf('.') + 1 ) ;
+ }
var description = Ti.UI.createLabel({
text:key.description,
font:{fontSize:12,fontWeight:'single'},
width:'auto',
textAlign:'left',
- top: title.top + title.height-5,
- left:profile_icon.width + 4
+ top: title.top + title.height,
+ left:profile_icon.width + 4,
+ height:'auto',
+ wordWrap:true
});
+ var max_height = MAX_ROW_HEIGHT - description.top;
+
+ if( description.height > max_height ) description.height = max_height;
+
- row.height = 50;
+ row.height = 'auto';
row.add( profile_icon );
// row.add( thumb_icon );
@@ -151,12 +180,14 @@
row.add(liked_by);
row.add( item_type );
row.add( description );
+
return row;
}
fs.ui.createLikeList = function() {
var ll_view = Ti.UI.createTableView();
+ ll_view.maxRowHeight = MAX_ROW_HEIGHT;
var loading = fs.ui.createLoadingView();
ll_view.add(loading);
--
cgit v1.2.3
From cd67bf9b30d6d787695ac4dc9d85b3289819527a Mon Sep 17 00:00:00 2001
From: Anqi Xu
Date: Sun, 24 Jun 2012 05:31:06 -0400
Subject: Added loading-by-20-items feature
---
Resources/friendship/core/FacebookFQL.js | 13 +++++-
Resources/friendship/core/core.js | 5 +--
Resources/friendship/ui/LikeList.js | 73 +++++++++++++++++++++++++++-----
3 files changed, 76 insertions(+), 15 deletions(-)
diff --git a/Resources/friendship/core/FacebookFQL.js b/Resources/friendship/core/FacebookFQL.js
index e93abb0..9a011aa 100644
--- a/Resources/friendship/core/FacebookFQL.js
+++ b/Resources/friendship/core/FacebookFQL.js
@@ -24,13 +24,13 @@
fs.core.handleLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); };
fs.core.queryLikeIDsFQL = function(friend_ids) {
- var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (" + friend_ids.join() + ")";
+ var query = "SELECT page_id, created_time, uid FROM page_fan WHERE uid IN (" + friend_ids.join() + ")";
Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikeIDsFQLResponse);
};
fs.core.handleAllFriendLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); };
fs.core.queryAllFriendLikeIDsFQL = function() {
- var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")";
+ var query = "SELECT page_id, created_time, uid FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")";
Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendLikeIDsFQLResponse);
};
@@ -45,4 +45,13 @@
query += "FROM page WHERE page_id IN (" + page_ids.join() + ")";
Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikesFQLResponse);
};
+
+ fs.core.fetchMoreLikes = function(numLikesMore) {
+ numLikesMore = Math.min((fs.data.reverseChronoLikedIDs.length - fs.data.numLikesFetched), numLikesMore);
+ page_ids = Array();
+ for (var i = fs.data.numLikesFetched; i < fs.data.numLikesFetched + numLikesMore; i++) {
+ page_ids.push(fs.data.reverseChronoLikedIDs[i]);
+ }
+ fs.core.queryLikesFQL(page_ids);
+ };
})();
diff --git a/Resources/friendship/core/core.js b/Resources/friendship/core/core.js
index a1f150c..fe6cb00 100644
--- a/Resources/friendship/core/core.js
+++ b/Resources/friendship/core/core.js
@@ -1,9 +1,8 @@
(function() {
fs.core = {};
- fs.data = {};
- fs.data.friends = Array();
})();
Ti.include(
- '/friendship/core/FacebookFQL.js'
+ '/friendship/core/FacebookFQL.js',
+ '/friendship/core/DataManipulation.js'
)
diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js
index c00ccff..0e9e784 100644
--- a/Resources/friendship/ui/LikeList.js
+++ b/Resources/friendship/ui/LikeList.js
@@ -153,7 +153,11 @@
row.add( description );
return row;
- }
+ };
+
+ function sortLikeIDsByTime(a, b) { // TODO: deprecated
+ return ((a.time > b.time) ? -1 : ((a.time < b.time) ? 1 : 0));
+ };
fs.ui.createLikeList = function() {
var ll_view = Ti.UI.createTableView();
@@ -171,24 +175,73 @@
});
Ti.API.addEventListener("processLikeIDs", function(e) {
- Ti.API.info("processLikeIDs");
- Ti.API.info(e.data);
+ fs.data.likeIDs = Array();
+ fs.data.reverseChronoLikedIDs = Array();
+
for ( key in e.data ) {
- // TODO: 0 go through all the page_ids and insert into a hashset/dictionary; update with latest create_time, and also ++; sort by latest time <- pbly need priority set, or jus filter after fact
- //e.data[key].page_id
- //e.data[key].created_time
+ pid = e.data[key].page_id + '';
+ tm = e.data[key].created_time;
+ uid = e.data[key].uid;
+
+ if (pid in fs.data.likeIDs) {
+ fs.data.likeIDs[pid].count += 1;
+
+ if (tm >= fs.data.likeIDs[pid].time) {
+ fs.data.likeIDs[pid].time = tm;
+ fs.data.likeIDs[pid].uid = uid;
+ }
+ } else {
+ fs.data.likeIDs[pid] = {count: 1, time: tm, uid: uid};
+ }
}
-
- // TODO: disable the hide loader, and start slowly loading processLikes
- Ti.App.fireEvent('app:hide.loader');
+
+ if (e.data.length > 0) {
+ var tuples = [];
+
+ for (var key in fs.data.likeIDs) {
+ tuples.push([key, fs.data.likeIDs[key]]);
+ }
+ tuples.sort(function(a, b) {
+ a = a[1].time;
+ b = b[1].time;
+ return a < b ? 1 : (a > b ? -1 : 0);
+ });
+
+ for (var i = 0; i < tuples.length; i++) {
+ fs.data.reverseChronoLikedIDs.push(tuples[i][0]);
+ //Ti.API.info(tuples[i][0] + ' ' + tuples[i][1].time);
+ }
+ fs.data.numLikesFetched = 0;
+
+ ll_view.footerTitle = "0 / " + fs.data.reverseChronoLikedIDs.length + " loaded";
+
+ fs.core.fetchMoreLikes(fs.data.NUM_LIKES_PER_FETCH);
+ } else {
+ ll_view.footerTitle = "0 / 0 loaded";
+ Ti.App.fireEvent('app:hide.loader');
+ }
});
Ti.API.addEventListener("processLikes", function(e) {
for ( key in e.data ) {
+ fs.data.numLikesFetched++;
ll_view.appendRow(create_row(e.data[key]));
- }
+ }
+
+ ll_view.footerTitle = fs.data.numLikesFetched + " / " + fs.data.reverseChronoLikedIDs.length + " loaded";
+ /*
+ if (fs.data.numLikesFetched < fs.data.reverseChronoLikedIDs.length) {
+ fs.core.fetchMoreLikes(fs.data.NUM_LIKES_PER_FETCH);
+ }
+ */
+ // TODO: when UI scrolls to bottom, can call this (might need mutex)
Ti.App.fireEvent('app:hide.loader');
});
+
+ ll_view.addEventListener("scrollEnd", function(e) {
+ Ti.API.info("scroll ended");
+ Ti.API.info(e.contentOffset);
+ });
return ll_view;
};
--
cgit v1.2.3