use of com.odysee.app.tasks.CommentListTask 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.tasks.CommentListTask in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadComments.
private void loadComments() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
View root = getView();
if (root != null && actualClaim != null) {
ProgressBar commentsLoading = root.findViewById(R.id.file_view_comments_progress);
CommentListTask task = new CommentListTask(1, 200, actualClaim.getClaimId(), commentsLoading, new CommentListHandler() {
@Override
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
if (!comments.isEmpty()) {
// Load and process comments reactions on a different thread so main thread is not blocked
Helper.setViewVisibility(commentsLoading, View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
Map<String, Reactions> commentReactions = loadReactions(comments);
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Helper.setViewVisibility(commentsLoading, View.GONE);
processCommentReactions(comments, commentReactions);
}
});
}
}
}).start();
}
}
@Override
public void onError(Exception error) {
if (error != null) {
error.printStackTrace();
}
checkNoComments();
}
private void processCommentReactions(List<Comment> comments, Map<String, Reactions> commentReactions) {
for (Comment c : comments) {
if (commentReactions != null) {
c.setReactions(commentReactions.get(c.getId()));
} else {
c.setReactions(new Reactions(0, 0, false, false));
}
}
List<Comment> rootComments = new ArrayList<>();
for (Comment c : comments) {
if (c.getParentId() == null) {
rootComments.add(c);
}
}
if (commentReactions != null) {
Collections.sort(rootComments, new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
int o1SelfLiked = (Lbryio.isSignedIn() && o1.getReactions() != null && o1.getReactions().isLiked()) ? 1 : 0;
int o2SelfLiked = (Lbryio.isSignedIn() && o2.getReactions() != null && o2.getReactions().isLiked()) ? 1 : 0;
int o1OtherLikes = o1.getReactions() != null ? o1.getReactions().getOthersLikes() : 0;
int o2OtherLikes = o2.getReactions() != null ? o2.getReactions().getOthersLikes() : 0;
return (o2OtherLikes + o2SelfLiked) - (o1OtherLikes + o1SelfLiked);
}
});
}
// Direct comments are now sorted by their amount of likes. We can now pick the
// one to be displayed as the collapsed single comment.
Comment singleComment = rootComments.get(0);
TextView commentText = singleCommentRoot.findViewById(R.id.comment_text);
ImageView thumbnailView = singleCommentRoot.findViewById(R.id.comment_thumbnail);
View noThumbnailView = singleCommentRoot.findViewById(R.id.comment_no_thumbnail);
TextView alphaView = singleCommentRoot.findViewById(R.id.comment_thumbnail_alpha);
commentText.setText(singleComment.getText());
commentText.setMaxLines(3);
commentText.setEllipsize(TextUtils.TruncateAt.END);
commentText.setClickable(true);
commentText.setTextIsSelectable(false);
boolean hasThumbnail = singleComment.getPoster() != null && !Helper.isNullOrEmpty(singleComment.getPoster().getThumbnailUrl());
thumbnailView.setVisibility(hasThumbnail ? View.VISIBLE : View.INVISIBLE);
noThumbnailView.setVisibility(!hasThumbnail ? View.VISIBLE : View.INVISIBLE);
int bgColor = Helper.generateRandomColorForValue(singleComment.getChannelId());
Helper.setIconViewBackgroundColor(noThumbnailView, bgColor, false, getContext());
if (hasThumbnail) {
Context ctx = getContext();
if (ctx != null) {
Context appCtx = ctx.getApplicationContext();
Glide.with(appCtx).asBitmap().load(singleComment.getPoster().getThumbnailUrl()).apply(RequestOptions.circleCropTransform()).into(thumbnailView);
}
}
alphaView.setText(singleComment.getChannelName() != null ? singleComment.getChannelName().substring(1, 2).toUpperCase() : null);
singleCommentRoot.findViewById(R.id.comment_actions_area).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_time).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_channel_name).setVisibility(View.GONE);
singleCommentRoot.findViewById(R.id.comment_more_options).setVisibility(View.GONE);
singleCommentRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandButton.performClick();
}
});
List<Comment> parentComments = rootComments;
// rootComments.clear();
for (Comment c : comments) {
if (!parentComments.contains(c)) {
if (c.getParentId() != null) {
Comment item = parentComments.stream().filter(v -> c.getParentId().equalsIgnoreCase(v.getId())).findFirst().orElse(null);
if (item != null) {
parentComments.add(parentComments.indexOf(item) + 1, c);
}
}
}
}
comments = parentComments;
Context ctx = getContext();
View root = getView();
if (ctx != null && root != null) {
ensureCommentListAdapterCreated(comments);
}
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
Aggregations