Show more context when loading a single comment

This commit makes it so that when loading a single comment (e.g. from the inbox) it also shows the parent comment.

Closes #47
This commit is contained in:
Bazsalanszky 2023-08-04 15:55:40 +02:00
parent 5c39fddbc6
commit 2af6c5a742
5 changed files with 18 additions and 4 deletions

View File

@ -227,6 +227,7 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId()); intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
startActivity(intent); startActivity(intent);
} }
@ -246,6 +247,7 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId()); intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
startActivity(intent); startActivity(intent);
} }

View File

@ -95,6 +95,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
public static final String EXTRA_POST_ID = "EPI"; public static final String EXTRA_POST_ID = "EPI";
public static final String EXTRA_POST_LIST_POSITION = "EPLP"; public static final String EXTRA_POST_LIST_POSITION = "EPLP";
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI"; public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
public static final String EXTRA_SINGLE_COMMENT_PARENT_ID = "ESCPI";
public static final String EXTRA_CONTEXT_NUMBER = "ECN"; public static final String EXTRA_CONTEXT_NUMBER = "ECN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENI"; public static final String EXTRA_MESSAGE_FULLNAME = "ENI";
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
@ -870,6 +871,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post); bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position); bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0)); bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_PARENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_PARENT_ID, 0));
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER)); bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME)); bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
} else { } else {
@ -891,6 +893,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition); bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
} }
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0)); bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_PARENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_PARENT_ID, 0));
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER)); bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME)); bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
} }

View File

@ -472,6 +472,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId()); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId()); intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
mActivity.startActivity(intent); mActivity.startActivity(intent);
} }
}); });

View File

@ -182,6 +182,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<CommentInteract
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, message.getComment().getPostId()); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, message.getComment().getPostId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, message.getComment().getId()); intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, message.getComment().getId());
if(message.getComment().getDepth() > 0) {
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, message.getComment().getParentId());
}
mActivity.startActivity(intent); mActivity.startActivity(intent);
} else if (mMessageType == FetchMessage.MESSAGE_TYPE_PRIVATE_MESSAGE) { } else if (mMessageType == FetchMessage.MESSAGE_TYPE_PRIVATE_MESSAGE) {
Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class); Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class);

View File

@ -129,6 +129,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public static final String EXTRA_POST_DATA = "EPD"; public static final String EXTRA_POST_DATA = "EPD";
public static final String EXTRA_POST_ID = "EPI"; public static final String EXTRA_POST_ID = "EPI";
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI"; public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
public static final String EXTRA_SINGLE_COMMENT_PARENT_ID = "ESCPID";
public static final String EXTRA_CONTEXT_NUMBER = "ECN"; public static final String EXTRA_CONTEXT_NUMBER = "ECN";
public static final String EXTRA_MESSAGE_FULLNAME = "EMF"; public static final String EXTRA_MESSAGE_FULLNAME = "EMF";
public static final String EXTRA_POST_LIST_POSITION = "EPLP"; public static final String EXTRA_POST_LIST_POSITION = "EPLP";
@ -229,6 +231,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private String mAccountQualifiedName; private String mAccountQualifiedName;
private int postListPosition = -1; private int postListPosition = -1;
private Integer mSingleCommentId; private Integer mSingleCommentId;
private Integer mSingleCommentParentId;
private String mContextNumber; private String mContextNumber;
private boolean showToast = false; private boolean showToast = false;
private boolean mIsSmoothScrolling = false; private boolean mIsSmoothScrolling = false;
@ -547,6 +550,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}; };
mSingleCommentId = getArguments().getInt(EXTRA_SINGLE_COMMENT_ID, 0); mSingleCommentId = getArguments().getInt(EXTRA_SINGLE_COMMENT_ID, 0);
mSingleCommentParentId = getArguments().getInt(EXTRA_SINGLE_COMMENT_PARENT_ID, 0);
mContextNumber = getArguments().getString(EXTRA_CONTEXT_NUMBER, "8"); mContextNumber = getArguments().getString(EXTRA_CONTEXT_NUMBER, "8");
if (savedInstanceState == null) { if (savedInstanceState == null) {
@ -606,8 +610,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
this, mCustomThemeWrapper, mExecutor, mRetrofit.getRetrofit(), this, mCustomThemeWrapper, mExecutor, mRetrofit.getRetrofit(),
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId
isSingleCommentThreadMode, mSharedPreferences, , isSingleCommentThreadMode, mSharedPreferences,
new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void retryFetchingComments() { public void retryFetchingComments() {
@ -626,7 +630,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public SortType.Type getSortType() { public SortType.Type getSortType() {
return sortType; return sortType;
} }
}); } );
if (mCommentsRecyclerView != null) { if (mCommentsRecyclerView != null) {
mRecyclerView.setAdapter(mPostAdapter); mRecyclerView.setAdapter(mPostAdapter);
mCommentsRecyclerView.setAdapter(mCommentsAdapter); mCommentsRecyclerView.setAdapter(mCommentsAdapter);
@ -1245,7 +1249,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostDetailsSharedPreferences, mExoCreator, mPostDetailsSharedPreferences, mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, post.getId(), mSingleCommentId == 0 ? null : mSingleCommentId, sortType, mExpandChildren, 1, new FetchComment.FetchCommentListener() { FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, post.getId(), mSingleCommentId == 0 ? null : mSingleCommentParentId == 0 ? mSingleCommentId : mSingleCommentParentId, sortType, mExpandChildren, 1, new FetchComment.FetchCommentListener() {
@Override @Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) { public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
pages_loaded++; pages_loaded++;
@ -1666,6 +1670,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
public void changeToNormalThreadMode() { public void changeToNormalThreadMode() {
isSingleCommentThreadMode = false; isSingleCommentThreadMode = false;
mSingleCommentId = null; mSingleCommentId = null;
mSingleCommentParentId = null;
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false); mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
refresh(false, true); refresh(false, true);
} }