Skip to content

Handle on cancelled #282

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 14 commits into from
Sep 2, 2016
13 changes: 11 additions & 2 deletions database/src/main/java/com/firebase/ui/database/FirebaseArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FirebaseArray implements ChildEventListener {
public interface OnChangedListener {
enum EventType { Added, Changed, Removed, Moved }
void onChanged(EventType type, int index, int oldIndex);
void onCancelled(DatabaseError databaseError);
}

private Query mQuery;
Expand Down Expand Up @@ -94,20 +95,28 @@ public void onChildMoved(DataSnapshot snapshot, String previousChildKey) {
notifyChangedListeners(OnChangedListener.EventType.Moved, newIndex, oldIndex);
}

public void onCancelled(DatabaseError firebaseError) {
// TODO: what do we do with this?
public void onCancelled(DatabaseError databaseError) {
notifyCancelledListeners(databaseError);
Copy link
Contributor

Choose a reason for hiding this comment

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

The symbol databaseError is not defined here, firebaseError is what you called the method argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks again! I'm working on another branch on my machine so I've been using the online file editor in Github. Yeah... It's tough without Intellij!

}
// End of ChildEventListener methods

public void setOnChangedListener(OnChangedListener listener) {
mListener = listener;
}

protected void notifyChangedListeners(OnChangedListener.EventType type, int index) {
notifyChangedListeners(type, index, -1);
}

protected void notifyChangedListeners(OnChangedListener.EventType type, int index, int oldIndex) {
if (mListener != null) {
mListener.onChanged(type, index, oldIndex);
}
}

protected void notifyCancelledListeners(DatabaseError databaseError) {
if (mListener != null) {
mListener.onCancelled(databaseError);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method is missing a closing bracket. TravisCI says:

/home/travis/build/firebase/FirebaseUI-Android/database/src/main/java/com/firebase/ui/database/FirebaseArray.java:121: error: reached end of file while parsing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package com.firebase.ui.database;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.Query;

Expand Down Expand Up @@ -73,6 +75,11 @@ public FirebaseListAdapter(Activity activity, Class<T> modelClass, int modelLayo
public void onChanged(EventType type, int index, int oldIndex) {
notifyDataSetChanged();
}

@Override
public void onCancelled(DatabaseError databaseError) {
FirebaseListAdapter.this.onCancelled(databaseError);
}
});
}
/**
Expand Down Expand Up @@ -133,6 +140,16 @@ public View getView(int position, View view, ViewGroup viewGroup) {
populateView(view, model, position);
return view;
}

/**
* This method will be triggered in the event that this listener either failed at the server,
* or is removed as a result of the security and Firebase Database rules.
*
* @param databaseError A description of the error that occurred
*/
protected void onCancelled(DatabaseError databaseError) {
Log.w("FirebaseRecyclerAdapter", databaseError.toException());
}

/**
* Each time the data at the given Firebase location changes, this method will be called for each item that needs
Expand All @@ -146,5 +163,4 @@ public View getView(int position, View view, ViewGroup viewGroup) {
* @param position The position in the list of the view being populated
*/
abstract protected void populateView(View v, T model, int position);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package com.firebase.ui.database;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.Query;

Expand Down Expand Up @@ -108,6 +110,11 @@ public void onChanged(EventType type, int index, int oldIndex) {
throw new IllegalStateException("Incomplete case statement");
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
FirebaseRecyclerAdapter.this.onCancelled(databaseError);
}
});
}

Expand Down Expand Up @@ -181,6 +188,16 @@ public void onBindViewHolder(VH viewHolder, int position) {
public int getItemViewType(int position) {
return mModelLayout;
}

/**
* This method will be triggered in the event that this listener either failed at the server,
* or is removed as a result of the security and Firebase Database rules.
*
* @param databaseError A description of the error that occurred
*/
protected void onCancelled(DatabaseError databaseError) {
Log.w("FirebaseRecyclerAdapter", databaseError.toException());
}

/**
* Each time the data at the given Firebase location changes, this method will be called for each item that needs
Expand Down