Search in sources :

Example 1 with Comment

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);
}
Also used : Context(android.content.Context) ContextMenu(android.view.ContextMenu) Setter(lombok.Setter) DateUtils(android.text.format.DateUtils) Getter(lombok.Getter) NonNull(androidx.annotation.NonNull) Lbry(com.odysee.app.utils.Lbry) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) Comment(com.odysee.app.model.Comment) Menu(android.view.Menu) LbryUri(com.odysee.app.utils.LbryUri) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Reactions(com.odysee.app.model.Reactions) Build(android.os.Build) ContextCompat(androidx.core.content.ContextCompat) AccountManager(android.accounts.AccountManager) RequestOptions(com.bumptech.glide.request.RequestOptions) Account(android.accounts.Account) LayoutInflater(android.view.LayoutInflater) Helper(com.odysee.app.utils.Helper) Claim(com.odysee.app.model.Claim) PorterDuff(android.graphics.PorterDuff) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) List(java.util.List) ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) R(com.odysee.app.R) Comment(com.odysee.app.model.Comment)

Example 2 with Comment

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);
    }
}
Also used : Comment(com.odysee.app.model.Comment)

Example 3 with Comment

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();
}
Also used : Comment(com.odysee.app.model.Comment) ArrayList(java.util.ArrayList) LbryUri(com.odysee.app.utils.LbryUri)

Example 4 with Comment

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);
    }
}
Also used : Context(android.content.Context) Comment(com.odysee.app.model.Comment) CommentListHandler(com.odysee.app.tasks.CommentListHandler) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) CommentListTask(com.odysee.app.tasks.CommentListTask)

Example 5 with Comment

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;
}
Also used : Comment(com.odysee.app.model.Comment) Claim(com.odysee.app.model.Claim)

Aggregations

Comment (com.odysee.app.model.Comment)19 ArrayList (java.util.ArrayList)9 Context (android.content.Context)8 MainActivity (com.odysee.app.MainActivity)8 Claim (com.odysee.app.model.Claim)8 Account (android.accounts.Account)7 AccountManager (android.accounts.AccountManager)7 View (android.view.View)7 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 IOException (java.io.IOException)6 JSONException (org.json.JSONException)6 AdapterView (android.widget.AdapterView)5 NestedScrollView (androidx.core.widget.NestedScrollView)5 ApiCallException (com.odysee.app.exceptions.ApiCallException)5 Reactions (com.odysee.app.model.Reactions)5 Bundle (android.os.Bundle)4 ViewGroup (android.view.ViewGroup)4 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)4