forked from Archives/Athou_commafeed
fix infinity scroll
This commit is contained in:
@@ -20,23 +20,39 @@ import com.commafeed.backend.model.FeedSubscription;
|
|||||||
import com.commafeed.frontend.model.Entries;
|
import com.commafeed.frontend.model.Entries;
|
||||||
import com.commafeed.frontend.model.Entry;
|
import com.commafeed.frontend.model.Entry;
|
||||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@Path("entries")
|
@Path("entries")
|
||||||
public class EntriesREST extends AbstractREST {
|
public class EntriesREST extends AbstractREST {
|
||||||
|
|
||||||
@Path("get/{type}/{id}/{readType}")
|
private static final String ALL = "all";
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
category, feed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ReadType {
|
||||||
|
all, unread;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Path("get")
|
||||||
@GET
|
@GET
|
||||||
public Entries getEntries(@PathParam("type") String type,
|
public Entries getEntries(@QueryParam("type") Type type,
|
||||||
@PathParam("id") String id, @PathParam("readType") String readType,
|
@QueryParam("id") String id,
|
||||||
|
@QueryParam("readType") ReadType readType,
|
||||||
@DefaultValue("0") @QueryParam("offset") int offset,
|
@DefaultValue("0") @QueryParam("offset") int offset,
|
||||||
@DefaultValue("-1") @QueryParam("limit") int limit) {
|
@DefaultValue("-1") @QueryParam("limit") int limit) {
|
||||||
|
|
||||||
Entries entries = new Entries();
|
Preconditions.checkNotNull(type);
|
||||||
boolean unreadOnly = "unread".equals(readType);
|
Preconditions.checkNotNull(id);
|
||||||
|
Preconditions.checkNotNull(readType);
|
||||||
|
|
||||||
if ("feed".equals(type)) {
|
Entries entries = new Entries();
|
||||||
|
boolean unreadOnly = readType == ReadType.unread;
|
||||||
|
|
||||||
|
if (type == Type.feed) {
|
||||||
FeedSubscription subscription = feedSubscriptionService.findById(
|
FeedSubscription subscription = feedSubscriptionService.findById(
|
||||||
getUser(), Long.valueOf(id));
|
getUser(), Long.valueOf(id));
|
||||||
entries.setName(subscription.getTitle());
|
entries.setName(subscription.getTitle());
|
||||||
@@ -44,13 +60,13 @@ public class EntriesREST extends AbstractREST {
|
|||||||
buildEntries(subscription, offset, limit, unreadOnly));
|
buildEntries(subscription, offset, limit, unreadOnly));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
FeedCategory feedCategory = "all".equals(id) ? null
|
FeedCategory feedCategory = ALL.equals(id) ? null
|
||||||
: feedCategoryService.findById(getUser(), Long.valueOf(id));
|
: feedCategoryService.findById(getUser(), Long.valueOf(id));
|
||||||
Collection<FeedSubscription> subscriptions = "all".equals(id) ? feedSubscriptionService
|
Collection<FeedSubscription> subscriptions = ALL.equals(id) ? feedSubscriptionService
|
||||||
.findAll(getUser()) : feedSubscriptionService
|
.findAll(getUser()) : feedSubscriptionService
|
||||||
.findWithCategory(getUser(), feedCategory);
|
.findWithCategory(getUser(), feedCategory);
|
||||||
|
|
||||||
entries.setName("all".equals(id) ? "All" : feedCategory.getName());
|
entries.setName(ALL.equals(id) ? ALL : feedCategory.getName());
|
||||||
for (FeedSubscription subscription : subscriptions) {
|
for (FeedSubscription subscription : subscriptions) {
|
||||||
entries.getEntries().addAll(
|
entries.getEntries().addAll(
|
||||||
buildEntries(subscription, offset, limit, unreadOnly));
|
buildEntries(subscription, offset, limit, unreadOnly));
|
||||||
@@ -67,11 +83,9 @@ public class EntriesREST extends AbstractREST {
|
|||||||
|
|
||||||
if (limit > -1) {
|
if (limit > -1) {
|
||||||
int size = entries.getEntries().size();
|
int size = entries.getEntries().size();
|
||||||
System.out.println(size);
|
|
||||||
int to = Math.min(size, limit);
|
int to = Math.min(size, limit);
|
||||||
List<Entry> subList = entries.getEntries().subList(0, to);
|
List<Entry> subList = entries.getEntries().subList(0, to);
|
||||||
entries.setEntries(Lists.newArrayList(subList));
|
entries.setEntries(Lists.newArrayList(subList));
|
||||||
System.out.println(entries.getEntries().size());
|
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,29 +104,34 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http,
|
|||||||
|
|
||||||
$scope.limit = 10;
|
$scope.limit = 10;
|
||||||
$scope.busy = false;
|
$scope.busy = false;
|
||||||
|
$scope.hasMore = true;
|
||||||
|
|
||||||
$scope.refreshList = function() {
|
$scope.refreshList = function() {
|
||||||
if ($scope.settings.readingMode) {
|
if ($scope.settings.readingMode) {
|
||||||
$scope.entryList = EntryService.get({
|
$scope.entryList = EntryService.get({
|
||||||
_type : $scope.selectedType,
|
type : $scope.selectedType,
|
||||||
_id : $scope.selectedId,
|
id : $scope.selectedId,
|
||||||
_readtype : $scope.settings.readingMode,
|
readType : $scope.settings.readingMode,
|
||||||
offset : 0,
|
offset : 0,
|
||||||
limit : $scope.limit
|
limit : 30
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.loadMoreEntries = function() {
|
$scope.loadMoreEntries = function() {
|
||||||
|
if(!$scope.hasMore)
|
||||||
|
return;
|
||||||
|
if (!$scope.entryList || !$scope.entryList.entries)
|
||||||
|
return;
|
||||||
if ($scope.busy)
|
if ($scope.busy)
|
||||||
return;
|
return;
|
||||||
if (!$scope.settings.readingMode)
|
if (!$scope.settings.readingMode)
|
||||||
return;
|
return;
|
||||||
$scope.busy = true;
|
$scope.busy = true;
|
||||||
EntryService.get({
|
EntryService.get({
|
||||||
_type : $scope.selectedType,
|
type : $scope.selectedType,
|
||||||
_id : $scope.selectedId,
|
id : $scope.selectedId,
|
||||||
_readtype : $scope.settings.readingMode,
|
readType : $scope.settings.readingMode,
|
||||||
offset : $scope.entryList.entries.length,
|
offset : $scope.entryList.entries.length,
|
||||||
limit : $scope.limit
|
limit : $scope.limit
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
@@ -135,9 +140,8 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http,
|
|||||||
for ( var i = 0; i < entries.length; i++) {
|
for ( var i = 0; i < entries.length; i++) {
|
||||||
$scope.entryList.entries.push(entries[i]);
|
$scope.entryList.entries.push(entries[i]);
|
||||||
}
|
}
|
||||||
console.log(entries.length)
|
|
||||||
console.log($scope.limit)
|
|
||||||
$scope.busy = false;
|
$scope.busy = false;
|
||||||
|
$scope.hasMore = entries.length == $scope.limit
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ module.factory('EntryService', [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
res = $resource('rest/entries/:_method/:_type/:_id/:_readtype', {},
|
res = $resource('rest/entries/:_method', {},
|
||||||
actions);
|
actions);
|
||||||
return res;
|
return res;
|
||||||
} ]);
|
} ]);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
{{readType}}
|
{{readType}}
|
||||||
<span>{{entryList.name}}</span><span
|
<span>{{entryList.name}}</span><span
|
||||||
ng-show="selectedType == 'category'"> »</span>
|
ng-show="selectedType == 'category'"> »</span>
|
||||||
<div id="feed-accordion" infinite-scroll="loadMoreEntries()" infinite-scroll-disabled="busy" infinite-scroll-distance="1">
|
<div class="accordion" id="feed-accordion" infinite-scroll="loadMoreEntries()" infinite-scroll-disabled="busy" infinite-scroll-distance="1">
|
||||||
<div ng-repeat="entry in entryList.entries">
|
<div ng-repeat="entry in entryList.entries" class="entry">
|
||||||
<div class="entry-heading">
|
<div class="entry-heading">
|
||||||
<a class="accordion-toggle" data-toggle="collapse"
|
<a class="accordion-toggle" data-toggle="collapse"
|
||||||
ng-click="mark(entry, true)"
|
ng-click="mark(entry, true)"
|
||||||
|
|||||||
Reference in New Issue
Block a user