-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathShareButtonAdapter.java
More file actions
104 lines (80 loc) · 2.79 KB
/
Copy pathShareButtonAdapter.java
File metadata and controls
104 lines (80 loc) · 2.79 KB
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
package com.automattic.simplenote.utils;
import android.graphics.drawable.Drawable;
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 com.automattic.simplenote.R;
import java.util.List;
public class ShareButtonAdapter extends RecyclerView.Adapter<ShareButtonAdapter.ViewHolder> {
private List<ShareButtonItem> mItems;
private ItemListener mListener;
public ShareButtonAdapter(List<ShareButtonItem> items, ItemListener listener) {
mItems = items;
mListener = listener;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.share_button_item, parent, false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.setData(mItems.get(position));
}
@Override
public int getItemCount() {
return mItems.size();
}
public interface ItemListener {
void onItemClick(ShareButtonItem item);
}
public static class ShareButtonItem {
private Drawable mDrawableRes;
private CharSequence mTitle;
private String mPackageName;
private String mActivityName;
public ShareButtonItem(Drawable drawable, CharSequence title,
String packageName, String activityName) {
mDrawableRes = drawable;
mTitle = title;
mPackageName = packageName;
mActivityName = activityName;
}
public Drawable getDrawable() {
return mDrawableRes;
}
public CharSequence getTitle() {
return mTitle;
}
public String getPackageName() {
return mPackageName;
}
public String getActivityName() {
return mActivityName;
}
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView button;
public ShareButtonItem item;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
button = itemView.findViewById(R.id.share_button);
}
public void setData(ShareButtonItem item) {
this.item = item;
button.setCompoundDrawablesWithIntrinsicBounds(null, item.getDrawable(), null, null);
button.setText(item.getTitle());
}
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onItemClick(item);
}
}
}
}