Commit 9a224440 authored by Tiago Cunha's avatar Tiago Cunha

Stops the same object from been propagated over and over as if updated

parent 2ae619c8
...@@ -22,7 +22,7 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes ...@@ -22,7 +22,7 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes
} }
protected boolean isSame(T element1, T element2) { protected boolean isSame(T element1, T element2) {
return false; return element1.equals(element2);
} }
} }
...@@ -47,29 +47,31 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes ...@@ -47,29 +47,31 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes
private T previousResult; private T previousResult;
@Override protected final RealmResults<T> queryItems(Realm realm) { @Override
protected final RealmResults<T> queryItems(Realm realm) {
return query.query(realm).findAll(); return query.query(realm).findAll();
} }
@Override protected final RealmChangeListener<RealmResults<T>> getListener() { @Override
protected final RealmChangeListener<RealmResults<T>> getListener() {
return new RealmChangeListener<RealmResults<T>>() { return new RealmChangeListener<RealmResults<T>>() {
@Override public void onChange(RealmResults<T> element) { @Override
T source = impl.extractObjectFromResults(element); public void onChange(RealmResults<T> element) {
T target = source != null ? realm.copyFromRealm(source) : null; T currentResult = impl.extractObjectFromResults(element);
if (previousResult != null && impl.isSame(previousResult, target)) { if (previousResult != null && impl.isSame(previousResult, currentResult)) {
return; return;
} }
previousResult = target; previousResult = currentResult;
if (onUpdateListener != null) { if (onUpdateListener != null) {
onUpdateListener.onUpdateObject(target); onUpdateListener.onUpdateObject(
currentResult != null ? realm.copyFromRealm(currentResult) : null);
} }
} }
}; };
} }
public void sub() { public void sub() {
previousResult = null; previousResult = null;
super.sub(); super.sub();
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment