Fix post refreshing bug

Fix bug where the whole post disappears after refreshing it.
This commit is contained in:
Balazs Toldi 2023-07-27 17:45:14 +02:00
parent 9d6e15edb7
commit 2fc4020b72
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
2 changed files with 10 additions and 9 deletions

View File

@ -1937,4 +1937,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((TextView) itemView).setTextColor(mColorAccent); ((TextView) itemView).setTextColor(mColorAccent);
} }
} }
public void clearLoadedComments() {
loadedComments.clear();
}
} }

View File

@ -1408,16 +1408,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
String suggestedCommentSort = "top"; String suggestedCommentSort = "top";
SortType.Type sortTypeType; SortType.Type sortTypeType;
if (suggestedCommentSort == null || suggestedCommentSort.equals("null") || suggestedCommentSort.equals("")) { try {
mRespectSubredditRecommendedSortType = false; sortTypeType = SortType.Type.fromValue(suggestedCommentSort);
} catch (IllegalArgumentException e) {
e.printStackTrace();
sortTypeType = loadSortType(); sortTypeType = loadSortType();
} else {
try {
sortTypeType = SortType.Type.valueOf(suggestedCommentSort.toUpperCase(Locale.US));
} catch (IllegalArgumentException e) {
e.printStackTrace();
sortTypeType = loadSortType();
}
} }
activity.setTitle(sortTypeType.fullName); activity.setTitle(sortTypeType.fullName);
ViewPostDetailFragment.this.sortType = sortTypeType; ViewPostDetailFragment.this.sortType = sortTypeType;
@ -1582,6 +1577,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
if (fetchComments) { if (fetchComments) {
pages_loaded = 0;
mCommentsAdapter.clearLoadedComments();
fetchCommentsRespectRecommendedSort(true); fetchCommentsRespectRecommendedSort(true);
} else { } else {
isRefreshing = false; isRefreshing = false;