2929package com .firebase .ui ;
3030
3131import android .support .v7 .widget .RecyclerView ;
32- import android .util .Log ;
3332import android .view .LayoutInflater ;
3433import android .view .View ;
3534import android .view .ViewGroup ;
3635
37- import com .firebase .client .ChildEventListener ;
38- import com .firebase .client .DataSnapshot ;
3936import com .firebase .client .Firebase ;
40- import com .firebase .client .FirebaseError ;
4137import com .firebase .client .Query ;
4238
4339import java .lang .reflect .Constructor ;
4440import java .lang .reflect .InvocationTargetException ;
45- import java .util .ArrayList ;
46- import java .util .HashMap ;
47- import java .util .List ;
48- import java .util .Map ;
4941
5042/**
5143 * This class is a generic way of backing an RecyclerView with a Firebase location.
5244 * It handles all of the child events at the given Firebase location. It marshals received data into the given
5345 * class type.
5446 *
55- * @param <T> The collection type
47+ * To use this class in your app, subclass it passing in all required parameters and implement the
48+ * populateViewHolder method.
49+ *
50+ * @param <T> The Java class that maps to the type of objects stored in the Firebase location.
51+ * @param <VH> The ViewHolder class that contains the Views in the layout that is shown for each object.
5652 */
5753public abstract class FirebaseRecyclerViewAdapter <T , VH extends RecyclerView .ViewHolder > extends RecyclerView .Adapter <VH > {
5854
@@ -62,11 +58,14 @@ public abstract class FirebaseRecyclerViewAdapter<T, VH extends RecyclerView.Vie
6258 FirebaseArray mSnapshots ;
6359
6460 /**
65- * @param ref The Firebase location to watch for data changes. Can also be a slice of a location, using some
66- * combination of <code>limit()</code>, <code>startAt()</code>, and <code>endAt()</code>,
6761 * @param modelClass Firebase will marshall the data at a location into an instance of a class that you provide
62+ * @param modelLayout This is the layout used to represent a single item in the list. You will be responsible for populating an
63+ * instance of the corresponding view with the data from an instance of modelClass.
64+ * @param viewHolderClass The class that hold references to all sub-views in an instance modelLayout.
65+ * @param ref The Firebase location to watch for data changes. Can also be a slice of a location, using some
66+ * combination of <code>limit()</code>, <code>startAt()</code>, and <code>endAt()</code>
6867 */
69- public FirebaseRecyclerViewAdapter (Query ref , Class <T > modelClass , int modelLayout , Class <VH > viewHolderClass ) {
68+ public FirebaseRecyclerViewAdapter (Class <T > modelClass , int modelLayout , Class <VH > viewHolderClass , Query ref ) {
7069 mModelClass = modelClass ;
7170 mModelLayout = modelLayout ;
7271 mViewHolderClass = viewHolderClass ;
@@ -93,9 +92,21 @@ public void onChanged(EventType type, int index, int oldIndex) {
9392 }
9493 }
9594 });
95+ }
9696
97+ /**
98+ * @param modelClass Firebase will marshall the data at a location into an instance of a class that you provide
99+ * @param modelLayout This is the layout used to represent a single item in the list. You will be responsible for populating an
100+ * instance of the corresponding view with the data from an instance of modelClass.
101+ * @param viewHolderClass The class that hold references to all sub-views in an instance modelLayout.
102+ * @param ref The Firebase location to watch for data changes. Can also be a slice of a location, using some
103+ * combination of <code>limit()</code>, <code>startAt()</code>, and <code>endAt()</code>
104+ */
105+ public FirebaseRecyclerViewAdapter (Class <T > modelClass , int modelLayout , Class <VH > viewHolderClass , Firebase ref ) {
106+ this (modelClass , modelLayout , viewHolderClass , (Query )ref );
97107 }
98108
109+
99110 public void cleanup () {
100111 mSnapshots .cleanup ();
101112 }
0 commit comments