diff options
| author | Anqi Xu | 2012-06-24 05:58:53 -0400 | 
|---|---|---|
| committer | Anqi Xu | 2012-06-24 05:58:53 -0400 | 
| commit | ffb4f153ba3578fdfcf4a16c1d0302b026addab0 (patch) | |
| tree | 889964a621c2a4d8c31118172258cea53ad060cd | |
| parent | 285771476af58db4b2b0839059f11e9ab0dfa90b (diff) | |
| download | LikeFeed-ffb4f153ba3578fdfcf4a16c1d0302b026addab0.tar.bz2 | |
Added infinite scrolling
| -rw-r--r-- | Resources/friendship/core/DataManipulation.js | 1 | ||||
| -rw-r--r-- | Resources/friendship/friendship.js | 2 | ||||
| -rw-r--r-- | Resources/friendship/ui/LikeList.js | 29 | 
3 files changed, 21 insertions, 11 deletions
| diff --git a/Resources/friendship/core/DataManipulation.js b/Resources/friendship/core/DataManipulation.js index e582ed9..ae18a89 100644 --- a/Resources/friendship/core/DataManipulation.js +++ b/Resources/friendship/core/DataManipulation.js @@ -5,4 +5,5 @@  	fs.data.reverseChronoLikedIDs = Array();  	fs.data.numLikesFetched = 0;  	fs.data.NUM_LIKES_PER_FETCH = 20; +	fs.data.isQueryingMore = false;  })();
\ No newline at end of file diff --git a/Resources/friendship/friendship.js b/Resources/friendship/friendship.js index fd61403..0e785e7 100644 --- a/Resources/friendship/friendship.js +++ b/Resources/friendship/friendship.js @@ -1,7 +1,9 @@  var fs = {}; +  (function() {  	fs.app = {}; +	fs.app.isAndroid = (Ti.Platform.osname === 'android');  })();  Ti.include( diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js index 187848c..0d49d74 100644 --- a/Resources/friendship/ui/LikeList.js +++ b/Resources/friendship/ui/LikeList.js @@ -226,6 +226,7 @@  				}  			} +			ll_view.setData(Array());  			if (e.data.length > 0) {			  				var tuples = []; @@ -246,8 +247,10 @@  	   			ll_view.footerTitle = "0 / " + fs.data.reverseChronoLikedIDs.length + " loaded"; +	   			fs.data.isQueryingMore = true;  	   			fs.core.fetchMoreLikes(fs.data.NUM_LIKES_PER_FETCH);  	   		} else { +	   			fs.data.isQueryingMore = false;  	   			ll_view.footerTitle = "0 / 0 loaded";  				Ti.App.fireEvent('app:hide.loader');  	   		}  @@ -260,20 +263,24 @@  			}    			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) +  			fs.data.isQueryingMore = false; +  			Ti.App.fireEvent('app:hide.loader');  		}); -		ll_view.addEventListener("scrollEnd", function(e) { -			Ti.API.info("scroll ended"); -			Ti.API.info(e.contentOffset.y); -			Ti.API.info(ll_view.height); -		}); +		ll_view.addEventListener("scroll", function(e) { +			if (fs.app.isAndroid && (e.totalItemCount < e.firstVisibleItem + e.visibleItemCount + 3) +            		|| (!fs.app.isAndroid && (e.contentOffset.y + e.size.height + 100 > e.contentSize.height))) { +        		if (fs.data.numLikesFetched < fs.data.reverseChronoLikedIDs.length) { +        			if (!fs.data.isQueryingMore) { +            			fs.data.isQueryingMore = true; +						fs.core.fetchMoreLikes(fs.data.NUM_LIKES_PER_FETCH); +        			} +        		} else { +        			fs.data.isQueryingMore = false; +        		} +            } +	    });  		return ll_view;  	}; | 
