aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java47
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java5
3 files changed, 51 insertions, 3 deletions
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 0f3b02a9..c759d06a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
@@ -49,6 +49,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -77,6 +78,7 @@ import ml.docilealligator.infinityforreddit.post.ParsePost;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostPagingSource;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
+import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Call;
@@ -660,7 +662,50 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
isFetchingMorePosts = false;
});
} else {
-
+ mExecutor.execute((Runnable) () -> {
+ long lastItem = posts.isEmpty() ? System.currentTimeMillis() : posts.get(posts.size() - 1).getPostTimeMillis();
+ List<ReadPost> readPosts = mRedditDataRoomDatabase.readPostDao().getAllReadPosts(username, lastItem);
+ StringBuilder ids = new StringBuilder();
+ for (ReadPost readPost : readPosts) {
+ ids.append("t3_").append(readPost.getId()).append(",");
+ }
+ if (ids.length() > 0) {
+ ids.deleteCharAt(ids.length() - 1);
+ }
+
+ Call<String> historyPosts;
+ if (mAccessToken != null && !mAccessToken.isEmpty()) {
+ historyPosts = mOauthRetrofit.create(RedditAPI.class).getInfoOauth(ids.toString(), APIUtils.getOAuthHeader(mAccessToken));
+ } else {
+ historyPosts = mRetrofit.create(RedditAPI.class).getInfo(ids.toString());
+ }
+
+ try {
+ Response<String> response = historyPosts.execute();
+ if (response.isSuccessful()) {
+ String responseString = response.body();
+ LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
+ if (newPosts == null || newPosts.isEmpty()) {
+ noMorePosts = true;
+ } else {
+ LinkedHashSet<Post> postLinkedHashSet = new LinkedHashSet<>(posts);
+ int currentPostsSize = postLinkedHashSet.size();
+ postLinkedHashSet.addAll(newPosts);
+ if (currentPostsSize == postLinkedHashSet.size()) {
+ noMorePosts = true;
+ } else {
+ posts = new ArrayList<>(postLinkedHashSet);
+ handler.post(() -> sectionsPagerAdapter.notifyItemRangeInserted(currentPostsSize, postLinkedHashSet.size() - currentPostsSize));
+ }
+ }
+ } else {
+ fetchMorePostsFailed = true;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ fetchMorePostsFailed = true;
+ }
+ });
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
index 596c2c79..917b9f5f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java
@@ -1265,7 +1265,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
public void onNeedForPostListFromPostRecyclerViewAdapterEvent(NeedForPostListFromPostFragmentEvent event) {
if (historyPostFragmentId == event.postFragmentTimeId && mAdapter != null) {
EventBus.getDefault().post(new ProvidePostListToViewPostDetailActivityEvent(historyPostFragmentId,
- new ArrayList<>(mAdapter.snapshot()), postType, null, null, null,
+ new ArrayList<>(mAdapter.snapshot()), HistoryPostPagingSource.TYPE_READ_POSTS, null, null, null,
null, null, null, postFilter, null, null));
}
}
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 f446811d..3e2f975a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/ReadPostDao.java
@@ -14,9 +14,12 @@ public interface ReadPostDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(ReadPost readPost);
- @Query("SELECT * FROM read_posts WHERE username = :username AND time < :before ORDER BY :before LIMIT 25")
+ @Query("SELECT * FROM read_posts WHERE username = :username AND time < :before ORDER BY time LIMIT 25")
ListenableFuture<List<ReadPost>> getAllReadPostsListenableFuture(String username, long before);
+ @Query("SELECT * FROM read_posts WHERE username = :username AND time < :before ORDER BY time LIMIT 25")
+ List<ReadPost> getAllReadPosts(String username, long before);
+
@Query("SELECT * FROM read_posts WHERE username = :username")
List<ReadPost> getAllReadPosts(String username);