Skip to content

The Big Kahuna of firebase-ui-database #544

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 121 commits into from
Mar 6, 2017
Merged

The Big Kahuna of firebase-ui-database #544

merged 121 commits into from
Mar 6, 2017

Conversation

SUPERCILEX
Copy link
Collaborator

@SUPERCILEX SUPERCILEX commented Jan 26, 2017

Enables #539 (I think)
#337
@TheCraftKid I think this one will make you happy! (and your library obsolete 😄)

@samtstern Sorry about this one, the amount of changes is high up there on my list of biggest PRs, but I believe all of this is necessary for us to be able to commit to maintaining firebase-ui-database in the long term.

  • Decide what to do about equals and hashCode.
  • Thoroughly test stuff
  • Figure out what to do about the performance issues with FirebaseArrayOfObjects
  • Explain what's going on in FirebaseArrayOfObjectsOptimized (Fixed in fda5417)

Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
…lback

# Conflicts:
#	app/src/main/java/com/firebase/uidemo/database/ChatActivity.java
#	database/src/main/java/com/firebase/ui/database/FirebaseArray.java
#	database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java
#	database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java
Signed-off-by: Alex Saveau <[email protected]>
# Conflicts:
#	database/src/main/java/com/firebase/ui/database/FirebaseArray.java
# Conflicts:
#	database/src/androidTest/java/com/firebase/ui/database/TestUtils.java
# Conflicts:
#	database/src/androidTest/java/com/firebase/ui/database/TestUtils.java
…lback

# Conflicts:
#	app/src/main/java/com/firebase/uidemo/database/ChatActivity.java
#	database/src/androidTest/java/com/firebase/ui/database/TestUtils.java
#	database/src/main/java/com/firebase/ui/database/FirebaseArray.java
#	database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java
#	database/src/main/java/com/firebase/ui/database/FirebaseListAdapter.java
#	database/src/main/java/com/firebase/ui/database/FirebaseRecyclerAdapter.java
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
@SUPERCILEX
Copy link
Collaborator Author

@samtstern Hmmm, your branch looks really interesting! The gist I got from it was to make the model class a first class citizen instead of DataSnapshot which makes way more sense. I don't really like that you have a getObject instead of getSnapshot method thus moving the model class a little further back. What do you think of rewriting this PR with your changes, but implementing List<E> in ObservableSnapshotArray instead of List<DataSnapshot>? (We could call it ObservableModelArray<T> or something better.)

@puf
Copy link
Contributor

puf commented Feb 25, 2017 via email

Change-Id: I831fd0bae52970ff7db6f4ab1ae2fdb7aa04200a
@samtstern
Copy link
Contributor

samtstern and others added 5 commits March 1, 2017 09:51
… object, change type name to `E` in ObservableSnapshotArray to unhide type T in toArray method, remove getSnapshots(int) method from FirebaseArray since there's already get(int), use `index` instead of `newIndex` in onKeyMove in FirebaseIndexArray

Signed-off-by: Alex Saveau <[email protected]>
@SUPERCILEX
Copy link
Collaborator Author

@samtstern The index adapters were completely broken because we forgot to pass in a parser. Since I feel like this could be a recurring theme, I just removed the possibility of a null parser in 7601ded. If devs really don't want to provide a model class for some reason, they can just pass in Object.class and it will return an object:

var1.equals(Object.class)?var0:(var1.isEnum()?zzd(var0, var1):zze(var0, var1));

I also had to write a hacky constructor that really bothers me, but I couldn't think of a better way of doing it that would still let devs extend the adapters while passing in their own FirebaseArray. What do you think of 7601ded?

@samtstern
Copy link
Contributor

@SUPERCILEX

  1. I am fine with removing the null parser option, like you did.
  2. Can you explain a little more what is enabled by adding the empty constructors for the adapters? I think I am missing something.

@SUPERCILEX
Copy link
Collaborator Author

SUPERCILEX commented Mar 2, 2017

@samtstern

  1. Awesome!
  2. Java forces you to either have a default constructor (the option I opted for) or to call super in the constructor you're extending.
public class First {
    public First(String foo) {}
}

private class Second extends First {
    public Second() {} // Doesn't compile

    public Second(String bar) { super(bar); } // Compiles
}

Since we also can't pass this into a super call, we're stuck again. Hope that helps clear things up!

super(activity, modelClass, modelLayout, new FirebaseIndexArray(keyRef, dataRef));
Query keyQuery,
DatabaseReference dataRef) {
init(activity, new FirebaseIndexArray<>(keyQuery, dataRef, this), modelClass, modelLayout);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm now I see what happened here. Having init be protected and called by the super class definitely "smells" and makes me think we got something wrong.

Seems like the problem is the circular reference between the adapter and the array, even though it goes through the SnapshotParser interface.

Any thoughts on how we can make this better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@samtstern Hmmm, I found out that you can't reference non-static fields or methods either in a constructor call so that means no forwarding calls or anything like that. At this point, the only solution I can think of is using a setter for the parser, but I feel like that's way more hacky and makes the intentions less clear. Also, that beats the point of initializing everything for people because they will have to call setParser. @puf Have you encountered this kind of issue before or have any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a possible answer. Since we're breaking parseSnapshot anyway, what if we removed it from the adapter entirely and instead had the adapters take an optional SnapshotParser in their constructor. They would pass it through to the FirebaseArray if provided.

This seems to be a better representation of the hierarchy anyway,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@samtstern As long as you're fine with making more breaking api changes, that solution sounds awesome to me!

@SUPERCILEX
Copy link
Collaborator Author

@samtstern I'm getting this really weird crash because ChildEventListeners are firing even though we removed the listener. I checked and there is only one pair of add/removing being called so that's not the issue. At this point, I think it's a Firebase problem, not this PR.

Here are some screenshots showing that even though removeEventListener was called, onChildMoved still gets called:

image

image

@samtstern
Copy link
Contributor

@SUPERCILEX looks like maybe it's how we're casting? We're calling removeEventListener(this) twice but maybe we need removeEventListener((ChildEventListener) this); removeEventListener((ValueEventListener) this);

@SUPERCILEX
Copy link
Collaborator Author

@samtstern I was confused by that too, but I think it's just a decompiling bug (java doesn't let you do what's in the screenshot anyway--I checked). If you look at our real code, we are casting things correctly: https://github.com/firebase/FirebaseUI-Android/pull/544/files#diff-fd5c505ad432166321255bc4541624ddR89 so I'm pretty sure this is an issue with the RTDB.

@samtstern
Copy link
Contributor

@SUPERCILEX yep you're right, it's not the casting issue.

I just took a look at this and (I can't believe I'm saying it) but I'm ready to merge this beast! Could you file a new issue about the possible listener removal race condition thing? Definitely worth tracking but it does not seem to be a direct result of this PR.

Do you have any oppositions to my doing a 'squash and merge' on this PR?

@samtstern
Copy link
Contributor

giphy

@SUPERCILEX
Copy link
Collaborator Author

@samtstern AWESOME!!!!

Yeah, I already filed a bug for the slow listener removal.

No objections at all, please don't do anything but a squash. There are way too many commits in this PR!

@SUPERCILEX
Copy link
Collaborator Author

Haha, nice gif!

@samtstern samtstern merged commit ac5c849 into firebase:version-2.0.0-dev Mar 6, 2017
@samtstern samtstern added this to the 2.0.0 milestone Mar 6, 2017
@SUPERCILEX SUPERCILEX deleted the FirebaseArray branch March 6, 2017 03:26
samtstern pushed a commit that referenced this pull request Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants