1 |
efrain |
1 |
package com.cesams.twogetskills.adapter;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.view.LayoutInflater;
|
|
|
5 |
import android.view.ViewGroup;
|
|
|
6 |
|
|
|
7 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
8 |
|
|
|
9 |
import com.cesams.twogetskills.viewdata.UserProfileViewData;
|
|
|
10 |
import com.cesams.twogetskills.skeleton.IUserProfileDelegateAdapter;
|
|
|
11 |
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
|
|
|
12 |
|
|
|
13 |
import java.util.HashMap;
|
|
|
14 |
import java.util.List;
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
public class UserProfileListViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
|
18 |
private final static String TAG = "C2GS - UserProfileListViewAdapter";
|
|
|
19 |
private List<UserProfileViewData> mData;
|
|
|
20 |
private LayoutInflater mInflater;
|
|
|
21 |
private Context mContext;
|
|
|
22 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
23 |
private HashMap<Integer, IUserProfileDelegateAdapter> adapterHashMap;
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
// data is passed into the constructor
|
|
|
27 |
public UserProfileListViewAdapter(Context context, List<UserProfileViewData> data) {
|
|
|
28 |
this.mContext = context;
|
|
|
29 |
this.iTwoGetSkills = (ITwoGetSkills) context;
|
|
|
30 |
this.mInflater = LayoutInflater.from(context);
|
|
|
31 |
this.mData = data;
|
|
|
32 |
this.adapterHashMap = new HashMap<>();
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
UserProfileListViewHeaderAdapter headerAdapter = new UserProfileListViewHeaderAdapter(mContext);
|
|
|
36 |
UserProfileListViewItemAdapter itemAdapter = new UserProfileListViewItemAdapter(mContext);
|
|
|
37 |
adapterHashMap.put(UserProfileViewData.TYPE_COMPANY, headerAdapter);
|
|
|
38 |
adapterHashMap.put(UserProfileViewData.TYPE_ITEM, itemAdapter);
|
|
|
39 |
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
// inflates the row layout from xml when needed
|
|
|
43 |
@Override
|
|
|
44 |
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
45 |
return adapterHashMap.get(viewType).onCreateViewHolder(parent, viewType);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
// binds the data to the TextView in each row
|
|
|
49 |
@Override
|
|
|
50 |
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
51 |
adapterHashMap.get(getItemViewType(position)).onBindViewHolder(holder, mData.get(position));
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
|
|
55 |
public int getItemViewType(int position) {
|
|
|
56 |
return mData.get(position).getType();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Override
|
|
|
60 |
public int getItemCount() {
|
|
|
61 |
return mData.size();
|
|
|
62 |
}
|
|
|
63 |
}
|