Skip to content

Commit f7b18eb

Browse files
committed
Added position taking populateView() overload to FirebaseRecyclerViewAdapter
1 parent 6961408 commit f7b18eb

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

library/src/main/java/com/firebase/ui/FirebaseListAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public View getView(int position, View view, ViewGroup viewGroup) {
143143
* You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object)} method
144144
* but not both.
145145
*
146-
146+
* @param v The view to populate
147+
* @param model The object containing the data used to populate the view
147148
* @param position The position in the list of the view being populated
148149
*/
149150
protected void populateView(View v, T model, int position) {

library/src/main/java/com/firebase/ui/FirebaseRecyclerViewAdapter.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void onChanged(EventType type, int index, int oldIndex) {
133133
* combination of <code>limit()</code>, <code>startAt()</code>, and <code>endAt()</code>
134134
*/
135135
public FirebaseRecyclerViewAdapter(Class<T> modelClass, int modelLayout, Class<VH> viewHolderClass, Firebase ref) {
136-
this(modelClass, modelLayout, viewHolderClass, (Query)ref);
136+
this(modelClass, modelLayout, viewHolderClass, (Query) ref);
137137
}
138138

139139

@@ -175,11 +175,39 @@ public VH onCreateViewHolder(ViewGroup parent, int viewType) {
175175
}
176176
}
177177
@Override
178-
public void onBindViewHolder(VH viewHolder, int i) {
179-
T model = getItem(i);
180-
populateViewHolder(viewHolder, model);
178+
public void onBindViewHolder(VH viewHolder, int position) {
179+
T model = getItem(position);
180+
populateViewHolder(viewHolder, model, position);
181181
}
182182

183-
abstract public void populateViewHolder(VH viewHolder, T model);
183+
/**
184+
* Each time the data at the given Firebase location changes, this method will be called for each item that needs
185+
* to be displayed. The first two arguments correspond to the mLayout and mModelClass given to the constructor of
186+
* this class. The third argument is the item's position in the list.
187+
* <p>
188+
* Your implementation should populate the view using the data contained in the model.
189+
* You should implement either this method or the other {@link FirebaseRecyclerViewAdapter#populateViewHolder(VH, Object)} method
190+
* but not both.
191+
*
192+
* @param viewHolder The view to populate
193+
* @param model The object containing the data used to populate the view
194+
* @param position The position in the list of the view being populated
195+
*/
196+
protected void populateViewHolder(VH viewHolder, T model, int position) {
197+
populateViewHolder(viewHolder, model);
198+
};
199+
/**
200+
* This is a backwards compatible version of populateViewHolder.
201+
* <p>
202+
* You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object, int)} method
203+
* but not both.
204+
*
205+
* @see FirebaseListAdapter#populateView(View, Object, int)
206+
*
207+
* @param viewHolder The view to populate
208+
* @param model The object containing the data used to populate the view
209+
*/
210+
protected void populateViewHolder(VH viewHolder, T model) {
211+
};
184212

185213
}

0 commit comments

Comments
 (0)