blob: 499c55871d1ef28b41a66069b44a8d8175b45eaa (
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
|
package it.niedermann.nextcloud.deck.ui.preparecreate;
import android.os.Build;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import java.util.function.Consumer;
import it.niedermann.nextcloud.deck.databinding.ItemPrepareCreateStackBinding;
import it.niedermann.nextcloud.deck.model.Stack;
import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils;
import it.niedermann.nextcloud.deck.ui.theme.Themed;
class PickStackViewHolder extends RecyclerView.ViewHolder implements Themed {
private final ItemPrepareCreateStackBinding binding;
public PickStackViewHolder(@NonNull ItemPrepareCreateStackBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
public void bind(@NonNull Stack stack, @NonNull Consumer<Stack> onStackSelected, @Nullable Stack selectedStack, @Nullable @ColorInt Integer color) {
binding.stackTitle.setText(stack.getTitle());
itemView.setSelected(stack.getLocalId().equals(selectedStack == null ? -1 : selectedStack.getLocalId()));
itemView.setOnClickListener(view -> {
if (!itemView.isSelected()) {
onStackSelected.accept(stack);
}
});
if (color != null) {
applyTheme(color);
}
}
@Override
public void applyTheme(@ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
final var utils = ThemeUtils.of(color, itemView.getContext());
utils.deck.colorSelectedCheck(binding.selectedCheck.getContext(), binding.selectedCheck.getDrawable());
}
}
}
|