Skip to content

Commit

Permalink
Speulative fix for #1210 (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Mar 28, 2018
2 parents b90a6ec + e21d9b4 commit eb8623a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project.ext {
targetSdk = 27
minSdk = 14

firebaseVersion = '11.8.0'
firebaseVersion = '12.0.1'
supportLibraryVersion = '27.1.0'
architectureVersion = '1.1.0'
kotlinVersion = '1.2.30'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.ListenerRegistration;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QueryListenOptions;
import com.google.firebase.firestore.QuerySnapshot;

Expand Down Expand Up @@ -95,30 +96,32 @@ public void onEvent(QuerySnapshot snapshots, FirebaseFirestoreException e) {
}

private void onDocumentAdded(DocumentChange change) {
mSnapshots.add(change.getNewIndex(), change.getDocument());
notifyOnChildChanged(ChangeEventType.ADDED, change.getDocument(), change.getNewIndex(), -1);
QueryDocumentSnapshot snapshot = change.getDocument();
mSnapshots.add(change.getNewIndex(), snapshot);
notifyOnChildChanged(ChangeEventType.ADDED, snapshot, change.getNewIndex(), -1);
}

private void onDocumentRemoved(DocumentChange change) {
mSnapshots.remove(change.getOldIndex());
notifyOnChildChanged(
ChangeEventType.REMOVED, change.getDocument(), -1, change.getOldIndex());
QueryDocumentSnapshot snapshot = change.getDocument();
notifyOnChildChanged(ChangeEventType.REMOVED, snapshot, -1, change.getOldIndex());
}

private void onDocumentModified(DocumentChange change) {
QueryDocumentSnapshot snapshot = change.getDocument();
if (change.getOldIndex() == change.getNewIndex()) {
// Document modified only
mSnapshots.set(change.getNewIndex(), change.getDocument());
notifyOnChildChanged(ChangeEventType.CHANGED, change.getDocument(),
mSnapshots.set(change.getNewIndex(), snapshot);
notifyOnChildChanged(ChangeEventType.CHANGED, snapshot,
change.getNewIndex(), change.getNewIndex());
} else {
// Document moved and possibly also modified
mSnapshots.remove(change.getOldIndex());
mSnapshots.add(change.getNewIndex(), change.getDocument());
mSnapshots.add(change.getNewIndex(), snapshot);

notifyOnChildChanged(ChangeEventType.MOVED, change.getDocument(),
notifyOnChildChanged(ChangeEventType.MOVED, snapshot,
change.getNewIndex(), change.getOldIndex());
notifyOnChildChanged(ChangeEventType.CHANGED, change.getDocument(),
notifyOnChildChanged(ChangeEventType.CHANGED, snapshot,
change.getNewIndex(), change.getNewIndex());
}
}
Expand Down

0 comments on commit eb8623a

Please sign in to comment.