From 5d5635a1c04bb8cc9e76c29b8e5f84e46fad6770 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Wed, 7 Dec 2016 19:12:22 -0800 Subject: [PATCH 01/17] Update api to let users do their own filtering + sorting Signed-off-by: Alex Saveau --- .../uidemo/database/ChatActivity.java | 29 +++++------ .../firebase/ui/database/FirebaseArray.java | 8 --- .../ui/database/FirebaseListAdapter.java | 21 +++----- .../ui/database/FirebaseRecyclerAdapter.java | 51 +++++++++---------- .../ui/database/OnChangedListener.java | 11 ++++ 5 files changed, 55 insertions(+), 65 deletions(-) create mode 100644 database/src/main/java/com/firebase/ui/database/OnChangedListener.java diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index 73b33a162..b744f7bb0 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -80,9 +80,9 @@ public void onClick(View v) { Chat chat = new Chat(name, mMessageEdit.getText().toString(), uid); mChatRef.push().setValue(chat, new DatabaseReference.CompletionListener() { @Override - public void onComplete(DatabaseError databaseError, DatabaseReference reference) { - if (databaseError != null) { - Log.e(TAG, "Failed to write message", databaseError.toException()); + public void onComplete(DatabaseError error, DatabaseReference reference) { + if (error != null) { + Log.e(TAG, "Failed to write message", error.toException()); } } }); @@ -92,11 +92,7 @@ public void onComplete(DatabaseError databaseError, DatabaseReference reference) }); mMessages = (RecyclerView) findViewById(R.id.messagesList); - mManager = new LinearLayoutManager(this); - mManager.setReverseLayout(false); - - mMessages.setHasFixedSize(false); mMessages.setLayoutManager(mManager); } @@ -107,10 +103,10 @@ public void onStart() { // Default Database rules do not allow unauthenticated reads, so we need to // sign in before attaching the RecyclerView adapter otherwise the Adapter will // not be able to read any data from the Database. - if (!isSignedIn()) { - signInAnonymously(); - } else { + if (isSignedIn()) { attachRecyclerViewAdapter(); + } else { + signInAnonymously(); } } @@ -139,7 +135,6 @@ private void attachRecyclerViewAdapter() { Query lastFifty = mChatRef.limitToLast(50); mRecyclerViewAdapter = new FirebaseRecyclerAdapter( Chat.class, R.layout.message, ChatHolder.class, lastFifty) { - @Override public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { chatView.setName(chat.getName()); @@ -158,7 +153,9 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { - mManager.smoothScrollToPosition(mMessages, null, mRecyclerViewAdapter.getItemCount()); + mManager.smoothScrollToPosition(mMessages, + null, + mRecyclerViewAdapter.getItemCount()); } }); @@ -173,12 +170,12 @@ private void signInAnonymously() { public void onComplete(@NonNull Task task) { Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful()); if (task.isSuccessful()) { - Toast.makeText(ChatActivity.this, "Signed In", - Toast.LENGTH_SHORT).show(); + Toast.makeText( + ChatActivity.this, "Signed In", Toast.LENGTH_SHORT).show(); attachRecyclerViewAdapter(); } else { - Toast.makeText(ChatActivity.this, "Sign In Failed", - Toast.LENGTH_SHORT).show(); + Toast.makeText( + ChatActivity.this, "Sign In Failed", Toast.LENGTH_SHORT).show(); } } }); diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java index 1bb5fa4fd..656fe5996 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java @@ -26,14 +26,6 @@ * This class implements an array-like collection on top of a Firebase location. */ 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; private OnChangedListener mListener; private List mSnapshots = new ArrayList<>(); diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index 4cce0df7c..302c1c4cb 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -50,7 +50,7 @@ * @param The class type to use as a model for the data * contained in the children of the given Firebase location */ -public abstract class FirebaseListAdapter extends BaseAdapter { +public abstract class FirebaseListAdapter extends BaseAdapter implements OnChangedListener { private static final String TAG = FirebaseListAdapter.class.getSimpleName(); private FirebaseArray mSnapshots; @@ -67,17 +67,7 @@ public abstract class FirebaseListAdapter extends BaseAdapter { mLayout = modelLayout; mSnapshots = snapshots; - mSnapshots.setOnChangedListener(new FirebaseArray.OnChangedListener() { - @Override - public void onChanged(EventType type, int index, int oldIndex) { - notifyDataSetChanged(); - } - - @Override - public void onCancelled(DatabaseError databaseError) { - FirebaseListAdapter.this.onCancelled(databaseError); - } - }); + mSnapshots.setOnChangedListener(this); } /** @@ -145,13 +135,18 @@ public View getView(int position, View view, ViewGroup viewGroup) { return view; } + @Override + public void onChanged(EventType type, int index, int oldIndex) { + notifyDataSetChanged(); + } + /** * 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 error A description of the error that occurred */ - protected void onCancelled(DatabaseError error) { + public void onCancelled(DatabaseError error) { Log.w(TAG, error.toException()); } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 5661a8563..884e42c9c 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -72,7 +72,7 @@ * @param The ViewHolder class that contains the Views in the layout that is shown for each object. */ public abstract class FirebaseRecyclerAdapter - extends RecyclerView.Adapter { + extends RecyclerView.Adapter implements OnChangedListener { private static final String TAG = FirebaseRecyclerAdapter.class.getSimpleName(); private FirebaseArray mSnapshots; @@ -89,32 +89,7 @@ public abstract class FirebaseRecyclerAdapter Date: Thu, 8 Dec 2016 16:47:41 -0800 Subject: [PATCH 02/17] Cleanup Signed-off-by: Alex Saveau --- .../com/firebase/uidemo/database/ChatActivity.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index b744f7bb0..a9fdc6a7b 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -153,9 +153,7 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { - mManager.smoothScrollToPosition(mMessages, - null, - mRecyclerViewAdapter.getItemCount()); + mManager.smoothScrollToPosition(mMessages, null, mRecyclerViewAdapter.getItemCount()); } }); @@ -170,12 +168,10 @@ private void signInAnonymously() { public void onComplete(@NonNull Task task) { Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful()); if (task.isSuccessful()) { - Toast.makeText( - ChatActivity.this, "Signed In", Toast.LENGTH_SHORT).show(); + Toast.makeText(ChatActivity.this, "Signed In", Toast.LENGTH_SHORT).show(); attachRecyclerViewAdapter(); } else { - Toast.makeText( - ChatActivity.this, "Sign In Failed", Toast.LENGTH_SHORT).show(); + Toast.makeText(ChatActivity.this, "Sign In Failed", Toast.LENGTH_SHORT).show(); } } }); From 9d462dc15c3ae784d614b4913c65da373c03f4fc Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 8 Dec 2016 16:52:09 -0800 Subject: [PATCH 03/17] Cleanup Signed-off-by: Alex Saveau --- .../uidemo/database/ChatActivity.java | 25 ++++++++++++++----- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index a9fdc6a7b..c5bb9f6aa 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -37,6 +37,7 @@ import com.firebase.ui.database.FirebaseRecyclerAdapter; import com.firebase.uidemo.R; import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth; @@ -153,7 +154,9 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { - mManager.smoothScrollToPosition(mMessages, null, mRecyclerViewAdapter.getItemCount()); + mManager.smoothScrollToPosition(mMessages, + null, + mRecyclerViewAdapter.getItemCount()); } }); @@ -163,15 +166,25 @@ public void onItemRangeInserted(int positionStart, int itemCount) { private void signInAnonymously() { Toast.makeText(this, "Signing in...", Toast.LENGTH_SHORT).show(); mAuth.signInAnonymously() - .addOnCompleteListener(this, new OnCompleteListener() { + .addOnSuccessListener(this, new OnSuccessListener() { + @Override + public void onSuccess(AuthResult result) { + attachRecyclerViewAdapter(); + } + }) + .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { - Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful()); if (task.isSuccessful()) { - Toast.makeText(ChatActivity.this, "Signed In", Toast.LENGTH_SHORT).show(); - attachRecyclerViewAdapter(); + Toast.makeText(getApplicationContext(), + R.string.signed_in, + Toast.LENGTH_SHORT) + .show(); } else { - Toast.makeText(ChatActivity.this, "Sign In Failed", Toast.LENGTH_SHORT).show(); + Toast.makeText(getApplicationContext(), + R.string.sign_in_failed, + Toast.LENGTH_SHORT) + .show(); } } }); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2fe2b9f42..0ca36b854 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,4 +64,6 @@ Choose Image Downloaded image Drive File + Sign In Failed + Signed In From 0f12fe3be76eb5d60fa06f5206c7575db7a14718 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 3 Jan 2017 14:59:32 -0800 Subject: [PATCH 04/17] Add documentation Signed-off-by: Alex Saveau --- database/README.md | 4 +-- .../firebase/ui/database/utils/TestUtils.java | 9 +++--- .../firebase/ui/database/FirebaseArray.java | 4 +-- .../ui/database/FirebaseListAdapter.java | 29 +++++++++++------- .../ui/database/FirebaseRecyclerAdapter.java | 30 ++++++++++++------- .../ui/database/OnChangedListener.java | 25 +++++++++++++++- 6 files changed, 71 insertions(+), 30 deletions(-) diff --git a/database/README.md b/database/README.md index c09c9f37c..e8d92012d 100644 --- a/database/README.md +++ b/database/README.md @@ -86,8 +86,8 @@ ref.limitToLast(5).addValueEventListener(new ValueEventListener() { } } @Override - public void onCancelled(DatabaseError firebaseError) { - Log.e("Chat", "The read failed: " + firebaseError.getText()); + public void onCancelled(DatabaseError error) { + Log.e("Chat", "The read failed: " + error.getText()); } }); ``` diff --git a/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java b/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java index 7e920561f..231c4b697 100644 --- a/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java +++ b/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java @@ -37,14 +37,15 @@ public static void runAndWaitUntil(FirebaseArray array, Runnable task, Callable done) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); - array.setOnChangedListener(new FirebaseArray.OnChangedListener() { - public void onChanged(EventType type, int index, int oldIndex) { + array.setOnChangedListener(new OnChangedListener() { + @Override + public void onChanged(OnChangedListener.EventType type, int index, int oldIndex) { semaphore.release(); } @Override - public void onCancelled(DatabaseError databaseError) { - throw new IllegalStateException(databaseError.toException()); + public void onCancelled(DatabaseError error) { + throw new IllegalStateException(error.toException()); } }); task.run(); diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java index 656fe5996..9bff6f3f3 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java @@ -111,9 +111,9 @@ protected void notifyChangedListeners(OnChangedListener.EventType type, int inde } } - protected void notifyCancelledListeners(DatabaseError databaseError) { + protected void notifyCancelledListeners(DatabaseError error) { if (mListener != null) { - mListener.onCancelled(databaseError); + mListener.onCancelled(error); } } } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index 302c1c4cb..5af7ffc17 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -50,8 +50,8 @@ * @param The class type to use as a model for the data * contained in the children of the given Firebase location */ -public abstract class FirebaseListAdapter extends BaseAdapter implements OnChangedListener { - private static final String TAG = FirebaseListAdapter.class.getSimpleName(); +public abstract class FirebaseListAdapter extends BaseAdapter { + private static final String TAG = "FirebaseListAdapter"; private FirebaseArray mSnapshots; private final Class mModelClass; @@ -67,7 +67,17 @@ public abstract class FirebaseListAdapter extends BaseAdapter implements OnCh mLayout = modelLayout; mSnapshots = snapshots; - mSnapshots.setOnChangedListener(this); + mSnapshots.setOnChangedListener(new OnChangedListener() { + @Override + public void onChanged(EventType type, int index, int oldIndex) { + FirebaseListAdapter.this.onChanged(type, index, oldIndex); + } + + @Override + public void onCancelled(DatabaseError error) { + FirebaseListAdapter.this.onCancelled(error); + } + }); } /** @@ -135,18 +145,17 @@ public View getView(int position, View view, ViewGroup viewGroup) { return view; } - @Override - public void onChanged(EventType type, int index, int oldIndex) { + /** + * @see OnChangedListener#onChanged(OnChangedListener.EventType, int, int) + */ + protected void onChanged(OnChangedListener.EventType type, int index, int oldIndex) { notifyDataSetChanged(); } /** - * 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 error A description of the error that occurred + * @see OnChangedListener#onCancelled(DatabaseError) */ - public void onCancelled(DatabaseError error) { + protected void onCancelled(DatabaseError error) { Log.w(TAG, error.toException()); } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 884e42c9c..466be4a01 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -71,9 +71,8 @@ * @param The Java class that maps to the type of objects stored in the Firebase location. * @param The ViewHolder class that contains the Views in the layout that is shown for each object. */ -public abstract class FirebaseRecyclerAdapter - extends RecyclerView.Adapter implements OnChangedListener { - private static final String TAG = FirebaseRecyclerAdapter.class.getSimpleName(); +public abstract class FirebaseRecyclerAdapter extends RecyclerView.Adapter { + private static final String TAG = "FirebaseRecyclerAdapter"; private FirebaseArray mSnapshots; private Class mModelClass; @@ -89,7 +88,17 @@ public abstract class FirebaseRecyclerAdapter + * CHANGED: an onChildChanged event was received + *

+ * REMOVED: an onChildRemoved event was received + *

+ * MOVED: an onChildMoved event was received + */ enum EventType {ADDED, CHANGED, REMOVED, MOVED} + /** + * A callback for when a child has changed in FirebaseArray. + * + * @param type The type of event received + * @param index The index at which the change occurred + * @param oldIndex If {@code type} is a moved event, the previous index of the moved child. + * For any other event, {@code oldIndex} will be -1. + */ void onChanged(EventType type, int index, int oldIndex); - void onCancelled(DatabaseError databaseError); + /** + * 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 error A description of the error that occurred + */ + void onCancelled(DatabaseError error); } From 2899205d93a8d42145a635021d83fb8ba3f63c78 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 3 Jan 2017 15:03:51 -0800 Subject: [PATCH 05/17] Cleanup Signed-off-by: Alex Saveau --- .../main/java/com/firebase/uidemo/database/ChatActivity.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index bf88505cc..62b24f9c5 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -155,9 +155,7 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { - mManager.smoothScrollToPosition(mMessages, - null, - mRecyclerViewAdapter.getItemCount()); + mManager.smoothScrollToPosition(mMessages, null, mRecyclerViewAdapter.getItemCount()); } }); From 0826541d2a81d27e798b8b5be6ca64a75e9cb3ec Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 3 Jan 2017 16:22:55 -0800 Subject: [PATCH 06/17] Cleanup Signed-off-by: Alex Saveau --- .../main/java/com/firebase/uidemo/database/ChatActivity.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index bf88505cc..62b24f9c5 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -155,9 +155,7 @@ public void populateViewHolder(ChatHolder chatView, Chat chat, int position) { mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { - mManager.smoothScrollToPosition(mMessages, - null, - mRecyclerViewAdapter.getItemCount()); + mManager.smoothScrollToPosition(mMessages, null, mRecyclerViewAdapter.getItemCount()); } }); From ab3743e23c457e2676bd571464245b03898acbff Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 5 Jan 2017 11:09:33 -0800 Subject: [PATCH 07/17] Extract onComplete listener into static inner class to prevent activity leaks Signed-off-by: Alex Saveau --- .../uidemo/database/ChatActivity.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index 62b24f9c5..f5da434a3 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -14,6 +14,7 @@ package com.firebase.uidemo.database; +import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.RotateDrawable; @@ -171,22 +172,7 @@ public void onSuccess(AuthResult result) { attachRecyclerViewAdapter(); } }) - .addOnCompleteListener(new OnCompleteListener() { - @Override - public void onComplete(@NonNull Task task) { - if (task.isSuccessful()) { - Toast.makeText(getApplicationContext(), - R.string.signed_in, - Toast.LENGTH_SHORT) - .show(); - } else { - Toast.makeText(getApplicationContext(), - R.string.sign_in_failed, - Toast.LENGTH_SHORT) - .show(); - } - } - }); + .addOnCompleteListener(new SignInResultNotifier(this)); } public boolean isSignedIn() { @@ -290,4 +276,21 @@ public void setText(String text) { mTextField.setText(text); } } + + private static class SignInResultNotifier implements OnCompleteListener { + private Context mContext; + + public SignInResultNotifier(Context context) { + mContext = context.getApplicationContext(); + } + + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) { + Toast.makeText(mContext, R.string.signed_in, Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(mContext, R.string.sign_in_failed, Toast.LENGTH_SHORT).show(); + } + } + } } From 08159bd30bbad1577f677f9f079a02f379c853bc Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 5 Jan 2017 11:26:25 -0800 Subject: [PATCH 08/17] Cleanup Signed-off-by: Alex Saveau --- .../com/firebase/ui/database/FirebaseRecyclerAdapter.java | 3 ++- .../java/com/firebase/ui/database/OnChangedListener.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 466be4a01..2fb0efd5c 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -71,7 +71,8 @@ * @param The Java class that maps to the type of objects stored in the Firebase location. * @param The ViewHolder class that contains the Views in the layout that is shown for each object. */ -public abstract class FirebaseRecyclerAdapter extends RecyclerView.Adapter { +public abstract class FirebaseRecyclerAdapter + extends RecyclerView.Adapter { private static final String TAG = "FirebaseRecyclerAdapter"; private FirebaseArray mSnapshots; diff --git a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java b/database/src/main/java/com/firebase/ui/database/OnChangedListener.java index 5792ff237..e78c86bf5 100644 --- a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java +++ b/database/src/main/java/com/firebase/ui/database/OnChangedListener.java @@ -1,5 +1,7 @@ package com.firebase.ui.database; +import com.google.firebase.database.ChildEventListener; +import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; public interface OnChangedListener { @@ -11,6 +13,11 @@ public interface OnChangedListener { * REMOVED: an onChildRemoved event was received *

* MOVED: an onChildMoved event was received + * + * @see ChildEventListener#onChildAdded(DataSnapshot, String) + * @see ChildEventListener#onChildChanged(DataSnapshot, String) + * @see ChildEventListener#onChildRemoved(DataSnapshot) + * @see ChildEventListener#onChildMoved(DataSnapshot, String) */ enum EventType {ADDED, CHANGED, REMOVED, MOVED} From b066b54262264e4e48f1168732183c184c1ac10f Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 5 Jan 2017 11:40:16 -0800 Subject: [PATCH 09/17] Temporarily ignore robolectric updates Signed-off-by: Alex Saveau --- auth/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/auth/build.gradle b/auth/build.gradle index b2df3070c..7a86b76b9 100644 --- a/auth/build.gradle +++ b/auth/build.gradle @@ -53,6 +53,7 @@ dependencies { testCompile 'junit:junit:4.12' //noinspection NewerVersionAvailable, GradleDynamicVersion testCompile 'org.mockito:mockito-core:2.5.+' + //noinspection NewerVersionAvailable testCompile 'org.robolectric:robolectric:3.1.4' // See https://github.com/robolectric/robolectric/issues/1932#issuecomment-219796474 testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1' From 1c1dfb7e6b27516a19cd3a5f3ee43cb1c1ae9903 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sat, 7 Jan 2017 12:05:20 -0800 Subject: [PATCH 10/17] Address review comments Signed-off-by: Alex Saveau --- .../uidemo/database/ChatActivity.java | 14 ++++-- .../ui/database/OnChangedListener.java | 44 ++++++++++++------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java index f5da434a3..429e22485 100644 --- a/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java +++ b/app/src/main/java/com/firebase/uidemo/database/ChatActivity.java @@ -94,8 +94,11 @@ public void onComplete(DatabaseError error, DatabaseReference reference) { } }); - mMessages = (RecyclerView) findViewById(R.id.messagesList); mManager = new LinearLayoutManager(this); + mManager.setReverseLayout(false); + + mMessages = (RecyclerView) findViewById(R.id.messagesList); + mMessages.setHasFixedSize(false); mMessages.setLayoutManager(mManager); } @@ -106,10 +109,10 @@ public void onStart() { // Default Database rules do not allow unauthenticated reads, so we need to // sign in before attaching the RecyclerView adapter otherwise the Adapter will // not be able to read any data from the Database. - if (isSignedIn()) { - attachRecyclerViewAdapter(); - } else { + if (!isSignedIn()) { signInAnonymously(); + } else { + attachRecyclerViewAdapter(); } } @@ -277,6 +280,9 @@ public void setText(String text) { } } + /** + * Notifies the user of sign in successes or failures beyond the lifecycle of an activity. + */ private static class SignInResultNotifier implements OnCompleteListener { private Context mContext; diff --git a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java b/database/src/main/java/com/firebase/ui/database/OnChangedListener.java index e78c86bf5..115768541 100644 --- a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java +++ b/database/src/main/java/com/firebase/ui/database/OnChangedListener.java @@ -6,26 +6,40 @@ public interface OnChangedListener { /** - * ADDED: an onChildAdded event was received - *

- * CHANGED: an onChildChanged event was received - *

- * REMOVED: an onChildRemoved event was received - *

- * MOVED: an onChildMoved event was received - * - * @see ChildEventListener#onChildAdded(DataSnapshot, String) - * @see ChildEventListener#onChildChanged(DataSnapshot, String) - * @see ChildEventListener#onChildRemoved(DataSnapshot) - * @see ChildEventListener#onChildMoved(DataSnapshot, String) + * The type of event received when a child has been updated. */ - enum EventType {ADDED, CHANGED, REMOVED, MOVED} + enum EventType { + /** + * An onChildAdded event was received. + * + * @see ChildEventListener#onChildAdded(DataSnapshot, String) + */ + ADDED, + /** + * An onChildChanged event was received. + * + * @see ChildEventListener#onChildChanged(DataSnapshot, String) + */ + CHANGED, + /** + * An onChildRemoved event was received. + * + * @see ChildEventListener#onChildRemoved(DataSnapshot) + */ + REMOVED, + /** + * An onChildMoved event was received. + * + * @see ChildEventListener#onChildMoved(DataSnapshot, String) + */ + MOVED + } /** * A callback for when a child has changed in FirebaseArray. * - * @param type The type of event received - * @param index The index at which the change occurred + * @param type The type of event received + * @param index The index at which the change occurred * @param oldIndex If {@code type} is a moved event, the previous index of the moved child. * For any other event, {@code oldIndex} will be -1. */ From a9bad96f3c278e00e7beff7748f547cd2825fdad Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Mon, 9 Jan 2017 11:32:51 -0800 Subject: [PATCH 11/17] Rename `OnChangedListener` to `ChangeEventListener` and `onChanged` to `onChildChanged` Signed-off-by: Alex Saveau --- .../firebase/ui/database/utils/TestUtils.java | 4 ++-- ...dListener.java => ChangeEventListener.java} | 4 ++-- .../firebase/ui/database/FirebaseArray.java | 18 +++++++++--------- .../ui/database/FirebaseIndexArray.java | 14 +++++++------- .../ui/database/FirebaseListAdapter.java | 10 +++++----- .../ui/database/FirebaseRecyclerAdapter.java | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) rename database/src/main/java/com/firebase/ui/database/{OnChangedListener.java => ChangeEventListener.java} (94%) diff --git a/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java b/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java index 231c4b697..c49e7ae78 100644 --- a/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java +++ b/database/src/androidTest/java/com/firebase/ui/database/utils/TestUtils.java @@ -37,9 +37,9 @@ public static void runAndWaitUntil(FirebaseArray array, Runnable task, Callable done) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); - array.setOnChangedListener(new OnChangedListener() { + array.setOnChangedListener(new ChangeEventListener() { @Override - public void onChanged(OnChangedListener.EventType type, int index, int oldIndex) { + public void onChildChanged(ChangeEventListener.EventType type, int index, int oldIndex) { semaphore.release(); } diff --git a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java b/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java similarity index 94% rename from database/src/main/java/com/firebase/ui/database/OnChangedListener.java rename to database/src/main/java/com/firebase/ui/database/ChangeEventListener.java index 115768541..e66e8e18f 100644 --- a/database/src/main/java/com/firebase/ui/database/OnChangedListener.java +++ b/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java @@ -4,7 +4,7 @@ import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.DatabaseError; -public interface OnChangedListener { +public interface ChangeEventListener { /** * The type of event received when a child has been updated. */ @@ -43,7 +43,7 @@ enum EventType { * @param oldIndex If {@code type} is a moved event, the previous index of the moved child. * For any other event, {@code oldIndex} will be -1. */ - void onChanged(EventType type, int index, int oldIndex); + void onChildChanged(EventType type, int index, int oldIndex); /** * This method will be triggered in the event that this listener either failed at the server, diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java index 9bff6f3f3..d2d5540ff 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseArray.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseArray.java @@ -27,7 +27,7 @@ */ class FirebaseArray implements ChildEventListener { private Query mQuery; - private OnChangedListener mListener; + private ChangeEventListener mListener; private List mSnapshots = new ArrayList<>(); public FirebaseArray(Query ref) { @@ -66,21 +66,21 @@ public void onChildAdded(DataSnapshot snapshot, String previousChildKey) { index = getIndexForKey(previousChildKey) + 1; } mSnapshots.add(index, snapshot); - notifyChangedListeners(OnChangedListener.EventType.ADDED, index); + notifyChangedListeners(ChangeEventListener.EventType.ADDED, index); } @Override public void onChildChanged(DataSnapshot snapshot, String previousChildKey) { int index = getIndexForKey(snapshot.getKey()); mSnapshots.set(index, snapshot); - notifyChangedListeners(OnChangedListener.EventType.CHANGED, index); + notifyChangedListeners(ChangeEventListener.EventType.CHANGED, index); } @Override public void onChildRemoved(DataSnapshot snapshot) { int index = getIndexForKey(snapshot.getKey()); mSnapshots.remove(index); - notifyChangedListeners(OnChangedListener.EventType.REMOVED, index); + notifyChangedListeners(ChangeEventListener.EventType.REMOVED, index); } @Override @@ -89,7 +89,7 @@ public void onChildMoved(DataSnapshot snapshot, String previousChildKey) { mSnapshots.remove(oldIndex); int newIndex = previousChildKey == null ? 0 : (getIndexForKey(previousChildKey) + 1); mSnapshots.add(newIndex, snapshot); - notifyChangedListeners(OnChangedListener.EventType.MOVED, newIndex, oldIndex); + notifyChangedListeners(ChangeEventListener.EventType.MOVED, newIndex, oldIndex); } @Override @@ -97,17 +97,17 @@ public void onCancelled(DatabaseError error) { notifyCancelledListeners(error); } - public void setOnChangedListener(OnChangedListener listener) { + public void setOnChangedListener(ChangeEventListener listener) { mListener = listener; } - protected void notifyChangedListeners(OnChangedListener.EventType type, int index) { + protected void notifyChangedListeners(ChangeEventListener.EventType type, int index) { notifyChangedListeners(type, index, -1); } - protected void notifyChangedListeners(OnChangedListener.EventType type, int index, int oldIndex) { + protected void notifyChangedListeners(ChangeEventListener.EventType type, int index, int oldIndex) { if (mListener != null) { - mListener.onChanged(type, index, oldIndex); + mListener.onChildChanged(type, index, oldIndex); } } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java b/database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java index 6044426a0..823629c30 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java @@ -32,7 +32,7 @@ class FirebaseIndexArray extends FirebaseArray { private static final String TAG = FirebaseIndexArray.class.getSimpleName(); private Query mQuery; - private OnChangedListener mListener; + private ChangeEventListener mListener; private Map mRefs = new HashMap<>(); private List mDataSnapshots = new ArrayList<>(); @@ -107,7 +107,7 @@ public void onChildRemoved(DataSnapshot keySnapshot) { if (isMatch(index, key)) { mDataSnapshots.remove(index); - notifyChangedListeners(OnChangedListener.EventType.REMOVED, index); + notifyChangedListeners(ChangeEventListener.EventType.REMOVED, index); } } @@ -124,7 +124,7 @@ public void onChildMoved(DataSnapshot keySnapshot, String previousChildKey) { DataSnapshot snapshot = mDataSnapshots.remove(oldIndex); int newIndex = getIndexForKey(key); mDataSnapshots.add(newIndex, snapshot); - notifyChangedListeners(OnChangedListener.EventType.MOVED, newIndex, oldIndex); + notifyChangedListeners(ChangeEventListener.EventType.MOVED, newIndex, oldIndex); } } @@ -135,7 +135,7 @@ public void onCancelled(DatabaseError error) { } @Override - public void setOnChangedListener(OnChangedListener listener) { + public void setOnChangedListener(ChangeEventListener listener) { super.setOnChangedListener(listener); mListener = listener; } @@ -149,15 +149,15 @@ public void onDataChange(DataSnapshot snapshot) { if (snapshot.getValue() != null) { if (!isMatch(index, key)) { mDataSnapshots.add(index, snapshot); - notifyChangedListeners(OnChangedListener.EventType.ADDED, index); + notifyChangedListeners(ChangeEventListener.EventType.ADDED, index); } else { mDataSnapshots.set(index, snapshot); - notifyChangedListeners(OnChangedListener.EventType.CHANGED, index); + notifyChangedListeners(ChangeEventListener.EventType.CHANGED, index); } } else { if (isMatch(index, key)) { mDataSnapshots.remove(index); - notifyChangedListeners(OnChangedListener.EventType.REMOVED, index); + notifyChangedListeners(ChangeEventListener.EventType.REMOVED, index); } else { Log.w(TAG, "Key not found at ref: " + snapshot.getRef()); } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index 5af7ffc17..c2ae15fa7 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -67,9 +67,9 @@ public abstract class FirebaseListAdapter extends BaseAdapter { mLayout = modelLayout; mSnapshots = snapshots; - mSnapshots.setOnChangedListener(new OnChangedListener() { + mSnapshots.setOnChangedListener(new ChangeEventListener() { @Override - public void onChanged(EventType type, int index, int oldIndex) { + public void onChildChanged(EventType type, int index, int oldIndex) { FirebaseListAdapter.this.onChanged(type, index, oldIndex); } @@ -146,14 +146,14 @@ public View getView(int position, View view, ViewGroup viewGroup) { } /** - * @see OnChangedListener#onChanged(OnChangedListener.EventType, int, int) + * @see ChangeEventListener#onChildChanged(ChangeEventListener.EventType, int, int) */ - protected void onChanged(OnChangedListener.EventType type, int index, int oldIndex) { + protected void onChanged(ChangeEventListener.EventType type, int index, int oldIndex) { notifyDataSetChanged(); } /** - * @see OnChangedListener#onCancelled(DatabaseError) + * @see ChangeEventListener#onCancelled(DatabaseError) */ protected void onCancelled(DatabaseError error) { Log.w(TAG, error.toException()); diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 2fb0efd5c..66ec2831a 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -89,9 +89,9 @@ public abstract class FirebaseRecyclerAdapter Date: Mon, 9 Jan 2017 11:35:52 -0800 Subject: [PATCH 12/17] Rename onChildChanged in adapters Signed-off-by: Alex Saveau --- .../java/com/firebase/ui/database/FirebaseListAdapter.java | 4 ++-- .../com/firebase/ui/database/FirebaseRecyclerAdapter.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index c2ae15fa7..e7ca14d0e 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -70,7 +70,7 @@ public abstract class FirebaseListAdapter extends BaseAdapter { mSnapshots.setOnChangedListener(new ChangeEventListener() { @Override public void onChildChanged(EventType type, int index, int oldIndex) { - FirebaseListAdapter.this.onChanged(type, index, oldIndex); + FirebaseListAdapter.this.onChildChanged(type, index, oldIndex); } @Override @@ -148,7 +148,7 @@ public View getView(int position, View view, ViewGroup viewGroup) { /** * @see ChangeEventListener#onChildChanged(ChangeEventListener.EventType, int, int) */ - protected void onChanged(ChangeEventListener.EventType type, int index, int oldIndex) { + protected void onChildChanged(ChangeEventListener.EventType type, int index, int oldIndex) { notifyDataSetChanged(); } diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 66ec2831a..56ed3d428 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -92,7 +92,7 @@ public abstract class FirebaseRecyclerAdapter Date: Tue, 10 Jan 2017 20:41:01 -0800 Subject: [PATCH 13/17] Fix merge mistakes Signed-off-by: Alex Saveau --- .../ui/database/ChangeEventListener.java | 10 +++++++ .../ui/database/FirebaseListAdapter.java | 26 +++++++------------ .../ui/database/FirebaseRecyclerAdapter.java | 25 +++++++----------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java b/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java index e66e8e18f..a8028dc47 100644 --- a/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java +++ b/database/src/main/java/com/firebase/ui/database/ChangeEventListener.java @@ -45,6 +45,16 @@ enum EventType { */ void onChildChanged(EventType type, int index, int oldIndex); + /** This method will be triggered each time updates from the database have been completely processed. + * So the first time this method is called, the initial data has been loaded - including the case + * when no data at all is available. Each next time the method is called, a complete update (potentially + * consisting of updates to multiple child items) has been completed. + *

+ * You would typically override this method to hide a loading indicator (after the initial load) or + * to complete a batch update to a UI element. + */ + void onDataChanged(); + /** * 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. diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index 1f7a8846e..c897c0415 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -74,29 +74,17 @@ public void onChildChanged(EventType type, int index, int oldIndex) { } @Override - public void onCancelled(DatabaseError error) { - FirebaseListAdapter.this.onCancelled(error); + public void onDataChanged() { + FirebaseListAdapter.this.onDataChanged(); } @Override - public void onDataChanged() { - FirebaseListAdapter.this.onDataChanged(); + public void onCancelled(DatabaseError error) { + FirebaseListAdapter.this.onCancelled(error); } }); } - - /* This method will be triggered each time updates from the database have been completely processed. - * So the first time this method is called, the initial data has been loaded - including the case - * when no data at all is available. Each next time the method is called, a complete update (potentially - * consisting of updates to multiple child items) has been completed. - *

- * You would typically override this method to hide a loading indicator (after the initial load) or - * to complete a batch update to a UI element. - */ - protected void onDataChanged() { - } - /** * @param activity The activity containing the ListView * @param modelClass Firebase will marshall the data at a location into @@ -169,6 +157,12 @@ protected void onChildChanged(ChangeEventListener.EventType type, int index, int notifyDataSetChanged(); } + /** + * @see ChangeEventListener#onDataChanged() + */ + protected void onDataChanged() { + } + /** * @see ChangeEventListener#onCancelled(DatabaseError) */ diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index 9655e5149..52ad49f98 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -96,28 +96,17 @@ public void onChildChanged(EventType type, int index, int oldIndex) { } @Override - public void onCancelled(DatabaseError error) { - FirebaseRecyclerAdapter.this.onCancelled(error); + public void onDataChanged() { + FirebaseRecyclerAdapter.this.onDataChanged(); } @Override - public void onDataChanged() { - FirebaseRecyclerAdapter.this.onDataChanged(); + public void onCancelled(DatabaseError error) { + FirebaseRecyclerAdapter.this.onCancelled(error); } }); } - /* This method will be triggered each time updates from the database have been completely processed. - * So the first time this method is called, the initial data has been loaded - including the case - * when no data at all is available. Each next time the method is called, a complete update (potentially - * consisting of updates to multiple child items) has been completed. - *

- * You would typically override this method to hide a loading indicator (after the initial load) or - * to complete a batch update to a UI element. - */ - protected void onDataChanged() { - } - /** * @param modelClass Firebase will marshall the data at a location into * an instance of a class that you provide @@ -219,6 +208,12 @@ protected void onChildChanged(ChangeEventListener.EventType type, int index, int } } + /** + * @see ChangeEventListener#onDataChanged() + */ + protected void onDataChanged() { + } + /** * @see ChangeEventListener#onCancelled(DatabaseError) */ From 50d3d3738df00d2f6c3e26df7d16d450fed8961d Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 12 Jan 2017 16:44:26 -0800 Subject: [PATCH 14/17] Fix merge mistakes Signed-off-by: Alex Saveau --- .../ui/database/FirebaseRecyclerAdapter.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java index d3a86d6f5..52ad49f98 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java @@ -186,18 +186,6 @@ public int getItemViewType(int position) { return mModelLayout; } - /** - * This method will be triggered each time updates from the database have been completely processed. - * So the first time this method is called, the initial data has been loaded - including the case - * when no data at all is available. Each next time the method is called, a complete update (potentially - * consisting of updates to multiple child items) has been completed. - *

- * You would typically override this method to hide a loading indicator (after the initial load) or - * to complete a batch update to a UI element. - */ - protected void onDataChanged() { - } - /** * @see ChangeEventListener#onChildChanged(ChangeEventListener.EventType, int, int) */ From 17a136d524ad4840f49bea54ba740016b7245b19 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Thu, 12 Jan 2017 16:51:52 -0800 Subject: [PATCH 15/17] Fix more merge mistakes Signed-off-by: Alex Saveau --- .../firebase/ui/database/FirebaseListAdapter.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java index 636284509..5ae25c451 100644 --- a/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java +++ b/database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java @@ -150,18 +150,6 @@ public View getView(int position, View view, ViewGroup viewGroup) { return view; } - /** - * This method will be triggered each time updates from the database have been completely processed. - * So the first time this method is called, the initial data has been loaded - including the case - * when no data at all is available. Each next time the method is called, a complete update (potentially - * consisting of updates to multiple child items) has been completed. - *

- * You would typically override this method to hide a loading indicator (after the initial load) or - * to complete a batch update to a UI element. - */ - protected void onDataChanged() { - } - /** * @see ChangeEventListener#onChildChanged(ChangeEventListener.EventType, int, int) */ From 358d50d20ace37061846e66b4526ad2e3eda96d4 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 17 Jan 2017 11:03:03 -0800 Subject: [PATCH 16/17] Cleanup Signed-off-by: Alex Saveau --- .../src/androidTest/java/com/firebase/ui/database/TestUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java b/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java index 1ef5b017c..d36b177a5 100644 --- a/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java +++ b/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java @@ -37,6 +37,7 @@ public static void runAndWaitUntil(FirebaseArray array, Runnable task, Callable done) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); + array.setOnChangedListener(new ChangeEventListener() { @Override public void onChildChanged(ChangeEventListener.EventType type, int index, int oldIndex) { From 4496bafbc9c469fdaa1bbae21519c0f22f61a1e0 Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Tue, 17 Jan 2017 11:05:59 -0800 Subject: [PATCH 17/17] Cleanup Signed-off-by: Alex Saveau --- .../src/androidTest/java/com/firebase/ui/database/TestUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java b/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java index 1ef5b017c..d36b177a5 100644 --- a/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java +++ b/database/src/androidTest/java/com/firebase/ui/database/TestUtils.java @@ -37,6 +37,7 @@ public static void runAndWaitUntil(FirebaseArray array, Runnable task, Callable done) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); + array.setOnChangedListener(new ChangeEventListener() { @Override public void onChildChanged(ChangeEventListener.EventType type, int index, int oldIndex) {