-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix small mistakes in FirebaseIndexArray #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,15 +67,15 @@ private int getIndexForKey(String key) { | |
String superKey = super.getItem(keyIndex).getKey(); | ||
if (key.equals(superKey)) { | ||
break; | ||
} else if (getItem(index).getKey().equals(superKey)) { | ||
} else if (mDataSnapshots.get(index).getKey().equals(superKey)) { | ||
index++; | ||
} | ||
} | ||
return index; | ||
} | ||
|
||
private boolean isMatch(int index, String key) { | ||
return index >= 0 && index < getCount() && getItem(index).getKey().equals(key); | ||
return index >= 0 && index < getCount() && mDataSnapshots.get(index).getKey().equals(key); | ||
} | ||
|
||
@Override | ||
|
@@ -155,10 +155,11 @@ public void onDataChange(DataSnapshot snapshot) { | |
notifyChangedListeners(OnChangedListener.EventType.CHANGED, index); | ||
} | ||
} else { | ||
Log.w(TAG, "Key not found at ref: " + snapshot.getRef()); | ||
if (isMatch(index, key)) { | ||
mDataSnapshots.remove(index); | ||
notifyChangedListeners(OnChangedListener.EventType.REMOVED, index); | ||
} else { | ||
Log.w(TAG, "Key not found at ref: " + snapshot.getRef()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only log the warning if the data wasn't in our list. Example: if people delete the data ref before the index ref, the warning would have been shown which is kinda pointless. |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.firebase.ui.database; | ||
|
||
import android.app.Activity; | ||
import android.support.annotation.LayoutRes; | ||
|
||
import com.google.firebase.database.Query; | ||
|
||
|
@@ -41,7 +42,7 @@ public abstract class FirebaseIndexListAdapter<T> extends FirebaseListAdapter<T> | |
*/ | ||
public FirebaseIndexListAdapter(Activity activity, | ||
Class<T> modelClass, | ||
int modelLayout, | ||
@LayoutRes int modelLayout, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also just noticed that we never had an |
||
Query keyRef, | ||
Query dataRef) { | ||
super(activity, modelClass, modelLayout, new FirebaseIndexArray(keyRef, dataRef)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have never used
getItem()
here because it's public api and anyone overriding that method will break our implementation.