blob: aa7e930a1d32c513bad53b95f7f1f0964503f84e (
plain) (
blame)
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
|
package ml.docilealligator.infinityforreddit.adapters;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.SettingsActivity;
import ml.docilealligator.infinityforreddit.databinding.ItemAcknowledgementBinding;
import ml.docilealligator.infinityforreddit.settings.Acknowledgement;
public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter<AcknowledgementRecyclerViewAdapter.AcknowledgementViewHolder> {
private final ArrayList<Acknowledgement> acknowledgements;
private final SettingsActivity activity;
public AcknowledgementRecyclerViewAdapter(SettingsActivity activity, ArrayList<Acknowledgement> acknowledgements) {
this.activity = activity;
this.acknowledgements = acknowledgements;
}
@NonNull
@Override
public AcknowledgementViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new AcknowledgementViewHolder(ItemAcknowledgementBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull AcknowledgementViewHolder holder, int position) {
Acknowledgement acknowledgement = acknowledgements.get(holder.getBindingAdapterPosition());
if (acknowledgement != null) {
holder.binding.nameTextViewItemAcknowledgement.setText(acknowledgement.getName());
holder.binding.introductionTextViewItemAcknowledgement.setText(acknowledgement.getIntroduction());
holder.itemView.setOnClickListener(view -> {
if (activity != null) {
Intent intent = new Intent(activity, LinkResolverActivity.class);
intent.setData(acknowledgement.getLink());
activity.startActivity(intent);
}
});
}
}
@Override
public int getItemCount() {
return acknowledgements == null ? 0 : acknowledgements.size();
}
class AcknowledgementViewHolder extends RecyclerView.ViewHolder {
ItemAcknowledgementBinding binding;
AcknowledgementViewHolder(@NonNull ItemAcknowledgementBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.nameTextViewItemAcknowledgement.setTextColor(activity.customThemeWrapper.getPrimaryTextColor());
binding.introductionTextViewItemAcknowledgement.setTextColor(activity.customThemeWrapper.getSecondaryTextColor());
if (activity.typeface != null) {
binding.nameTextViewItemAcknowledgement.setTypeface(activity.typeface);
binding.introductionTextViewItemAcknowledgement.setTypeface(activity.typeface);
}
}
}
}
|