29
29
package com .firebase .ui ;
30
30
31
31
import android .support .v7 .widget .RecyclerView ;
32
- import android .util .Log ;
33
32
import android .view .LayoutInflater ;
34
33
import android .view .View ;
35
34
import android .view .ViewGroup ;
36
35
37
- import com .firebase .client .ChildEventListener ;
38
- import com .firebase .client .DataSnapshot ;
39
36
import com .firebase .client .Firebase ;
40
- import com .firebase .client .FirebaseError ;
41
37
import com .firebase .client .Query ;
42
38
43
39
import java .lang .reflect .Constructor ;
44
40
import java .lang .reflect .InvocationTargetException ;
45
- import java .util .ArrayList ;
46
- import java .util .HashMap ;
47
- import java .util .List ;
48
- import java .util .Map ;
49
41
50
42
/**
51
43
* This class is a generic way of backing an RecyclerView with a Firebase location.
52
44
* It handles all of the child events at the given Firebase location. It marshals received data into the given
53
45
* class type.
54
46
*
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.
56
52
*/
57
53
public abstract class FirebaseRecyclerViewAdapter <T , VH extends RecyclerView .ViewHolder > extends RecyclerView .Adapter <VH > {
58
54
@@ -62,11 +58,14 @@ public abstract class FirebaseRecyclerViewAdapter<T, VH extends RecyclerView.Vie
62
58
FirebaseArray mSnapshots ;
63
59
64
60
/**
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>,
67
61
* @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>
68
67
*/
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 ) {
70
69
mModelClass = modelClass ;
71
70
mModelLayout = modelLayout ;
72
71
mViewHolderClass = viewHolderClass ;
@@ -93,9 +92,21 @@ public void onChanged(EventType type, int index, int oldIndex) {
93
92
}
94
93
}
95
94
});
95
+ }
96
96
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 );
97
107
}
98
108
109
+
99
110
public void cleanup () {
100
111
mSnapshots .cleanup ();
101
112
}
0 commit comments