Skip to content

Commit 1f271c9

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

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,18 @@ public int getCount() {
113113

114114
@Override
115115
public T getItem(int position) {
116-
if (mModelClass != DataSnapshot.class) {
117-
return mSnapshots.getItem(position).getValue(mModelClass);
118-
}
119-
else {
120-
return (T) mSnapshots.getItem(position);
121-
}
116+
return parseSnapshot(mSnapshots.getItem(position));
117+
}
118+
119+
/**
120+
* This method parses the DataSnapshot into the requested type. You can override it in subclasses
121+
* to do custom parsing.
122+
*
123+
* @param snapshot the DataSnapshot to extract the model from
124+
* @return the model extracted from the DataSnapshot
125+
*/
126+
protected T parseSnapshot(DataSnapshot snapshot) {
127+
return snapshot.getValue(mModelClass);
122128
}
123129

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

0 commit comments

Comments
 (0)