-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Enable listeners on RealmList #4216
Conversation
- Add RealmObservable and RealmCollectionObservable interfaces. - Enable detailed change information for RealmResults through OrderedCollectionChange interface. - Fix a bug in the ObserverPairList which could cause the removed listener gets called if it was removed during previous listener iteration. Fix #989
The listeners should be check by equality.
8711b2a
to
1b6e24e
Compare
I is quite difficult for me to make all the |
The RealmList holds a Collection which is used for listeners. Other RealmList APIs are still calling from LinkView.
1b6e24e
to
bca646f
Compare
|
||
@Test | ||
@RunTestInLooperThread | ||
public void removeALlChangeListeners() { |
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.
ALl -> All
@@ -15,8 +15,7 @@ | |||
|
|||
/** | |||
* General implementation for {@link OrderedRealmCollection} which is based on the {@code Collection}. | |||
* Currently only {@link RealmResults} and {@link OrderedRealmCollectionSnapshot} extend this class. But | |||
* {@link RealmList} could also extend this to share the same iterator implementation. | |||
* Currently only {@link RealmResults} and {@link OrderedRealmCollectionSnapshot} extend this class. |
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.
Any value in this line at all?
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.
no. will remove.
*/ | ||
@Override | ||
public void removeAllChangeListeners() { | ||
realm.checkIfValid(); |
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.
Would be nice if this could be incorporated into the checkForAddRemoveListener
method? Perhaps checkForAddRemoveListener(listener, checkForNull)
?
@@ -13,6 +13,7 @@ | |||
|
|||
* Added support for sorting by link's field (#672). | |||
* Added `OrderedRealmCollectionSnapshot` class and `OrderedRealmCollection.createSnapshot()` method. `OrderedRealmCollectionSnapshot` is useful when changing `RealmResults` or `RealmList` in simple loops. | |||
* Added support for adding listeners on `RealmList`. |
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.
What happens with the iterators?
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.
RealmList
's iterators stay the same. They have quite different meanings compared with RealmResults
. e.g.: RealmList
is actually mutable for users, but RealmResults
is not.
realm.commitTransaction(); | ||
|
||
collection.removeChangeListener(listener1); | ||
collection.removeChangeListener(listener2); |
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.
I think we should keep at least one listener in order to make sure that removeChangeListener
does not remove all listeners.
@@ -348,6 +348,7 @@ public Collection(SharedRealm sharedRealm, LinkView linkView, SortDescriptor sor | |||
this.context = sharedRealm.context; | |||
this.table = linkView.getTable(); | |||
this.context.addReference(this); | |||
this.loaded = true; |
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 not initialize loaded
field twice.
private boolean loaded = false;
should be private boolean loaded;
and assign value in each constructor.
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.
👍
The RealmList holds a Collection which is used for listeners.
Other RealmList APIs are still calling from LinkView.