Search in sources :

Example 96 with Claim

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

the class ClaimListAdapter method addItems.

public void addItems(List<Claim> claims) {
    final int initialCount = items.size();
    for (Claim claim : claims) {
        if (claim != null) {
            boolean c = items.stream().anyMatch(p -> p.getClaimId() != null && p.getClaimId().equalsIgnoreCase(claim.getClaimId()));
            if (!c) {
                items.add(claim);
            }
        }
    }
    notifyItemRangeInserted(initialCount, items.size() - initialCount);
    notFoundClaimUrlMap.clear();
    notFoundClaimIdMap.clear();
}
Also used : SuppressLint(android.annotation.SuppressLint) Claim(com.odysee.app.model.Claim)

Example 97 with Claim

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

the class ClaimListAdapter method filterBlockedChannels.

public void filterBlockedChannels(List<LbryUri> blockedChannels) {
    if (blockedChannels.size() == 0) {
        return;
    }
    List<String> blockedChannelClaimIds = new ArrayList<>();
    for (LbryUri uri : blockedChannels) {
        blockedChannelClaimIds.add(uri.getClaimId());
    }
    for (Claim claim : items) {
        if (claim.getSigningChannel() != null && blockedChannelClaimIds.contains(claim.getSigningChannel().getClaimId())) {
            int position = items.indexOf(claim);
            items.remove(claim);
            notifyItemRemoved(position);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LbryUri(com.odysee.app.utils.LbryUri) Claim(com.odysee.app.model.Claim) SuppressLint(android.annotation.SuppressLint)

Example 98 with Claim

use of com.odysee.app.model.Claim 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 99 with Claim

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

the class SuggestedChannelGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(SuggestedChannelGridAdapter.ViewHolder vh, int position) {
    Claim claim = items.get(position);
    ViewGroup.LayoutParams lp = vh.thumbnailView.getLayoutParams();
    String thumbnailUrl = claim.getThumbnailUrl(lp.width, lp.height, 85);
    int bgColor = Helper.generateRandomColorForValue(claim.getClaimId());
    Helper.setIconViewBackgroundColor(vh.noThumbnailView, bgColor, false, context);
    vh.noThumbnailView.setVisibility(Helper.isNullOrEmpty(thumbnailUrl) ? View.INVISIBLE : View.VISIBLE);
    vh.alphaView.setText(claim.getName().substring(1, 2));
    if (!Helper.isNullOrEmpty(thumbnailUrl)) {
        vh.thumbnailView.setVisibility(View.VISIBLE);
        Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
    } else {
        vh.thumbnailView.setVisibility(View.GONE);
    }
    vh.titleView.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle());
    String firstTag = claim.getFirstTag();
    vh.tagView.setVisibility(Helper.isNullOrEmpty(firstTag) ? View.INVISIBLE : View.VISIBLE);
    vh.tagView.setBackgroundResource(R.drawable.bg_tag);
    vh.tagView.setText(firstTag);
    vh.itemView.setSelected(isClaimSelected(claim));
    vh.itemView.setOnClickListener(view -> {
        if (selectedItems.contains(claim)) {
            selectedItems.remove(claim);
            if (listener != null) {
                listener.onChannelItemDeselected(claim);
            }
        } else {
            selectedItems.add(claim);
            if (listener != null) {
                listener.onChannelItemSelected(claim);
            }
        }
        notifyDataSetChanged();
    });
}
Also used : ViewGroup(android.view.ViewGroup) Claim(com.odysee.app.model.Claim)

Example 100 with Claim

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

the class InlineChannelSpinnerAdapter method createView.

private View createView(int position, View convertView, ViewGroup parent) {
    View view = inflater.inflate(layoutResourceId, parent, false);
    Context context = getContext();
    Claim channel = getItem(position);
    String name = channel.getName();
    if (channel.isPlaceholder()) {
        name = context.getString(R.string.create_a_channel);
    } else if (channel.isPlaceholderAnonymous()) {
        name = context.getString(R.string.anonymous);
    }
    TextView label = view.findViewById(R.id.channel_item_name);
    label.setText(name);
    return view;
}
Also used : Context(android.content.Context) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)133 Context (android.content.Context)51 MainActivity (com.odysee.app.MainActivity)44 JSONException (org.json.JSONException)42 View (android.view.View)41 TextView (android.widget.TextView)37 RecyclerView (androidx.recyclerview.widget.RecyclerView)36 ApiCallException (com.odysee.app.exceptions.ApiCallException)36 ArrayList (java.util.ArrayList)32 ImageView (android.widget.ImageView)31 AdapterView (android.widget.AdapterView)29 NestedScrollView (androidx.core.widget.NestedScrollView)28 ClaimListResultHandler (com.odysee.app.tasks.claim.ClaimListResultHandler)26 JSONObject (org.json.JSONObject)26 ExecutionException (java.util.concurrent.ExecutionException)25 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)24 LbryUriException (com.odysee.app.exceptions.LbryUriException)24 SolidIconView (com.odysee.app.ui.controls.SolidIconView)24 WebView (android.webkit.WebView)23 PhotoView (com.github.chrisbanes.photoview.PhotoView)23