-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurrencyAdapter.java
81 lines (61 loc) · 2.62 KB
/
CurrencyAdapter.java
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
package com.galtech.alibawa.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import com.galtech.alibawa.R;
import com.galtech.alibawa.interfaces.OnCurrencyClickListener;
import com.galtech.alibawa.model.CurrencyInfo;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by Bhavesh on 04-04-2017.
*/
public class CurrencyAdapter extends RecyclerView.Adapter<CurrencyAdapter.MyViewHolder> {
private Context context;
private List<CurrencyInfo.CurrencyBean> currencyBeen;
private int lastCheckedPosition;
private OnCurrencyClickListener onCurrencyClickListener;
public CurrencyAdapter(Context context, List<CurrencyInfo.CurrencyBean> currencyBeen, int position, OnCurrencyClickListener onCurrencyClickListener) {
this.context = context;
this.currencyBeen = currencyBeen;
this.lastCheckedPosition = position;
this.onCurrencyClickListener = onCurrencyClickListener;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.content_currency, parent, false));
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
CurrencyInfo.CurrencyBean info = currencyBeen.get(position);
if (info != null) {
holder.tvCurrency.setText(info.getName_plural() + "\t\t" + info.getCode() + "\t\t" + info.getSymbol_native());
holder.tvCurrency.setChecked(position == lastCheckedPosition);
}
}
@Override
public int getItemCount() {
return currencyBeen != null ? currencyBeen.size() : 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tv_currency)
CheckBox tvCurrency;
public MyViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
tvCurrency.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lastCheckedPosition = getAdapterPosition();
notifyItemRangeChanged(0, currencyBeen.size());
onCurrencyClickListener.onCurrencyClick(currencyBeen.get(getAdapterPosition()));
}
});
}
}
}