blob: 8128690369aa1be28c954de5a5399ff91cf44567 (
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
|
package Settings;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.R;
class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter<AcknowledgementRecyclerViewAdapter.AcknowledgementViewHolder> {
private ArrayList<Acknowledgement> acknowledgements;
private Context context;
AcknowledgementRecyclerViewAdapter(Context context, ArrayList<Acknowledgement> acknowledgements) {
this.context = context;
this.acknowledgements = acknowledgements;
}
@NonNull
@Override
public AcknowledgementViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new AcknowledgementViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_acknowledgement, parent, false));
}
@Override
public void onBindViewHolder(@NonNull AcknowledgementViewHolder holder, int position) {
Acknowledgement acknowledgement = acknowledgements.get(holder.getAdapterPosition());
if(acknowledgement != null) {
holder.nameTextView.setText(acknowledgement.getName());
holder.introductionTextView.setText(acknowledgement.getIntroduction());
holder.itemView.setOnClickListener(view -> {
if(context != null) {
Intent intent = new Intent(context, LinkResolverActivity.class);
intent.setData(acknowledgement.getLink());
context.startActivity(intent);
}
});
}
}
@Override
public int getItemCount() {
return acknowledgements == null ? 0 : acknowledgements.size();
}
class AcknowledgementViewHolder extends RecyclerView.ViewHolder {
View itemView;
@BindView(R.id.name_text_view_item_acknowledgement) TextView nameTextView;
@BindView(R.id.introduction_text_view_item_acknowledgement) TextView introductionTextView;
AcknowledgementViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
this.itemView = itemView;
}
}
}
|