diff options
author | Louis Pré <louispre94@gmail.com> | 2024-03-12 18:25:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 18:25:12 +0000 |
commit | 04377b9eb090befd1cd17500971eee3078340650 (patch) | |
tree | 1330d03c96d8839077811374ab44ff65edefe1e9 /app | |
parent | 532fab53ed8b10ff9e72a2d38e2894696e5ac21e (diff) | |
download | infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar.gz infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar.bz2 infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar.lz infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar.xz infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.tar.zst infinity-for-reddit-04377b9eb090befd1cd17500971eee3078340650.zip |
Order history reverse chronologically (#1601)
* Typo and variable name
* Order history reverse chronologically
Diffstat (limited to 'app')
3 files changed, 12 insertions, 12 deletions
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<String } private ListenableFuture<LoadResult<String, Post>> loadHomePosts(@NonNull LoadParams<String> loadParams, RedditDataRoomDatabase redditDataRoomDatabase) { - String after = loadParams.getKey(); - ListenableFuture<List<ReadPost>> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, Long.parseLong(after == null ? "0" : after)); + Long before = loadParams.getKey() != null ? Long.parseLong(loadParams.getKey()) : null; + ListenableFuture<List<ReadPost>> readPosts = redditDataRoomDatabase.readPostDao().getAllReadPostsListenableFuture(username, before); ListenableFuture<LoadResult<String, Post>> 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<String, Post> pager = new Pager<>(new PagingConfig(25, 4, false, 10), this::returnPagingSoruce); + Pager<String, Post> 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<List<ReadPost>> 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<List<ReadPost>> getAllReadPostsListenableFuture(String username, Long before); - @Query("SELECT * FROM read_posts WHERE username = :username AND time > :after ORDER BY time LIMIT 25") - List<ReadPost> 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<ReadPost> getAllReadPosts(String username, Long before); @Query("SELECT * FROM read_posts WHERE username = :username") List<ReadPost> getAllReadPosts(String username); |