Skip to content

Commit 984c056

Browse files
committed
Allow overriding of snapshot parsing
Fixes #20. But also changes #9 to needing to override both `populdateView()` and `parseSnapshot()`.
1 parent 8fa944a commit 984c056

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,18 @@ public int getItemCount() {
147147
}
148148

149149
public T getItem(int position) {
150-
if (mModelClass != DataSnapshot.class) {
151-
return mSnapshots.getItem(position).getValue(mModelClass);
152-
}
153-
else {
154-
return (T) mSnapshots.getItem(position);
155-
}
150+
return parseSnapshot(mSnapshots.getItem(position));
151+
}
152+
153+
/**
154+
* This method parses the DataSnapshot into the requested type. You can override it in subclasses
155+
* to do custom parsing.
156+
*
157+
* @param snapshot the DataSnapshot to extract the model from
158+
* @return the model extracted from the DataSnapshot
159+
*/
160+
protected T parseSnapshot(DataSnapshot snapshot) {
161+
return snapshot.getValue(mModelClass);
156162
}
157163

158164
public Firebase getRef(int position) { return mSnapshots.getItem(position).getRef(); }

0 commit comments

Comments
 (0)