Search in sources :

Example 16 with Comment

use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.

the class CommentItemDecoration method getItemOffsets.

@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, RecyclerView parent, @NonNull RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    CommentListAdapter adapter = (CommentListAdapter) parent.getAdapter();
    if (adapter != null) {
        Comment comment = adapter.items.get(position);
        if (comment.getParentId() != null) {
            outRect.left = marginInPx;
        }
    }
}
Also used : Comment(com.odysee.app.model.Comment)

Example 17 with Comment

use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.

the class CommentListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    Comment comment = items.get(position);
    switchViewReplies(comment, (TextView) holder.viewReplies);
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
    if (collapsed || (comment.getParentId() != null && !childsToBeShown.contains(comment.getParentId()))) {
        holder.itemView.setVisibility(View.GONE);
        lp.height = 0;
        lp.width = 0;
        holder.itemView.setLayoutParams(lp);
    } else {
        if (comment.getParentId() == null || (comment.getParentId() != null && childsToBeShown.contains(comment.getParentId()))) {
            lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
            holder.itemView.setLayoutParams(lp);
            holder.itemView.setVisibility(View.VISIBLE);
        }
    }
    holder.comment = comment;
    holder.blockChannelView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Claim channel = comment.getPoster();
            if (channel != null) {
                if (context instanceof MainActivity) {
                    ((MainActivity) context).handleBlockChannel(channel);
                }
            }
        }
    });
    if (CommentAction.areAnyActionsAvailable(comment, claim)) {
        holder.moreOptionsView.setVisibility(collapsed ? View.INVISIBLE : View.VISIBLE);
        holder.moreOptionsView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                view.showContextMenu();
            }
        });
    } else {
        holder.moreOptionsView.setVisibility(View.INVISIBLE);
        holder.moreOptionsView.setOnClickListener(null);
    }
    holder.channelName.setText(comment.getChannelName());
    holder.commentTimeView.setText(DateUtils.getRelativeTimeSpanString((comment.getTimestamp() * 1000), System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
    holder.commentText.setText(comment.getText());
    Reactions commentReactions = comment.getReactions();
    if (commentReactions != null) {
        int countTextColor;
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
            countTextColor = context.getResources().getColor(R.color.foreground, null);
        } else {
            countTextColor = context.getResources().getColor(R.color.foreground);
        }
        String likesAmount = String.valueOf(commentReactions.getOthersLikes());
        String dislikesAmount = String.valueOf(commentReactions.getOthersDislikes());
        if (commentReactions.isLiked()) {
            int fireActive;
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
                fireActive = context.getResources().getColor(R.color.fireActive, null);
            } else {
                fireActive = context.getResources().getColor(R.color.fireActive);
            }
            holder.likesCount.setText(String.valueOf(Integer.parseInt(likesAmount) + 1));
            holder.likesCount.setTextColor(fireActive);
            for (Drawable d : holder.likesCount.getCompoundDrawablesRelative()) {
                if (d != null) {
                    d.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(holder.likesCount.getContext(), R.color.fireActive), PorterDuff.Mode.SRC_IN));
                }
            }
        } else {
            holder.likesCount.setText(likesAmount);
            holder.likesCount.setTextColor(countTextColor);
            for (Drawable d : holder.likesCount.getCompoundDrawablesRelative()) {
                if (d != null) {
                    d.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(holder.likesCount.getContext(), R.color.foreground), PorterDuff.Mode.SRC_IN));
                }
            }
        }
        if (commentReactions.isDisliked()) {
            int slimeActive;
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
                slimeActive = context.getResources().getColor(R.color.slimeActive, null);
            } else {
                slimeActive = context.getResources().getColor(R.color.slimeActive);
            }
            holder.dislikesCount.setText(String.valueOf(Integer.parseInt(dislikesAmount) + 1));
            holder.dislikesCount.setTextColor(slimeActive);
            for (Drawable d : holder.dislikesCount.getCompoundDrawablesRelative()) {
                if (d != null) {
                    d.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(holder.dislikesCount.getContext(), R.color.slimeActive), PorterDuff.Mode.SRC_IN));
                }
            }
        } else {
            holder.dislikesCount.setText(dislikesAmount);
            holder.dislikesCount.setTextColor(countTextColor);
            for (Drawable d : holder.dislikesCount.getCompoundDrawablesRelative()) {
                if (d != null) {
                    d.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(holder.dislikesCount.getContext(), R.color.foreground), PorterDuff.Mode.SRC_IN));
                }
            }
        }
    }
    holder.likesCount.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AccountManager am = AccountManager.get(context);
            Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
            if (odyseeAccount != null && comment.getClaimId() != null && commentListListener != null) {
                commentListListener.onCommentReactClicked(comment, true);
            }
        }
    });
    holder.dislikesCount.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AccountManager am = AccountManager.get(context);
            Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
            if (odyseeAccount != null && comment.getClaimId() != null && commentListListener != null) {
                commentListListener.onCommentReactClicked(comment, false);
            }
        }
    });
    boolean hasThumbnail = comment.getPoster() != null && !Helper.isNullOrEmpty(comment.getPoster().getThumbnailUrl());
    holder.thumbnailView.setVisibility(hasThumbnail ? View.VISIBLE : View.INVISIBLE);
    holder.noThumbnailView.setVisibility(!hasThumbnail ? View.VISIBLE : View.INVISIBLE);
    int bgColor = Helper.generateRandomColorForValue(comment.getChannelId());
    Helper.setIconViewBackgroundColor(holder.noThumbnailView, bgColor, false, context);
    if (hasThumbnail) {
        Glide.with(context.getApplicationContext()).asBitmap().load(comment.getPoster().getThumbnailUrl(holder.thumbnailView.getLayoutParams().width, holder.thumbnailView.getLayoutParams().height, 85)).apply(RequestOptions.circleCropTransform()).into(holder.thumbnailView);
    }
    holder.alphaView.setText(comment.getChannelName() != null ? comment.getChannelName().substring(1, 2).toUpperCase() : null);
    holder.channelName.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null && comment.getPoster() != null) {
                listener.onClaimClicked(comment.getPoster(), position);
            }
        }
    });
    holder.replyLink.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (commentListListener != null) {
                commentListListener.onReplyClicked(comment);
            }
        }
    });
    if (position != (items.size() - 1)) {
        String pId = items.get(position + 1).getParentId();
        if (pId != null && pId.equalsIgnoreCase(comment.getId())) {
            holder.viewReplies.setVisibility(View.VISIBLE);
            holder.viewReplies.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    switchRepliesVisibility(comment.getId());
                    switchViewReplies(comment, (TextView) holder.viewReplies);
                }
            });
        } else {
            holder.viewReplies.setVisibility(View.GONE);
        }
    } else {
        holder.viewReplies.setVisibility(View.GONE);
    }
}
Also used : Comment(com.odysee.app.model.Comment) Account(android.accounts.Account) ViewGroup(android.view.ViewGroup) Reactions(com.odysee.app.model.Reactions) Drawable(android.graphics.drawable.Drawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) MainActivity(com.odysee.app.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AccountManager(android.accounts.AccountManager) TextView(android.widget.TextView) Claim(com.odysee.app.model.Claim)

Example 18 with Comment

use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.

the class CommentListAdapter method addReply.

public void addReply(Comment comment) {
    Comment c = items.stream().filter(v -> comment.getParentId().equalsIgnoreCase(v.getId())).findFirst().orElse(null);
    if (c != null) {
        int positionToInsert = items.indexOf(c) + 1;
        items.add(positionToInsert, comment);
        notifyItemInserted(positionToInsert);
    }
}
Also used : Comment(com.odysee.app.model.Comment)

Example 19 with Comment

use of com.odysee.app.model.Comment in project odysee-android by OdyseeTeam.

the class CommentListTask method doInBackground.

protected List<Comment> doInBackground(Void... voids) {
    List<Comment> comments = null;
    try {
        Map<String, Object> options = new HashMap<>();
        options.put("claim_id", claim);
        options.put("page", page);
        options.put("page_size", pageSize);
        options.put("hidden", false);
        options.put("include_replies", false);
        options.put("is_channel_signature_valid", true);
        options.put("skip_validation", true);
        options.put("visible", true);
        JSONObject result = (JSONObject) Lbry.parseResponse(Comments.performRequest(Lbry.buildJsonParams(options), "comment.List"));
        if (result != null && result.has("items")) {
            JSONArray items = result.getJSONArray("items");
            List<Comment> children = new ArrayList<>();
            comments = new ArrayList<>();
            for (int i = 0; i < items.length(); i++) {
                Comment comment = Comment.fromJSONObject(items.getJSONObject(i));
                if (comment != null) {
                    if (!Helper.isNullOrEmpty(comment.getParentId())) {
                        children.add(comment);
                    } else {
                        comments.add(comment);
                    }
                }
            }
            // Sort all replies from oldest to newest at once and then group them by its parent comment
            Collections.sort(children);
            Map<String, List<Comment>> groupedChildrenList = children.stream().collect(groupingBy(Comment::getParentId));
            List<Comment> finalComments = comments;
            groupedChildrenList.forEach((key, value) -> {
                Comment c = finalComments.stream().filter(v -> key.equalsIgnoreCase(v.getId())).findFirst().orElse(null);
                finalComments.addAll(finalComments.indexOf(c) + 1, value);
            });
            comments = finalComments;
        }
    } catch (JSONException | LbryResponseException | IOException ex) {
        error = ex;
    }
    return comments;
}
Also used : Comment(com.odysee.app.model.Comment) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) IOException(java.io.IOException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List)

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