diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-04-17 17:17:26 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-04-17 17:17:26 +0000 |
commit | 8503e78a8e42f8e29b57f0017dafcfc615512d69 (patch) | |
tree | de326d5da4d0df19c020902f0f48a31d91e38cd8 /app/src | |
parent | dbc36bee6fb98b2b513f4a7f35f47ea5175e1665 (diff) | |
download | infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar.gz infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar.bz2 infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar.lz infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar.xz infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.tar.zst infinity-for-reddit-8503e78a8e42f8e29b57f0017dafcfc615512d69.zip |
Fix issues related to PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT. Fix crashes when loading anonymous front page or anonymous multireddit on ViewPostDetailActivity when swipe between posts is enabled.
Diffstat (limited to 'app/src')
7 files changed, 32 insertions, 28 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 a34ea1b0..59cab228 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -151,6 +151,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele @State String subredditName; @State + String concatenatedSubredditNames; + @State String username; @State String userWhere; @@ -559,8 +561,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } break; case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: - //case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT - call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey); + case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT: + call = api.getSubredditBestPosts(concatenatedSubredditNames, sortType, sortTime, afterKey); break; default: call = api.getBestPosts(sortType, sortTime, afterKey, @@ -725,6 +727,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele this.posts = event.posts; this.postType = event.postType; this.subredditName = event.subredditName; + this.concatenatedSubredditNames = event.concatenatedSubredditNames; this.username = event.username; this.userWhere = event.userWhere; this.multiPath = event.multiPath; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 2c4c21a8..5254c6db 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -323,7 +323,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi @Override public int getItemViewType(int position) { - if (mVisibleComments.size() == 0) { + if (mVisibleComments.isEmpty()) { if (isInitiallyLoading) { return VIEW_TYPE_FIRST_LOADING; } else if (isInitiallyLoadingFailed) { @@ -842,15 +842,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi return findCommentPosition(fullName, positionHint, Comment.NOT_PLACEHOLDER); } - /** - * Find position of comment with given {@code fullName} and - * {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type - * @return position of the placeholder or -1 if not found - */ - private int findLoadMoreCommentsPlaceholderPosition(String fullName, int positionHint) { - return findCommentPosition(fullName, positionHint, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS); - } - private int findCommentPosition(String fullName, int positionHint, int placeholderType) { if (0 <= positionHint && positionHint < mVisibleComments.size() && mVisibleComments.get(positionHint).getFullName().equals(fullName) @@ -867,8 +858,17 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi return -1; } + /** + * Find position of comment with given {@code fullName} and + * {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type + * @return position of the placeholder or -1 if not found + */ + private int findLoadMoreCommentsPlaceholderPosition(String fullName, int positionHint) { + return findCommentPosition(fullName, positionHint, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS); + } + private void expandChildren(ArrayList<Comment> comments, ArrayList<Comment> newList) { - if (comments != null && comments.size() > 0) { + if (comments != null && !comments.isEmpty()) { for (Comment comment : comments) { newList.add(comment); expandChildren(comment.getChildren(), newList); @@ -1165,7 +1165,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi return 1; } - if (isInitiallyLoadingFailed || mVisibleComments.size() == 0) { + if (isInitiallyLoadingFailed || mVisibleComments.isEmpty()) { return mIsSingleCommentThreadMode ? 2 : 1; } @@ -1370,7 +1370,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi }); moreButton.setOnClickListener(view -> { - getItemCount(); Comment comment = getCurrentComment(this); if (comment != null) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java index 15c37ff1..ffe27c0d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java @@ -11,6 +11,7 @@ public class ProvidePostListToViewPostDetailActivityEvent { public ArrayList<Post> posts; public int postType; public String subredditName; + public String concatenatedSubredditNames; public String username; public String userWhere; public String multiPath; @@ -21,13 +22,16 @@ public class ProvidePostListToViewPostDetailActivityEvent { public ArrayList<String> readPostList; public ProvidePostListToViewPostDetailActivityEvent(long postFragmentId, ArrayList<Post> posts, int postType, - String subredditName, String username, String userWhere, + String subredditName, String concatenatedSubredditNames, + String username, String userWhere, String multiPath, String query, String trendingSource, - PostFilter postFilter, SortType sortType, ArrayList<String> readPostList) { + PostFilter postFilter, SortType sortType, + ArrayList<String> readPostList) { this.postFragmentId = postFragmentId; this.posts = posts; this.postType = postType; this.subredditName = subredditName; + this.concatenatedSubredditNames = concatenatedSubredditNames; this.username = username; this.userWhere = userWhere; this.multiPath = multiPath; 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 616b1759..e88e549f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -1280,7 +1280,8 @@ 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()), HistoryPostPagingSource.TYPE_READ_POSTS, null, null, null, + new ArrayList<>(mAdapter.snapshot()), HistoryPostPagingSource.TYPE_READ_POSTS, + null, null, null, null, null, null, null, postFilter, null, null)); } } 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 3dfd5828..f73e3db8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -1238,18 +1238,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mRetrofit, null, activity.accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType, postFilter, readPosts)).get(PostViewModel.class); - } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) { - mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, - mRetrofit, null, activity.accountName, mSharedPreferences, - mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath, - postType, sortType, postFilter, readPosts)).get(PostViewModel.class); } else if (postType == PostPagingSource.TYPE_USER) { mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mRetrofit, null, activity.accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter, where, readPosts)).get(PostViewModel.class); } else { - //Anonymous Front Page + //Anonymous front page or multireddit mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)) .get(PostViewModel.class); @@ -2051,8 +2046,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { public void onNeedForPostListFromPostRecyclerViewAdapterEvent(NeedForPostListFromPostFragmentEvent event) { if (postFragmentId == event.postFragmentTimeId && mAdapter != null) { EventBus.getDefault().post(new ProvidePostListToViewPostDetailActivityEvent(postFragmentId, - new ArrayList<>(mAdapter.snapshot()), postType, subredditName, username, where, - multiRedditPath, query, trendingSource, postFilter, sortType, readPosts)); + new ArrayList<>(mAdapter.snapshot()), postType, subredditName, + concatenatedSubredditNames, username, where, multiRedditPath, query, trendingSource, + postFilter, sortType, readPosts)); } } 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 cc2519cf..2d5191a4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java @@ -86,7 +86,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post> this.accountName = accountName; this.sharedPreferences = sharedPreferences; this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences; - if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) { + if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE || postType == TYPE_ANONYMOUS_MULTIREDDIT) { this.subredditOrUserName = path; } else { if (sortType != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index 65f8314c..aad51bad 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -235,6 +235,7 @@ public class PostViewModel extends ViewModel { case PostPagingSource.TYPE_SUBREDDIT: case PostPagingSource.TYPE_MULTI_REDDIT: case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: + case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT: paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName, sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType, sortType, postFilter, readPostList); @@ -386,7 +387,7 @@ public class PostViewModel extends ViewModel { return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences, postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, postType, sortType, postFilter, readPostList); - } else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) { + } else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE || postType == PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT) { return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences, null, null, name, postType, sortType, postFilter, null); |