From c86408dbe56a27fbf66f06c0d799145437d88fe9 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 5 Nov 2022 14:31:58 +1100 Subject: Fix history posts problems. --- .../infinityforreddit/activities/ViewPostDetailActivity.java | 4 ++-- .../infinityforreddit/post/HistoryPostPagingSource.java | 4 ++-- .../docilealligator/infinityforreddit/readpost/ReadPostDao.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index c759d06a..3a59798d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -373,7 +373,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { @Override public void onPageSelected(int position) { - if (position > posts.size() - 5) { + if (posts != null && position > posts.size() - 5) { fetchMorePosts(); } } @@ -663,7 +663,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele }); } else { mExecutor.execute((Runnable) () -> { - long lastItem = posts.isEmpty() ? System.currentTimeMillis() : posts.get(posts.size() - 1).getPostTimeMillis(); + long lastItem = posts.isEmpty() ? 0 : posts.get(posts.size() - 1).getPostTimeMillis(); List readPosts = mRedditDataRoomDatabase.readPostDao().getAllReadPosts(username, lastItem); StringBuilder ids = new StringBuilder(); for (ReadPost readPost : readPosts) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java index c89f7161..ada5ce11 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostPagingSource.java @@ -111,8 +111,8 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource> loadHomePosts(@NonNull LoadParams loadParams, RedditDataRoomDatabase redditDataRoomDatabase) { - String before = loadParams.getKey(); - ListenableFuture> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, Long.parseLong(before == null ? Long.toString(System.currentTimeMillis()) : before)); + String after = loadParams.getKey(); + ListenableFuture> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, Long.parseLong(after == null ? "0" : after)); ListenableFuture> pageFuture = Futures.transform(readPosts, this::transformData, executor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java index 3e2f975a..832b491a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java @@ -14,11 +14,11 @@ public interface ReadPostDao { @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(ReadPost readPost); - @Query("SELECT * FROM read_posts WHERE username = :username AND time < :before ORDER BY time LIMIT 25") - ListenableFuture> getAllReadPostsListenableFuture(String username, long before); + @Query("SELECT * FROM read_posts WHERE username = :username AND time > :after ORDER BY time LIMIT 25") + ListenableFuture> getAllReadPostsListenableFuture(String username, long after); - @Query("SELECT * FROM read_posts WHERE username = :username AND time < :before ORDER BY time LIMIT 25") - List getAllReadPosts(String username, long before); + @Query("SELECT * FROM read_posts WHERE username = :username AND time > :after ORDER BY time LIMIT 25") + List getAllReadPosts(String username, long after); @Query("SELECT * FROM read_posts WHERE username = :username") List getAllReadPosts(String username); -- cgit v1.2.3