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:
parent
463be0ec2e
commit
786c567cca
@ -174,7 +174,7 @@ public class RepliesFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupToolbar() {
|
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.setNavigationIcon(R.drawable.ic_round_arrow_back_24);
|
||||||
binding.toolbar.setNavigationOnClickListener(v -> {
|
binding.toolbar.setNavigationOnClickListener(v -> {
|
||||||
final FragmentManager fragmentManager = getParentFragmentManager();
|
final FragmentManager fragmentManager = getParentFragmentManager();
|
||||||
@ -187,7 +187,16 @@ public class RepliesFragment extends Fragment {
|
|||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
commentsAdapter = new CommentsAdapter(currentUserId,
|
commentsAdapter = new CommentsAdapter(currentUserId,
|
||||||
true,
|
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);
|
binding.comments.setAdapter(commentsAdapter);
|
||||||
final Resource<List<Comment>> listResource = viewModel.getReplyList().getValue();
|
final Resource<List<Comment>> listResource = viewModel.getReplyList().getValue();
|
||||||
commentsAdapter.submitList(listResource != null ? listResource.data : Collections.emptyList());
|
commentsAdapter.submitList(listResource != null ? listResource.data : Collections.emptyList());
|
||||||
|
@ -54,7 +54,7 @@ public class CommentsViewerViewModel extends ViewModel {
|
|||||||
private String postId;
|
private String postId;
|
||||||
private String rootCursor;
|
private String rootCursor;
|
||||||
private boolean rootHasNext = true;
|
private boolean rootHasNext = true;
|
||||||
private Comment repliesParent;
|
private Comment repliesParent, replyTo;
|
||||||
private String repliesCursor;
|
private String repliesCursor;
|
||||||
private boolean repliesHasNext = true;
|
private boolean repliesHasNext = true;
|
||||||
private final CommentService commentService;
|
private final CommentService commentService;
|
||||||
@ -153,6 +153,11 @@ public class CommentsViewerViewModel extends ViewModel {
|
|||||||
return repliesParent;
|
return repliesParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public void setReplyTo(final Comment replyTo) {
|
||||||
|
this.replyTo = replyTo;
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<Resource<List<Comment>>> getRootList() {
|
public LiveData<Resource<List<Comment>>> getRootList() {
|
||||||
return rootList;
|
return rootList;
|
||||||
}
|
}
|
||||||
@ -297,6 +302,7 @@ public class CommentsViewerViewModel extends ViewModel {
|
|||||||
if (comment == null) return;
|
if (comment == null) return;
|
||||||
if (repliesParent == null || !Objects.equals(repliesParent.getPk(), comment.getPk())) {
|
if (repliesParent == null || !Objects.equals(repliesParent.getPk(), comment.getPk())) {
|
||||||
repliesParent = comment;
|
repliesParent = comment;
|
||||||
|
replyTo = comment;
|
||||||
prevReplies = null;
|
prevReplies = null;
|
||||||
prevRepliesCursor = null;
|
prevRepliesCursor = null;
|
||||||
prevRepliesHasNext = true;
|
prevRepliesHasNext = true;
|
||||||
@ -368,8 +374,8 @@ public class CommentsViewerViewModel extends ViewModel {
|
|||||||
final boolean isReply) {
|
final boolean isReply) {
|
||||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>(Resource.loading(null));
|
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>(Resource.loading(null));
|
||||||
String replyToId = null;
|
String replyToId = null;
|
||||||
if (isReply && repliesParent != null) {
|
if (isReply && replyTo != null) {
|
||||||
replyToId = repliesParent.getPk();
|
replyToId = replyTo.getPk();
|
||||||
}
|
}
|
||||||
if (isReply && replyToId == null) {
|
if (isReply && replyToId == null) {
|
||||||
data.postValue(Resource.error(null, 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 List<Comment> list = getPrevList(isReply ? replyList : rootList);
|
||||||
final ImmutableList.Builder<Comment> builder = ImmutableList.builder();
|
final ImmutableList.Builder<Comment> builder = ImmutableList.builder();
|
||||||
if (isReply) {
|
if (isReply) {
|
||||||
// in a reply list the first comment is the parent comment
|
// replies are added to the bottom of the list to preserve chronological order
|
||||||
builder.add(list.get(0))
|
builder.addAll(list)
|
||||||
.add(comment)
|
.add(comment);
|
||||||
.addAll(list.subList(1, list.size()));
|
|
||||||
} else {
|
} else {
|
||||||
builder.add(comment)
|
builder.add(comment)
|
||||||
.addAll(list);
|
.addAll(list);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
<string name="title_favorites">Favorites</string>
|
<string name="title_favorites">Favorites</string>
|
||||||
<string name="title_discover">Discover</string>
|
<string name="title_discover">Discover</string>
|
||||||
<string name="title_comments">Comments</string>
|
<string name="title_comments">Comments</string>
|
||||||
|
<string name="title_replies">Replies</string>
|
||||||
<string name="title_notifications">Activity</string>
|
<string name="title_notifications">Activity</string>
|
||||||
<string name="update_check">Check for updates at startup</string>
|
<string name="update_check">Check for updates at startup</string>
|
||||||
<string name="flag_secure">Block screenshots & app preview</string>
|
<string name="flag_secure">Block screenshots & app preview</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user