Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CardCommentsAdapter.java « comments « card « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 68e23c7d7fc27de1d8ce5343e18dc1df4bc2d46b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package it.niedermann.nextcloud.deck.ui.card.comments;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import it.niedermann.nextcloud.deck.databinding.ItemCommentBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.ocs.comment.full.FullDeckComment;

import static it.niedermann.nextcloud.deck.Application.readBrandMainColor;
import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme;

public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHolder> {

    private int mainColor;
    @NonNull
    private final List<FullDeckComment> comments = new ArrayList<>();
    @NonNull
    private final Account account;
    @NonNull
    private final MenuInflater menuInflater;
    @NonNull
    private final CommentDeletedListener deletedListener;
    @NonNull
    private final CommentSelectAsReplyListener selectAsReplyListener;
    @NonNull
    private final FragmentManager fragmentManager;

    CardCommentsAdapter(@NonNull Context context, @NonNull Account account, @NonNull MenuInflater menuInflater, @NonNull CommentDeletedListener deletedListener, @NonNull CommentSelectAsReplyListener selectAsReplyListener, @NonNull FragmentManager fragmentManager) {
        this.account = account;
        this.menuInflater = menuInflater;
        this.deletedListener = deletedListener;
        this.selectAsReplyListener = selectAsReplyListener;
        this.fragmentManager = fragmentManager;
        this.mainColor = getSecondaryForegroundColorDependingOnTheme(context, readBrandMainColor(context));
        setHasStableIds(true);
    }

    @Override
    public long getItemId(int position) {
        return comments.get(position).getLocalId();
    }

    @NonNull
    @Override
    public ItemCommentViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
        return new ItemCommentViewHolder(ItemCommentBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ItemCommentViewHolder holder, int position) {
        holder.bind(comments.get(position), account, mainColor, menuInflater, deletedListener, selectAsReplyListener, fragmentManager);
    }

    @SuppressWarnings("WeakerAccess")
    public void updateComments(@NonNull List<FullDeckComment> comments) {
        this.comments.clear();
        this.comments.addAll(comments);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return comments.size();
    }
}