From 04377b9eb090befd1cd17500971eee3078340650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Pr=C3=A9?= Date: Tue, 12 Mar 2024 11:25:12 -0700 Subject: Order history reverse chronologically (#1601) * Typo and variable name * Order history reverse chronologically --- .../infinityforreddit/post/HistoryPostPagingSource.java | 4 ++-- .../infinityforreddit/post/HistoryPostViewModel.java | 12 ++++++------ .../infinityforreddit/readpost/ReadPostDao.java | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') 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 360496db..a0b9167f 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 after = loadParams.getKey(); - ListenableFuture> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, Long.parseLong(after == null ? "0" : after)); + Long before = loadParams.getKey() != null ? Long.parseLong(loadParams.getKey()) : null; + ListenableFuture> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, before); ListenableFuture> pageFuture = Futures.transform(readPosts, this::transformData, executor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostViewModel.java index f3116b45..199a8f34 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/HistoryPostViewModel.java @@ -49,7 +49,7 @@ public class HistoryPostViewModel extends ViewModel { postFilterLiveData = new MutableLiveData<>(postFilter); - Pager pager = new Pager<>(new PagingConfig(25, 4, false, 10), this::returnPagingSoruce); + Pager pager = new Pager<>(new PagingConfig(25, 4, false, 10), this::returnPagingSource); posts = Transformations.switchMap(postFilterLiveData, postFilterValue -> PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this))); } @@ -58,19 +58,19 @@ public class HistoryPostViewModel extends ViewModel { return posts; } - public HistoryPostPagingSource returnPagingSoruce() { - HistoryPostPagingSource paging3PagingSource; + public HistoryPostPagingSource returnPagingSource() { + HistoryPostPagingSource historyPostPagingSource; switch (postType) { case HistoryPostPagingSource.TYPE_READ_POSTS: - paging3PagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName, + historyPostPagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName, sharedPreferences, accountName, postType, postFilter); break; default: - paging3PagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName, + historyPostPagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName, sharedPreferences, accountName, postType, postFilter); break; } - return paging3PagingSource; + return historyPostPagingSource; } public void changePostFilter(PostFilter postFilter) { 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 7193306a..5f7fb8da 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 > :after ORDER BY time LIMIT 25") - ListenableFuture> getAllReadPostsListenableFuture(String username, long after); + @Query("SELECT * FROM read_posts WHERE username = :username AND (:before IS NULL OR time < :before) ORDER BY time DESC LIMIT 25") + ListenableFuture> getAllReadPostsListenableFuture(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 AND (:before IS NULL OR time < :before) ORDER BY time DESC LIMIT 25") + List getAllReadPosts(String username, Long before); @Query("SELECT * FROM read_posts WHERE username = :username") List getAllReadPosts(String username); -- cgit v1.2.3