1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06:37:30 +00:00

allow replying to replies

This commit is contained in:
Austin Huang 2021-06-28 12:02:34 -04:00
parent 463be0ec2e
commit 786c567cca
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 24 additions and 9 deletions

View File

@ -174,7 +174,7 @@ public class RepliesFragment extends Fragment {
}
private void setupToolbar() {
binding.toolbar.setTitle("Replies");
binding.toolbar.setTitle(R.string.title_replies);
binding.toolbar.setNavigationIcon(R.drawable.ic_round_arrow_back_24);
binding.toolbar.setNavigationOnClickListener(v -> {
final FragmentManager fragmentManager = getParentFragmentManager();
@ -187,7 +187,16 @@ public class RepliesFragment extends Fragment {
if (context == null) return;
commentsAdapter = new CommentsAdapter(currentUserId,
true,
Helper.getCommentCallback(context, getViewLifecycleOwner(), getNavController(), viewModel, null));
Helper.getCommentCallback(context,
getViewLifecycleOwner(),
getNavController(),
viewModel,
(comment, focusInput) -> {
viewModel.setReplyTo(comment);
binding.commentText.setText(String.format("@%s ", comment.getUser().getUsername()));
if (focusInput) Utils.showKeyboard(binding.commentText);
return null;
}));
binding.comments.setAdapter(commentsAdapter);
final Resource<List<Comment>> listResource = viewModel.getReplyList().getValue();
commentsAdapter.submitList(listResource != null ? listResource.data : Collections.emptyList());

View File

@ -54,7 +54,7 @@ public class CommentsViewerViewModel extends ViewModel {
private String postId;
private String rootCursor;
private boolean rootHasNext = true;
private Comment repliesParent;
private Comment repliesParent, replyTo;
private String repliesCursor;
private boolean repliesHasNext = true;
private final CommentService commentService;
@ -153,6 +153,11 @@ public class CommentsViewerViewModel extends ViewModel {
return repliesParent;
}
@Nullable
public void setReplyTo(final Comment replyTo) {
this.replyTo = replyTo;
}
public LiveData<Resource<List<Comment>>> getRootList() {
return rootList;
}
@ -297,6 +302,7 @@ public class CommentsViewerViewModel extends ViewModel {
if (comment == null) return;
if (repliesParent == null || !Objects.equals(repliesParent.getPk(), comment.getPk())) {
repliesParent = comment;
replyTo = comment;
prevReplies = null;
prevRepliesCursor = null;
prevRepliesHasNext = true;
@ -368,8 +374,8 @@ public class CommentsViewerViewModel extends ViewModel {
final boolean isReply) {
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>(Resource.loading(null));
String replyToId = null;
if (isReply && repliesParent != null) {
replyToId = repliesParent.getPk();
if (isReply && replyTo != null) {
replyToId = replyTo.getPk();
}
if (isReply && replyToId == null) {
data.postValue(Resource.error(null, null));
@ -399,10 +405,9 @@ public class CommentsViewerViewModel extends ViewModel {
final List<Comment> list = getPrevList(isReply ? replyList : rootList);
final ImmutableList.Builder<Comment> builder = ImmutableList.builder();
if (isReply) {
// in a reply list the first comment is the parent comment
builder.add(list.get(0))
.add(comment)
.addAll(list.subList(1, list.size()));
// replies are added to the bottom of the list to preserve chronological order
builder.addAll(list)
.add(comment);
} else {
builder.add(comment)
.addAll(list);

View File

@ -22,6 +22,7 @@
<string name="title_favorites">Favorites</string>
<string name="title_discover">Discover</string>
<string name="title_comments">Comments</string>
<string name="title_replies">Replies</string>
<string name="title_notifications">Activity</string>
<string name="update_check">Check for updates at startup</string>
<string name="flag_secure">Block screenshots &amp; app preview</string>