aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-09-16 14:44:15 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-09-16 14:44:15 +0000
commit6aaef3820cf7d78775e1746c7f065fccd13889af (patch)
treeed3be7e1e217915acf699e9fea83f2333b7ec761 /app/src/main
parent7f44b6a8de7de55fb0db04cc253c83a3709230a4 (diff)
downloadinfinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar.gz
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar.bz2
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar.lz
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar.xz
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.tar.zst
infinity-for-reddit-6aaef3820cf7d78775e1746c7f065fccd13889af.zip
Fix no post message not shown in PostFragment.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java2
3 files changed, 20 insertions, 9 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 6acd1336..768d3672 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -1158,17 +1158,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter.addLoadStateListener(combinedLoadStates -> {
LoadState refreshLoadState = combinedLoadStates.getRefresh();
+ LoadState appendLoadState = combinedLoadStates.getAppend();
mSwipeRefreshLayout.setRefreshing(refreshLoadState instanceof LoadState.Loading);
if (refreshLoadState instanceof LoadState.NotLoading) {
if (refreshLoadState.getEndOfPaginationReached() && mAdapter.getItemCount() < 1) {
- hasPost = false;
- if (isInLazyMode) {
- stopLazyMode();
- }
-
- mFetchPostInfoLinearLayout.setOnClickListener(null);
- showErrorView(R.string.no_posts);
+ noPostFound();
} else {
hasPost = true;
}
@@ -1176,6 +1171,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.load_posts_error);
}
+ if (appendLoadState instanceof LoadState.NotLoading) {
+ if (appendLoadState.getEndOfPaginationReached() && mAdapter.getItemCount() < 1) {
+ noPostFound();
+ }
+ }
return null;
});
@@ -1183,6 +1183,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
view -> mAdapter.retry())));
}
+ private void noPostFound() {
+ hasPost = false;
+ if (isInLazyMode) {
+ stopLazyMode();
+ }
+
+ mFetchPostInfoLinearLayout.setOnClickListener(null);
+ showErrorView(R.string.no_posts);
+ }
+
public void changeSortType(SortType sortType) {
if (mPostViewModel != null) {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 4626a08c..8b02bab9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -117,7 +117,8 @@ public class ParsePost {
public static String getLastItem(String response) {
try {
- return new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
+ JSONObject object = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY);
+ return object.isNull(JSONUtils.AFTER_KEY) ? null : object.getString(JSONUtils.AFTER_KEY);
} catch (JSONException e) {
e.printStackTrace();
return null;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
index cb60ae4b..38288785 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
@@ -190,7 +190,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
int currentPostsSize = postLinkedHashSet.size();
postLinkedHashSet.addAll(newPosts);
if (currentPostsSize == postLinkedHashSet.size()) {
- return new LoadResult.Page<>(new ArrayList<>(), null, null);
+ return new LoadResult.Page<>(new ArrayList<>(), null, lastItem);
} else {
return new LoadResult.Page<>(new ArrayList<>(postLinkedHashSet).subList(currentPostsSize, postLinkedHashSet.size()), null, lastItem);
}