No more infinity post loading!

Loading should posts now stops if we could not load any new posts. This is particularly important, because previously the app made WAY TOO MANY requests.
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2023-07-27 08:22:34 +02:00
parent 3b5852d1e4
commit efc74a074c
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58

View File

@ -191,9 +191,19 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
if (newPosts == null) {
return new LoadResult.Error<>(new Exception("Error parsing posts"));
} else {
List<Post> trulyNewPosts = new ArrayList<>();
for (Post post : newPosts) {
if (!postLinkedHashSet.contains(post)) {
trulyNewPosts.add(post);
}
}
int currentPostsSize = postLinkedHashSet.size();
postLinkedHashSet.addAll(newPosts);
int nextKey = (postLinkedHashSet.size()+1) / 25+1;
postLinkedHashSet.addAll(trulyNewPosts);
int nextKey = ++page;
if (trulyNewPosts.size() == 0) {
return new LoadResult.Page<>(new ArrayList<>(), null, null);
}
if (currentPostsSize == postLinkedHashSet.size()) {
return new LoadResult.Page<>(new ArrayList<>(), null, nextKey);
} else {