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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
package it.niedermann.nextcloud.deck.ui.card;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.MenuRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.google.android.material.card.MaterialCardView;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.databinding.ItemCardDefaultBinding;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.full.FullCard;
public class DefaultCardViewHolder extends AbstractCardViewHolder {
private final ItemCardDefaultBinding binding;
private final int maxCoverImagesCount;
@SuppressWarnings("WeakerAccess")
public DefaultCardViewHolder(@NonNull ItemCardDefaultBinding binding, int maxCoverImagesCount) {
super(binding.getRoot());
this.binding = binding;
this.maxCoverImagesCount = maxCoverImagesCount;
}
/**
* Removes all {@link OnClickListener} and {@link OnLongClickListener}
*/
@Override
public void bind(@NonNull FullCard fullCard, @NonNull Account account, @Nullable Long boardRemoteId, boolean hasEditPermission, @MenuRes int optionsMenu, @NonNull CardOptionsItemSelectedListener optionsItemsSelectedListener, @NonNull String counterMaxValue, @ColorInt int mainColor) {
super.bind(fullCard, account, boardRemoteId, hasEditPermission, optionsMenu, optionsItemsSelectedListener, counterMaxValue, mainColor);
final var context = itemView.getContext();
if (fullCard.getAssignedUsers() != null && fullCard.getAssignedUsers().size() > 0) {
binding.overlappingAvatars.setAvatars(account, fullCard.getAssignedUsers());
binding.overlappingAvatars.setVisibility(View.VISIBLE);
} else {
binding.overlappingAvatars.setVisibility(View.GONE);
}
setupCoverImages(account, binding.coverImages, fullCard, maxCoverImagesCount);
final int attachmentsCount = fullCard.getAttachments().size();
if (attachmentsCount == 0) {
binding.cardCountAttachments.setVisibility(View.GONE);
} else {
setupCounter(binding.cardCountAttachments, counterMaxValue, attachmentsCount);
binding.cardCountAttachments.setVisibility(View.VISIBLE);
}
final int commentsCount = fullCard.getCommentCount();
if (commentsCount == 0) {
binding.cardCountComments.setVisibility(View.GONE);
} else {
setupCounter(binding.cardCountComments, counterMaxValue, commentsCount);
binding.cardCountComments.setVisibility(View.VISIBLE);
}
final var labels = fullCard.getLabels();
if (labels != null && labels.size() > 0) {
binding.labels.updateLabels(labels);
binding.labels.setVisibility(View.VISIBLE);
} else {
binding.labels.removeAllViews();
binding.labels.setVisibility(View.GONE);
}
final var taskStatus = fullCard.getCard().getTaskStatus();
if (taskStatus.taskCount > 0) {
binding.cardCountTasks.setText(context.getResources().getString(R.string.task_count, String.valueOf(taskStatus.doneCount), String.valueOf(taskStatus.taskCount)));
binding.cardCountTasks.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context, R.drawable.ic_check_grey600_24dp), null, null, null);
binding.cardCountTasks.setVisibility(View.VISIBLE);
} else {
final String description = fullCard.getCard().getDescription();
if (!TextUtils.isEmpty(description)) {
binding.cardCountTasks.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(context, R.drawable.ic_baseline_subject_24), null, null, null);
binding.cardCountTasks.setText(null);
binding.cardCountTasks.setVisibility(View.VISIBLE);
} else {
binding.cardCountTasks.setVisibility(View.GONE);
}
}
}
@Override
protected TextView getCardDueDate() {
return binding.cardDueDate;
}
@Override
protected ImageView getNotSyncedYet() {
return binding.notSyncedYet;
}
@Override
protected TextView getCardTitle() {
return binding.cardTitle;
}
@Override
protected View getCardMenu() {
return binding.cardMenu;
}
@Override
protected MaterialCardView getCard() {
return binding.card;
}
public void bindCardClickListener(@Nullable OnClickListener l) {
binding.card.setOnClickListener(l);
}
public void bindCardLongClickListener(@Nullable OnLongClickListener l) {
binding.card.setOnLongClickListener(l);
}
public MaterialCardView getDraggable() {
return binding.card;
}
private static void setupCounter(@NonNull TextView textView, @NonNull String counterMaxValue, int count) {
if (count > 99) {
textView.setText(counterMaxValue);
} else if (count > 1) {
textView.setText(String.valueOf(count));
} else if (count == 1) {
textView.setText("");
}
}
}
|