use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class CommentListAdapter method switchRepliesVisibility.
/**
* Adds the parent ids for the items which should be shown on the recycler view
* @param parentId IDs of Comments which must be visible
*/
private void switchRepliesVisibility(String parentId) {
int firstChild = -1;
int lastIndex;
// By calculating the range of items which will be hidden/displayed and then
// using it on the notification to the adapter, RecyclerView optimizes the change
// and also animates it -for free!!!-
Comment parentComment = items.stream().filter(c -> c.getId().equalsIgnoreCase(parentId)).findFirst().orElse(null);
int parentPosition = items.indexOf(parentComment);
List<Comment> directChilds = items.stream().filter(c -> c.getParentId() != null && c.getParentId().equalsIgnoreCase(parentId)).collect(Collectors.toList());
Comment lastChildCandidate = directChilds.get(directChilds.size() - 1);
lastIndex = items.indexOf(lastChildCandidate);
if (directChilds.size() > 1) {
String lastChildCandidateId = lastChildCandidate.getId();
List<Comment> lastGlobalChildCandidates = items.stream().filter(c -> {
if (c.getParentId() != null && c.getParentId().equalsIgnoreCase(lastChildCandidateId)) {
return true;
} else {
return false;
}
}).collect(Collectors.toList());
if (lastGlobalChildCandidates.size() > 0) {
// Last child candidate has more childs
boolean isLast = false;
String candidateParentId = lastGlobalChildCandidates.get(lastGlobalChildCandidates.size() - 1).getId();
while (!isLast) {
String finalCandidateParentId = candidateParentId;
List<Comment> candidates = items.stream().filter(c -> c.getParentId() != null && c.getParentId().equalsIgnoreCase(finalCandidateParentId)).collect(Collectors.toList());
isLast = containsLastChild(candidates);
if (!isLast) {
candidateParentId = candidates.get(candidates.size() - 1).getId();
}
}
String finalCandidateId = candidateParentId;
Comment lastComment = items.stream().filter(c -> c.getId().equalsIgnoreCase(finalCandidateId)).findFirst().orElse(null);
lastIndex = items.indexOf(lastComment);
}
}
Comment firstChildComment = items.stream().filter(c -> (c.getParentId() != null && c.getParentId().equalsIgnoreCase(parentId))).findFirst().orElse(null);
if (firstChildComment != null) {
firstChild = items.indexOf(firstChildComment);
}
// RecyclerView will display any item which parentId was contained on childsToBeShown
if (!childsToBeShown.contains(parentId)) {
childsToBeShown.add(parentId);
} else {
childsToBeShown.remove(parentId);
// Also remove child parentIds from the list so child replies are also collapsed
for (int i = firstChild; i < lastIndex; i++) {
childsToBeShown.remove(items.get(i).getParentId());
}
}
notifyItemRangeChanged(parentPosition, lastIndex - parentPosition + 1);
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class CommentListAdapter method removeComment.
/**
* Removes the given comment and any children from the tree.
*/
public void removeComment(final Comment commentToRemove) {
if (items.contains(commentToRemove)) {
for (int i = items.size() - 1; i >= 0; i--) {
final Comment ith = items.get(i);
boolean remove = false;
if (ith.getId().equals(commentToRemove.getId())) {
remove = true;
} else {
// Have to travel up the potential reply chain to remove all children.
String parentId = ith.getParentId();
while (parentId != null) {
final Comment parentComment = getCommentForId(parentId);
if (parentComment != null) {
if (parentComment.getId() == commentToRemove.getId()) {
remove = true;
break;
}
} else {
break;
}
parentId = parentComment.getParentId();
}
}
if (remove == true) {
items.remove(i);
childsToBeShown.remove(commentToRemove.getId());
}
}
notifyDataSetChanged();
/**
* For some reason getting out of bounds exception in {@link CommentItemDecoration} so doing the blanket {@link #notifyDataSetChanged()}.
*/
// notifyItemRemoved(indexOfComment);
}
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class CommentListAdapter method filterBlockedChannels.
public void filterBlockedChannels(List<LbryUri> blockedChannels) {
if (blockedChannels.size() == 0) {
return;
}
List<Comment> commentsToRemove = new ArrayList<>();
List<String> blockedChannelClaimIds = new ArrayList<>();
for (LbryUri uri : blockedChannels) {
blockedChannelClaimIds.add(uri.getClaimId());
}
for (Comment comment : items) {
if (comment.getPoster() != null && blockedChannelClaimIds.contains(comment.getPoster().getClaimId())) {
commentsToRemove.add(comment);
}
}
items.removeAll(commentsToRemove);
notifyDataSetChanged();
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method loadComments.
private void loadComments() {
View root = getView();
if (claim != null && root != null) {
ProgressBar relatedLoading = root.findViewById(R.id.channel_comments_progress);
CommentListTask task = new CommentListTask(1, 200, claim.getClaimId(), relatedLoading, new CommentListHandler() {
@Override
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
Context ctx = getContext();
View root = getView();
if (ctx != null && root != null) {
ensureCommentListAdapterCreated(comments);
}
}
@Override
public void onError(Exception error) {
// pass
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method buildPostComment.
private Comment buildPostComment() {
Comment comment = new Comment();
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
comment.setClaimId(claim.getClaimId());
comment.setChannelId(channel.getClaimId());
comment.setChannelName(channel.getName());
comment.setText(Helper.getValue(inputComment.getText()));
comment.setPoster(channel);
if (replyToComment != null) {
comment.setParentId(replyToComment.getId());
}
return comment;
}
Aggregations