mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Separate CommentAndPostRecyclerViewAdapter to PostDetailRecyclerViewAdapter and CommentsRecyclerViewAdapter and combine them using ConcatAdapter.
This commit is contained in:
parent
92a1c1d1ae
commit
e222fbc5b1
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.core.graphics.drawable.DrawableCompat;
|
import androidx.core.graphics.drawable.DrawableCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.ConcatAdapter;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.LinearSmoothScroller;
|
import androidx.recyclerview.widget.LinearSmoothScroller;
|
||||||
@ -75,7 +76,8 @@ import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActiv
|
|||||||
import ml.docilealligator.infinityforreddit.activities.ReportActivity;
|
import ml.docilealligator.infinityforreddit.activities.ReportActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.SubmitCrosspostActivity;
|
import ml.docilealligator.infinityforreddit.activities.SubmitCrosspostActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
|
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
|
||||||
import ml.docilealligator.infinityforreddit.adapters.CommentAndPostRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.adapters.CommentsRecyclerViewAdapter;
|
||||||
|
import ml.docilealligator.infinityforreddit.adapters.PostDetailRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment;
|
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment;
|
||||||
@ -212,7 +214,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
private boolean mExpandChildren;
|
private boolean mExpandChildren;
|
||||||
private int mWindowWidth;
|
private int mWindowWidth;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private CommentAndPostRecyclerViewAdapter mAdapter;
|
private ConcatAdapter mConcatAdapter;
|
||||||
|
private PostDetailRecyclerViewAdapter mPostAdapter;
|
||||||
|
private CommentsRecyclerViewAdapter mCommentAdapter;
|
||||||
private RecyclerView.SmoothScroller mSmoothScroller;
|
private RecyclerView.SmoothScroller mSmoothScroller;
|
||||||
private Drawable mSavedIcon;
|
private Drawable mSavedIcon;
|
||||||
private Drawable mUnsavedIcon;
|
private Drawable mUnsavedIcon;
|
||||||
@ -365,7 +369,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
if (!(viewHolder instanceof CommentAndPostRecyclerViewAdapter.CommentViewHolder)) {
|
if (!(viewHolder instanceof CommentsRecyclerViewAdapter.CommentViewHolder)) {
|
||||||
return makeMovementFlags(0, 0);
|
return makeMovementFlags(0, 0);
|
||||||
}
|
}
|
||||||
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
||||||
@ -387,8 +391,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
if (touchHelper != null) {
|
if (touchHelper != null) {
|
||||||
touchHelper.attachToRecyclerView(null);
|
touchHelper.attachToRecyclerView(null);
|
||||||
touchHelper.attachToRecyclerView(mRecyclerView);
|
touchHelper.attachToRecyclerView(mRecyclerView);
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction);
|
mCommentAdapter.onItemSwipe(viewHolder, direction, swipeLeftAction, swipeRightAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -517,17 +521,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
} else {
|
} else {
|
||||||
setupMenu();
|
setupMenu();
|
||||||
|
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(activity,
|
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
|
||||||
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||||
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
|
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
|
||||||
isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator,
|
isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator, new PostDetailRecyclerViewAdapter.PostDetailRecyclerViewAdapterCallback() {
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePost(Post post) {
|
public void updatePost(Post post) {
|
||||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
mCommentAdapter = new CommentsRecyclerViewAdapter(activity,
|
||||||
|
this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit,
|
||||||
|
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
|
||||||
|
isSingleCommentThreadMode, mSharedPreferences,
|
||||||
|
new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryFetchingComments() {
|
public void retryFetchingComments() {
|
||||||
fetchCommentsRespectRecommendedSort(false);
|
fetchCommentsRespectRecommendedSort(false);
|
||||||
@ -541,7 +549,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
fetchMoreComments();
|
fetchMoreComments();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentAdapter);
|
||||||
|
mRecyclerView.setAdapter(mConcatAdapter);
|
||||||
|
|
||||||
if (comments == null) {
|
if (comments == null) {
|
||||||
fetchCommentsRespectRecommendedSort(false);
|
fetchCommentsRespectRecommendedSort(false);
|
||||||
@ -552,7 +561,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
} else if (isFetchingComments) {
|
} else if (isFetchingComments) {
|
||||||
fetchCommentsRespectRecommendedSort(false);
|
fetchCommentsRespectRecommendedSort(false);
|
||||||
} else {
|
} else {
|
||||||
mAdapter.addComments(comments, hasMoreChildren);
|
mCommentAdapter.addComments(comments, hasMoreChildren);
|
||||||
if (isLoadingMoreChildren) {
|
if (isLoadingMoreChildren) {
|
||||||
isLoadingMoreChildren = false;
|
isLoadingMoreChildren = false;
|
||||||
fetchMoreComments();
|
fetchMoreComments();
|
||||||
@ -561,7 +570,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mRecyclerView.setCacheManager(mAdapter);
|
mRecyclerView.setCacheManager(mPostAdapter);
|
||||||
mRecyclerView.setPlayerInitializer(order -> {
|
mRecyclerView.setPlayerInitializer(order -> {
|
||||||
VolumeInfo volumeInfo = new VolumeInfo(true, 0f);
|
VolumeInfo volumeInfo = new VolumeInfo(true, 0f);
|
||||||
return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo);
|
return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo);
|
||||||
@ -661,28 +670,28 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addComment(Comment comment) {
|
public void addComment(Comment comment) {
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.addComment(comment);
|
mCommentAdapter.addComment(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChildComment(Comment comment, String parentFullname, int parentPosition) {
|
public void addChildComment(Comment comment, String parentFullname, int parentPosition) {
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.addChildComment(comment, parentFullname, parentPosition);
|
mCommentAdapter.addChildComment(comment, parentFullname, parentPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
|
public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.editComment(commentAuthor,
|
mCommentAdapter.editComment(commentAuthor,
|
||||||
commentContentMarkdown,
|
commentContentMarkdown,
|
||||||
position);
|
position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void awardGiven(String awardsHTML, int awardCount, int position) {
|
public void awardGiven(String awardsHTML, int awardCount, int position) {
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.giveAward(awardsHTML, awardCount, position);
|
mCommentAdapter.giveAward(awardsHTML, awardCount, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,8 +743,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveComment(int position, boolean isSaved) {
|
public void saveComment(int position, boolean isSaved) {
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
mAdapter.setSaveComment(position, isSaved);
|
mCommentAdapter.setSaveComment(position, isSaved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +1009,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mAdapter != null && mRecyclerView != null) {
|
if (mCommentAdapter != null && mRecyclerView != null) {
|
||||||
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
|
mRecyclerView.onWindowVisibilityChanged(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1008,7 +1017,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (mAdapter != null && mRecyclerView != null) {
|
if (mCommentAdapter != null && mRecyclerView != null) {
|
||||||
mRecyclerView.onWindowVisibilityChanged(View.GONE);
|
mRecyclerView.onWindowVisibilityChanged(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1016,7 +1025,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
comments = mAdapter == null ? null : mAdapter.getVisibleComments();
|
comments = mCommentAdapter == null ? null : mCommentAdapter.getVisibleComments();
|
||||||
Bridge.saveInstanceState(this, outState);
|
Bridge.saveInstanceState(this, outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1086,18 +1095,23 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
setupMenu();
|
setupMenu();
|
||||||
|
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(activity,
|
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
|
||||||
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
|
||||||
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale,
|
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale,
|
||||||
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
|
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
|
||||||
mNsfwAndSpoilerSharedPreferences, mExoCreator,
|
mNsfwAndSpoilerSharedPreferences, mExoCreator, new PostDetailRecyclerViewAdapter.PostDetailRecyclerViewAdapterCallback() {
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePost(Post post) {
|
public void updatePost(Post post) {
|
||||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mCommentAdapter = new CommentsRecyclerViewAdapter(activity,
|
||||||
|
ViewPostDetailFragment.this, mCustomThemeWrapper, mRetrofit, mOauthRetrofit,
|
||||||
|
mAccessToken, mAccountName, mPost, mLocale,
|
||||||
|
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
|
||||||
|
new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryFetchingComments() {
|
public void retryFetchingComments() {
|
||||||
fetchCommentsRespectRecommendedSort(false);
|
fetchCommentsRespectRecommendedSort(false);
|
||||||
@ -1111,7 +1125,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
fetchMoreComments();
|
fetchMoreComments();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentAdapter);
|
||||||
|
mRecyclerView.setAdapter(mConcatAdapter);
|
||||||
|
|
||||||
if (mRespectSubredditRecommendedSortType) {
|
if (mRespectSubredditRecommendedSortType) {
|
||||||
fetchCommentsRespectRecommendedSort(false);
|
fetchCommentsRespectRecommendedSort(false);
|
||||||
@ -1123,7 +1138,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
ViewPostDetailFragment.this.children = moreChildrenFullnames;
|
ViewPostDetailFragment.this.children = moreChildrenFullnames;
|
||||||
|
|
||||||
hasMoreChildren = children.size() != 0;
|
hasMoreChildren = children.size() != 0;
|
||||||
mAdapter.addComments(expandedComments, hasMoreChildren);
|
mCommentAdapter.addComments(expandedComments, hasMoreChildren);
|
||||||
|
|
||||||
if (children.size() > 0) {
|
if (children.size() > 0) {
|
||||||
mRecyclerView.clearOnScrollListeners();
|
mRecyclerView.clearOnScrollListeners();
|
||||||
@ -1174,7 +1189,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onParseCommentFailed() {
|
public void onParseCommentFailed() {
|
||||||
mAdapter.initiallyLoadCommentsFailed();
|
mCommentAdapter.initiallyLoadCommentsFailed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1236,8 +1251,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
private void fetchComments(boolean changeRefreshState, boolean checkSortState, String sortType) {
|
private void fetchComments(boolean changeRefreshState, boolean checkSortState, String sortType) {
|
||||||
isFetchingComments = true;
|
isFetchingComments = true;
|
||||||
mAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
|
mCommentAdapter.setSingleComment(mSingleCommentId, isSingleCommentThreadMode);
|
||||||
mAdapter.initiallyLoading();
|
mCommentAdapter.initiallyLoading();
|
||||||
String commentId = null;
|
String commentId = null;
|
||||||
if (isSingleCommentThreadMode) {
|
if (isSingleCommentThreadMode) {
|
||||||
commentId = mSingleCommentId;
|
commentId = mSingleCommentId;
|
||||||
@ -1261,7 +1276,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
comments = expandedComments;
|
comments = expandedComments;
|
||||||
hasMoreChildren = children.size() != 0;
|
hasMoreChildren = children.size() != 0;
|
||||||
mAdapter.addComments(expandedComments, hasMoreChildren);
|
mCommentAdapter.addComments(expandedComments, hasMoreChildren);
|
||||||
|
|
||||||
if (children.size() > 0) {
|
if (children.size() > 0) {
|
||||||
mRecyclerView.clearOnScrollListeners();
|
mRecyclerView.clearOnScrollListeners();
|
||||||
@ -1326,7 +1341,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mAdapter.initiallyLoadCommentsFailed();
|
mCommentAdapter.initiallyLoadCommentsFailed();
|
||||||
if (changeRefreshState) {
|
if (changeRefreshState) {
|
||||||
isRefreshing = false;
|
isRefreshing = false;
|
||||||
}
|
}
|
||||||
@ -1351,7 +1366,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void onFetchMoreCommentSuccess(ArrayList<Comment> expandedComments, int childrenStartingIndex) {
|
public void onFetchMoreCommentSuccess(ArrayList<Comment> expandedComments, int childrenStartingIndex) {
|
||||||
hasMoreChildren = childrenStartingIndex < children.size();
|
hasMoreChildren = childrenStartingIndex < children.size();
|
||||||
mAdapter.addComments(expandedComments, hasMoreChildren);
|
mCommentAdapter.addComments(expandedComments, hasMoreChildren);
|
||||||
mChildrenStartingIndex = childrenStartingIndex;
|
mChildrenStartingIndex = childrenStartingIndex;
|
||||||
isLoadingMoreChildren = false;
|
isLoadingMoreChildren = false;
|
||||||
loadMoreChildrenSuccess = true;
|
loadMoreChildrenSuccess = true;
|
||||||
@ -1361,13 +1376,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
public void onFetchMoreCommentFailed() {
|
public void onFetchMoreCommentFailed() {
|
||||||
isLoadingMoreChildren = false;
|
isLoadingMoreChildren = false;
|
||||||
loadMoreChildrenSuccess = false;
|
loadMoreChildrenSuccess = false;
|
||||||
mAdapter.loadMoreCommentsFailed();
|
mCommentAdapter.loadMoreCommentsFailed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean fetchPost, boolean fetchComments) {
|
public void refresh(boolean fetchPost, boolean fetchComments) {
|
||||||
if (mAdapter != null && !isRefreshing) {
|
if (mPostAdapter != null && !isRefreshing) {
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
mChildrenStartingIndex = 0;
|
mChildrenStartingIndex = 0;
|
||||||
|
|
||||||
@ -1390,7 +1405,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
mPost = post;
|
mPost = post;
|
||||||
mAdapter.updatePost(mPost);
|
mPostAdapter.updatePost(mPost);
|
||||||
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
|
||||||
isRefreshing = false;
|
isRefreshing = false;
|
||||||
setupMenu();
|
setupMenu();
|
||||||
@ -1584,7 +1599,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void deleteSuccess() {
|
public void deleteSuccess() {
|
||||||
Toast.makeText(activity, R.string.delete_post_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, R.string.delete_post_success, Toast.LENGTH_SHORT).show();
|
||||||
mAdapter.deleteComment(position);
|
mCommentAdapter.deleteComment(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1604,7 +1619,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
new FetchRemovedComment.FetchRemovedCommentListener() {
|
new FetchRemovedComment.FetchRemovedCommentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchSuccess(Comment comment) {
|
public void fetchSuccess(Comment comment) {
|
||||||
mAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
|
mCommentAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1624,8 +1639,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
public void scrollToNextParentComment() {
|
public void scrollToNextParentComment() {
|
||||||
if (mLinearLayoutManager != null) {
|
if (mLinearLayoutManager != null) {
|
||||||
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
|
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
int nextParentPosition = mAdapter.getNextParentCommentPosition(currentPosition);
|
int nextParentPosition = mCommentAdapter.getNextParentCommentPosition(currentPosition);
|
||||||
if (nextParentPosition < 0) {
|
if (nextParentPosition < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1641,8 +1656,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
public void scrollToPreviousParentComment() {
|
public void scrollToPreviousParentComment() {
|
||||||
if (mLinearLayoutManager != null) {
|
if (mLinearLayoutManager != null) {
|
||||||
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
|
int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
|
||||||
if (mAdapter != null) {
|
if (mCommentAdapter != null) {
|
||||||
int nextParentPosition = mAdapter.getPreviousParentCommentPosition(currentPosition);
|
int nextParentPosition = mCommentAdapter.getPreviousParentCommentPosition(currentPosition);
|
||||||
if (nextParentPosition < 0) {
|
if (nextParentPosition < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1668,7 +1683,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
@Override
|
@Override
|
||||||
public void fetchSuccess(Post post) {
|
public void fetchSuccess(Post post) {
|
||||||
mPost = post;
|
mPost = post;
|
||||||
mAdapter.updatePost(post);
|
if (mPostAdapter != null) {
|
||||||
|
mPostAdapter.updatePost(post);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1697,19 +1714,25 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
mMenu.findItem(R.id.action_save_view_post_detail_fragment).setIcon(mUnsavedIcon);
|
mMenu.findItem(R.id.action_save_view_post_detail_fragment).setIcon(mUnsavedIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAdapter.updatePost(mPost);
|
if (mPostAdapter != null) {
|
||||||
|
mPostAdapter.updatePost(mPost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
|
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
|
||||||
mAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits);
|
if (mPostAdapter != null) {
|
||||||
|
mPostAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits);
|
||||||
|
}
|
||||||
refreshAdapter();
|
refreshAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
|
public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
|
||||||
mAdapter.setBlurSpoiler(event.needBlurSpoiler);
|
if (mPostAdapter != null) {
|
||||||
|
mPostAdapter.setBlurSpoiler(event.needBlurSpoiler);
|
||||||
|
}
|
||||||
refreshAdapter();
|
refreshAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1722,7 +1745,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
|
RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
|
||||||
mRecyclerView.setAdapter(null);
|
mRecyclerView.setAdapter(null);
|
||||||
mRecyclerView.setLayoutManager(null);
|
mRecyclerView.setLayoutManager(null);
|
||||||
mRecyclerView.setAdapter(mAdapter);
|
mRecyclerView.setAdapter(mConcatAdapter);
|
||||||
mRecyclerView.setLayoutManager(layoutManager);
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
if (previousPosition > 0) {
|
if (previousPosition > 0) {
|
||||||
@ -1732,16 +1755,16 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
|
public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
|
||||||
if (mAdapter != null) {
|
if (mPostAdapter != null) {
|
||||||
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
|
||||||
String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
|
||||||
boolean stateChanged = false;
|
boolean stateChanged = false;
|
||||||
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
|
||||||
mAdapter.setAutoplay(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_WIFI);
|
mPostAdapter.setAutoplay(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_WIFI);
|
||||||
stateChanged = true;
|
stateChanged = true;
|
||||||
}
|
}
|
||||||
if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
|
||||||
mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
|
mPostAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
|
||||||
stateChanged = true;
|
stateChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user