-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreRecyclerViewAdapter.java
More file actions
99 lines (84 loc) · 3.16 KB
/
StoreRecyclerViewAdapter.java
File metadata and controls
99 lines (84 loc) · 3.16 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
package com.ikai.unit.adapters;
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.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.ikai.unit.R;
import com.ikai.unit.dataModels.StoreDataModel;
import java.util.List;
public class StoreRecyclerViewAdapter extends
RecyclerView.Adapter<StoreRecyclerViewAdapter.ViewHolder>{
private List<StoreDataModel> storeDataModels;
private LayoutInflater mInflater;
private ItemClickListener mClickListener;
private Context context;
/**
* @param context
* @param storeDataModels List of StoreDataModel Objects to show in recyclerview
*/
public StoreRecyclerViewAdapter(Context context, List<StoreDataModel> storeDataModels){
this.storeDataModels = storeDataModels;
}
@Override
public StoreRecyclerViewAdapter.ViewHolder
onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.stores_grid_structure,
parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder
(ViewHolder holder, int position) {
//super.onBindViewHolder(holder, position);
StoreDataModel sdmInstance = storeDataModels.get(position);
String storeName = sdmInstance.getStoreName();
String thumbnailURL = sdmInstance.getStoreThumbnailImage();
boolean favorite = sdmInstance.isFavoriteShop();
holder.storeCardTextView.setText(storeName);
ImageView imageView = holder.storeCardImageView;
Glide.with(this.context)
.load(thumbnailURL)
.into(imageView);
}
@Override
public int getItemCount() {
return storeDataModels.size();
}
/**
* This class will hold all the views to show into RecyclerView
* the layout file here: {stores_grid_structure.xml}
*/
public class ViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener{
ImageView storeCardImageView;
TextView storeCardTextView;
ViewHolder(View itemView) {
super(itemView);
storeCardImageView = itemView.findViewById(R.id.shop_thumbnail);
storeCardTextView = itemView.findViewById(R.id.info_text);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (mClickListener != null)
mClickListener.onItemClick(view, getAdapterPosition());
}
}
// convenience method for getting data at click position
public StoreDataModel getItem(int id) {
return storeDataModels.get(id);
}
// allows clicks events to be caught
public void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
// parent activity will implement this method to respond to click events
public interface ItemClickListener {
void onItemClick(View view, int position);
}
}