That fuck shit the fascists are using
1package org.tm.archive.blocked;
2
3import android.view.LayoutInflater;
4import android.view.View;
5import android.view.ViewGroup;
6import android.widget.TextView;
7
8import androidx.annotation.NonNull;
9import androidx.core.util.Consumer;
10import androidx.recyclerview.widget.DiffUtil;
11import androidx.recyclerview.widget.ListAdapter;
12import androidx.recyclerview.widget.RecyclerView;
13
14import org.tm.archive.R;
15import org.tm.archive.components.AvatarImageView;
16import org.tm.archive.phonenumbers.PhoneNumberFormatter;
17import org.tm.archive.recipients.Recipient;
18import org.whispersystems.signalservice.api.util.OptionalUtil;
19
20import java.util.Objects;
21
22final class BlockedUsersAdapter extends ListAdapter<Recipient, BlockedUsersAdapter.ViewHolder> {
23
24 private final RecipientClickedListener recipientClickedListener;
25
26 BlockedUsersAdapter(@NonNull RecipientClickedListener recipientClickedListener) {
27 super(new RecipientDiffCallback());
28
29 this.recipientClickedListener = recipientClickedListener;
30 }
31
32 @Override
33 public @NonNull ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
34 return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.blocked_users_adapter_item, parent, false),
35 position -> recipientClickedListener.onRecipientClicked(Objects.requireNonNull(getItem(position))));
36 }
37
38 @Override
39 public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
40 holder.bind(Objects.requireNonNull(getItem(position)));
41 }
42
43 static final class ViewHolder extends RecyclerView.ViewHolder {
44
45 private final AvatarImageView avatar;
46 private final TextView displayName;
47 private final TextView numberOrUsername;
48
49 public ViewHolder(@NonNull View itemView, Consumer<Integer> clickConsumer) {
50 super(itemView);
51
52 this.avatar = itemView.findViewById(R.id.avatar);
53 this.displayName = itemView.findViewById(R.id.display_name);
54 this.numberOrUsername = itemView.findViewById(R.id.number_or_username);
55
56 itemView.setOnClickListener(unused -> {
57 if (getAdapterPosition() != RecyclerView.NO_POSITION) {
58 clickConsumer.accept(getAdapterPosition());
59 }
60 });
61 }
62
63 public void bind(@NonNull Recipient recipient) {
64 avatar.setAvatar(recipient);
65 displayName.setText(recipient.getDisplayName(itemView.getContext()));
66
67 if (recipient.hasAUserSetDisplayName(itemView.getContext())) {
68 String identifier = OptionalUtil.or(recipient.getE164().map(PhoneNumberFormatter::prettyPrint),
69 recipient.getUsername())
70 .orElse(null);
71
72 if (identifier != null) {
73 numberOrUsername.setText(identifier);
74 numberOrUsername.setVisibility(View.VISIBLE);
75 } else {
76 numberOrUsername.setVisibility(View.GONE);
77 }
78 } else {
79 numberOrUsername.setVisibility(View.GONE);
80 }
81 }
82 }
83
84 private static final class RecipientDiffCallback extends DiffUtil.ItemCallback<Recipient> {
85
86 @Override
87 public boolean areItemsTheSame(@NonNull Recipient oldItem, @NonNull Recipient newItem) {
88 return oldItem.equals(newItem);
89 }
90
91 @Override
92 public boolean areContentsTheSame(@NonNull Recipient oldItem, @NonNull Recipient newItem) {
93 return oldItem.equals(newItem);
94 }
95 }
96
97 interface RecipientClickedListener {
98 void onRecipientClicked(@NonNull Recipient recipient);
99 }
100}