1
1
package com .firebase .ui .database ;
2
2
3
3
import android .arch .lifecycle .LifecycleOwner ;
4
- import android .support .annotation .LayoutRes ;
5
4
import android .support .annotation .Nullable ;
6
- import android .support .v7 .widget .RecyclerView ;
7
5
8
6
import com .google .firebase .database .DatabaseReference ;
9
7
import com .google .firebase .database .Query ;
16
14
*
17
15
* @see Builder
18
16
*/
19
- public class FirebaseRecyclerOptions <T , VH extends RecyclerView . ViewHolder > {
17
+ public class FirebaseRecyclerOptions <T > {
20
18
21
19
private static final String ERR_SNAPSHOTS_SET = "Snapshot array already set. " +
22
20
"Call only one of setSnapshotArray, setQuery, or setIndexedQuery." ;
23
-
24
- private static final String ERR_SNAPSHOTS_NULL = "Snapshot array cannot be null. " +
21
+ private static final String ERR_SNAPSHOTS_NULL = "Snapshot array cannot be null. " +
25
22
"Call one of setSnapshotArray, setQuery, or setIndexedQuery." ;
26
23
27
- private static final String ERR_VIEWHOLDER_NULL = "View holder class cannot be null. " +
28
- "Call setViewHolder." ;
29
-
30
24
private final ObservableSnapshotArray <T > mSnapshots ;
31
- private final Class <VH > mViewHolderClass ;
32
- private final int mModelLayout ;
33
25
private final LifecycleOwner mOwner ;
34
26
35
27
private FirebaseRecyclerOptions (ObservableSnapshotArray <T > snapshots ,
36
- Class <VH > viewHolderClass ,
37
- @ LayoutRes int modelLayout ,
38
- LifecycleOwner owner ) {
28
+ @ Nullable LifecycleOwner owner ) {
39
29
mSnapshots = snapshots ;
40
- mViewHolderClass = viewHolderClass ;
41
- mModelLayout = modelLayout ;
42
30
mOwner = owner ;
43
31
}
44
32
@@ -50,24 +38,8 @@ public ObservableSnapshotArray<T> getSnapshots() {
50
38
}
51
39
52
40
/**
53
- * Get the class of the {@link android.support.v7.widget.RecyclerView.ViewHolder} for
54
- * each RecyclerView item.
55
- */
56
- public Class <VH > getViewHolderClass () {
57
- return mViewHolderClass ;
58
- }
59
-
60
- /**
61
- * Get the resource ID of the layout for each RecyclerView item.
62
- */
63
- @ LayoutRes
64
- public int getModelLayout () {
65
- return mModelLayout ;
66
- }
67
-
68
- /**
69
- * Get the (optional) LifecycleOwner. Listening will start/stop after the appropriate
70
- * lifecycle events.
41
+ * Get the (optional) LifecycleOwner. Listening will start/stop after the appropriate lifecycle
42
+ * events.
71
43
*/
72
44
@ Nullable
73
45
public LifecycleOwner getOwner () {
@@ -78,109 +50,93 @@ public LifecycleOwner getOwner() {
78
50
* Builder for a {@link FirebaseRecyclerOptions}.
79
51
*
80
52
* @param <T> the model class for the {@link FirebaseRecyclerAdapter}.
81
- * @param <VH> the ViewHolder class for the {@link FirebaseRecyclerAdapter}.
82
53
*/
83
- public static class Builder <T , VH extends RecyclerView . ViewHolder > {
54
+ public static class Builder <T > {
84
55
85
56
private ObservableSnapshotArray <T > mSnapshots ;
86
- private Class <VH > mViewHolderClass ;
87
- private int mModelLayout ;
88
57
private LifecycleOwner mOwner ;
89
58
90
59
/**
91
60
* Directly set the {@link ObservableSnapshotArray} to be listened to.
92
- *
61
+ * <p>
93
62
* Do not call this method after calling {@code setQuery}.
94
63
*/
95
- public Builder <T , VH > setSnapshotArray (ObservableSnapshotArray <T > snapshots ) {
64
+ public Builder <T > setSnapshotArray (ObservableSnapshotArray <T > snapshots ) {
96
65
assertNull (mSnapshots , ERR_SNAPSHOTS_SET );
97
66
98
67
mSnapshots = snapshots ;
99
68
return this ;
100
69
}
101
70
102
71
/**
103
- * Set the Firebase query to listen to, along with a {@link SnapshotParser} to
104
- * parse snapshots into model objects.
105
- *
72
+ * Set the Firebase query to listen to, along with a {@link SnapshotParser} to parse
73
+ * snapshots into model objects.
74
+ * <p>
106
75
* Do not call this method after calling {@link #setSnapshotArray(ObservableSnapshotArray)}.
107
76
*/
108
- public Builder <T , VH > setQuery (Query query , SnapshotParser <T > snapshotParser ) {
77
+ public Builder <T > setQuery (Query query , SnapshotParser <T > snapshotParser ) {
109
78
assertNull (mSnapshots , ERR_SNAPSHOTS_SET );
110
79
111
- mSnapshots = new FirebaseArray <T >(query , snapshotParser );
80
+ mSnapshots = new FirebaseArray <>(query , snapshotParser );
112
81
return this ;
113
82
}
114
83
115
84
/**
116
- * Set the Firebase query to listen to, along with a {@link Class} to which snapshots
117
- * should be parsed.
118
- *
85
+ * Set the Firebase query to listen to, along with a {@link Class} to which snapshots should
86
+ * be parsed.
87
+ * <p>
119
88
* Do not call this method after calling {@link #setSnapshotArray(ObservableSnapshotArray)}.
120
89
*/
121
- public Builder <T , VH > setQuery (Query query , Class <T > modelClass ) {
122
- return setQuery (query , new ClassSnapshotParser <T >(modelClass ));
90
+ public Builder <T > setQuery (Query query , Class <T > modelClass ) {
91
+ return setQuery (query , new ClassSnapshotParser <>(modelClass ));
123
92
}
124
93
125
94
126
95
/**
127
- * Set an indexed Firebase query to listen to, along with a {@link SnapshotParser} to
128
- * parse snapshots into model objects. Keys are identified by the {@code keyQuery} and then
129
- * data is fetched using those keys from the {@code dataRef}.
130
- *
96
+ * Set an indexed Firebase query to listen to, along with a {@link SnapshotParser} to parse
97
+ * snapshots into model objects. Keys are identified by the {@code keyQuery} and then data
98
+ * is fetched using those keys from the {@code dataRef}.
99
+ * <p>
131
100
* Do not call this method after calling {@link #setSnapshotArray(ObservableSnapshotArray)}.
132
101
*/
133
- public Builder <T , VH > setIndexedQuery (Query keyQuery ,
134
- DatabaseReference dataRef ,
135
- SnapshotParser <T > snapshotParser ) {
102
+ public Builder <T > setIndexedQuery (Query keyQuery ,
103
+ DatabaseReference dataRef ,
104
+ SnapshotParser <T > snapshotParser ) {
136
105
assertNull (mSnapshots , ERR_SNAPSHOTS_SET );
137
106
138
- mSnapshots = new FirebaseIndexArray <T >(keyQuery , dataRef , snapshotParser );
107
+ mSnapshots = new FirebaseIndexArray <>(keyQuery , dataRef , snapshotParser );
139
108
return this ;
140
109
}
141
110
142
111
/**
143
- * Set an indexed Firebase query to listen to, along with a {@link Class} to which
144
- * snapshots should be parsed. Keys are identified by the {@code keyQuery} and then
145
- * data is fetched using those keys from the {@code dataRef}.
146
- *
112
+ * Set an indexed Firebase query to listen to, along with a {@link Class} to which snapshots
113
+ * should be parsed. Keys are identified by the {@code keyQuery} and then data is fetched
114
+ * using those keys from the {@code dataRef}.
115
+ * <p>
147
116
* Do not call this method after calling {@link #setSnapshotArray(ObservableSnapshotArray)}.
148
117
*/
149
- public Builder <T , VH > setIndexedQuery (Query keyQuery ,
150
- DatabaseReference dataRef ,
151
- Class <T > modelClass ) {
152
- return setIndexedQuery (keyQuery , dataRef , new ClassSnapshotParser <T >(modelClass ));
153
- }
154
-
155
- /**
156
- * Set the layout resource ID and class for the
157
- * {@link android.support.v7.widget.RecyclerView.ViewHolder} for each RecyclerView item.
158
- */
159
- public Builder <T , VH > setViewHolder (@ LayoutRes int modelLayout , Class <VH > viewHolderClass ) {
160
- mModelLayout = modelLayout ;
161
- mViewHolderClass = viewHolderClass ;
162
-
163
- return this ;
118
+ public Builder <T > setIndexedQuery (Query keyQuery ,
119
+ DatabaseReference dataRef ,
120
+ Class <T > modelClass ) {
121
+ return setIndexedQuery (keyQuery , dataRef , new ClassSnapshotParser <>(modelClass ));
164
122
}
165
123
166
124
/**
167
125
* Set the (optional) {@link LifecycleOwner}. Listens will start and stop after the
168
126
* appropriate lifecycle events.
169
127
*/
170
- public Builder <T , VH > setLifecycleOwner (LifecycleOwner owner ) {
128
+ public Builder <T > setLifecycleOwner (LifecycleOwner owner ) {
171
129
mOwner = owner ;
172
130
return this ;
173
131
}
174
132
175
133
/**
176
134
* Build a {@link FirebaseRecyclerOptions} from the provided arguments.
177
135
*/
178
- public FirebaseRecyclerOptions <T , VH > build () {
136
+ public FirebaseRecyclerOptions <T > build () {
179
137
assertNonNull (mSnapshots , ERR_SNAPSHOTS_NULL );
180
- assertNonNull (mViewHolderClass , ERR_VIEWHOLDER_NULL );
181
138
182
- return new FirebaseRecyclerOptions <>(
183
- mSnapshots , mViewHolderClass , mModelLayout , mOwner );
139
+ return new FirebaseRecyclerOptions <>(mSnapshots , mOwner );
184
140
}
185
141
}
186
142
0 commit comments