Skip to content

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

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator Author

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.

}

@Override
Expand Down Expand Up @@ -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());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

}
}
}
Expand Down
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;

Expand Down Expand Up @@ -41,7 +42,7 @@ public abstract class FirebaseIndexListAdapter<T> extends FirebaseListAdapter<T>
*/
public FirebaseIndexListAdapter(Activity activity,
Class<T> modelClass,
int modelLayout,
@LayoutRes int modelLayout,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also just noticed that we never had an @Res annotation on our layouts so I added that too.

Query keyRef,
Query dataRef) {
super(activity, modelClass, modelLayout, new FirebaseIndexArray(keyRef, dataRef));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.database;

import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;

import com.google.firebase.database.Query;
Expand Down Expand Up @@ -70,7 +71,7 @@ public abstract class FirebaseIndexRecyclerAdapter<T, VH extends RecyclerView.Vi
* Each key key found at {@code keyRef}'s location represents a list item in the {@code RecyclerView}.
*/
public FirebaseIndexRecyclerAdapter(Class<T> modelClass,
int modelLayout,
@LayoutRes int modelLayout,
Class<VH> viewHolderClass,
Query keyRef,
Query dataRef) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.firebase.ui.database;

import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class FirebaseListAdapter<T> extends BaseAdapter {

FirebaseListAdapter(Activity activity,
Class<T> modelClass,
int modelLayout,
@LayoutRes int modelLayout,
FirebaseArray snapshots) {
mModelClass = modelClass;
mLayout = modelLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.database;

import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -76,7 +77,7 @@ public abstract class FirebaseRecyclerAdapter<T, VH extends RecyclerView.ViewHol
FirebaseArray mSnapshots;

FirebaseRecyclerAdapter(Class<T> modelClass,
int modelLayout,
@LayoutRes int modelLayout,
Class<VH> viewHolderClass,
FirebaseArray snapshots) {
mModelClass = modelClass;
Expand Down