Skip to content

Commit

Permalink
#1594 RealmChangeListener should provide the changes object/realm/col…
Browse files Browse the repository at this point in the history
…lection as well (#2705)

RealmChangeListener should provide the changes object/realm/collection as well
  • Loading branch information
nhachicha committed Apr 29, 2016
1 parent 0e3651e commit c0a13d7
Show file tree
Hide file tree
Showing 28 changed files with 595 additions and 365 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Breaking changes

* RealmChangeListener provides the changed object/Realm/collection as well (#1594).
* All JSON methods on Realm now only wraps JSONException in RealmException. All other Exceptions are thrown as they are.
* Marked all methods on `RealmObject` and all public classes final (#1594).
* Removed `BaseRealm` from the public API.
Expand Down
Expand Up @@ -40,7 +40,7 @@
/**
* This fragment demonstrates how you can perform asynchronous queries with Realm.
*/
public class AsyncQueryFragment extends Fragment implements View.OnClickListener, RealmChangeListener {
public class AsyncQueryFragment extends Fragment implements View.OnClickListener, RealmChangeListener<RealmResults<Dot>> {
private Realm realm;
private DotAdapter dotAdapter;
private RealmResults<Dot> allSortedDots;
Expand Down Expand Up @@ -135,7 +135,7 @@ private void cancelAsyncTransaction() {
}

@Override
public void onChange() {
public void onChange(RealmResults<Dot> result) {
dotAdapter.notifyDataSetChanged();
}

Expand Down
Expand Up @@ -44,9 +44,9 @@ public class ThreadFragment extends Fragment {
private DotsView dotsView;

// Realm change listener that refreshes the UI when there is changes to Realm.
private RealmChangeListener realmListener = new RealmChangeListener() {
private RealmChangeListener<Realm> realmListener = new RealmChangeListener<Realm>() {
@Override
public void onChange() {
public void onChange(Realm realm) {
dotsView.invalidate();
}
};
Expand Down
Expand Up @@ -54,7 +54,7 @@
* <ol>
* <li>Create proxy classes for all classes marked with @RealmClass. They are named &lt;className&gt;RealmProxy.java</li>
* <li>Create a DefaultRealmModule containing all RealmObject classes (if needed).</li>
* <li>Create a RealmProxyMediator class for all classes marked with @RealmModule. They are named <moduleName>Mediator.java</li>
* <li>Create a RealmProxyMediator class for all classes marked with {@code @RealmModule}. They are named {@code <moduleName>Mediator.java}</li>
* </ol>
*
* <h1>WHY</h1>
Expand All @@ -68,7 +68,7 @@
* annotated with @RealmModule(library = true). It is not allowed to have both a class with library = true and
* library = false in the same IntelliJ module and it will cause the annotation processor to throw an exception. If no
* library modules are defined, we will create a DefaultRealmModule containing all known RealmObjects and with the
* @RealmModule annotation. Realm automatically knows about this module, but it is still possible for users to create
* {@code @RealmModule} annotation. Realm automatically knows about this module, but it is still possible for users to create
* their own modules with a subset of model classes.</li>
*
* <li>For each class annotated with @RealmModule a matching Mediator class is created (including the default one). This
Expand Down
Expand Up @@ -196,7 +196,7 @@ private void emitConstructor(JavaWriter writer) throws IOException {
// FooRealmProxy(ColumnInfo)
writer.beginConstructor(EnumSet.noneOf(Modifier.class), "ColumnInfo", "columnInfo");
writer.emitStatement("this.columnInfo = (%s) columnInfo", columnInfoClassName());
writer.emitStatement("this.proxyState = new ProxyState(%s.class)", className);
writer.emitStatement("this.proxyState = new ProxyState(%s.class, this)", className);
writer.endConstructor();
writer.emitEmptyLine();
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ static final class AllTypesColumnInfo extends ColumnInfo {

AllTypesRealmProxy(ColumnInfo columnInfo) {
this.columnInfo = (AllTypesColumnInfo) columnInfo;
this.proxyState = new ProxyState(AllTypes.class);
this.proxyState = new ProxyState(AllTypes.class, this);
}

@SuppressWarnings("cast")
Expand Down
Expand Up @@ -68,7 +68,7 @@ static final class BooleansColumnInfo extends ColumnInfo {

BooleansRealmProxy(ColumnInfo columnInfo) {
this.columnInfo = (BooleansColumnInfo) columnInfo;
this.proxyState = new ProxyState(Booleans.class);
this.proxyState = new ProxyState(Booleans.class, this);
}

@SuppressWarnings("cast")
Expand Down
Expand Up @@ -153,7 +153,7 @@ static final class NullTypesColumnInfo extends ColumnInfo {

NullTypesRealmProxy(ColumnInfo columnInfo) {
this.columnInfo = (NullTypesColumnInfo) columnInfo;
this.proxyState = new ProxyState(NullTypes.class);
this.proxyState = new ProxyState(NullTypes.class, this);
}

@SuppressWarnings("cast")
Expand Down
Expand Up @@ -58,7 +58,7 @@ static final class SimpleColumnInfo extends ColumnInfo {

SimpleRealmProxy(ColumnInfo columnInfo) {
this.columnInfo = (SimpleColumnInfo) columnInfo;
this.proxyState = new ProxyState(Simple.class);
this.proxyState = new ProxyState(Simple.class, this);
}

@SuppressWarnings("cast")
Expand Down
Expand Up @@ -337,10 +337,9 @@ public void findFirstAsync() {
.between(AllTypes.FIELD_LONG, 4, 9)
.findFirstAsync();
assertFalse(allTypes.isLoaded());

allTypes.addChangeListener(new RealmChangeListener() {
allTypes.addChangeListener(new RealmChangeListener<DynamicRealmObject>() {
@Override
public void onChange() {
public void onChange(DynamicRealmObject object) {
assertEquals("test data 4", allTypes.getString(AllTypes.FIELD_STRING));
dynamicRealm.close();
looperThread.testComplete();
Expand All @@ -359,9 +358,9 @@ public void findAllAsync() {
assertFalse(allTypes.isLoaded());
assertEquals(0, allTypes.size());

allTypes.addChangeListener(new RealmChangeListener() {
allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>() {
@Override
public void onChange() {
public void onChange(RealmResults<DynamicRealmObject> object) {
assertEquals(6, allTypes.size());
for (int i = 0; i < allTypes.size(); i++) {
assertEquals("test data " + (4 + i), allTypes.get(i).getString(AllTypes.FIELD_STRING));
Expand All @@ -382,9 +381,9 @@ public void findAllSortedAsync() {
assertFalse(allTypes.isLoaded());
assertEquals(0, allTypes.size());

allTypes.addChangeListener(new RealmChangeListener() {
allTypes.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>() {
@Override
public void onChange() {
public void onChange(RealmResults<DynamicRealmObject> object) {
assertEquals(5, allTypes.size());
for (int i = 0; i < 5; i++) {
int iteration = (4 - i);
Expand Down Expand Up @@ -450,9 +449,9 @@ public void run() {
}
};

realmResults1.addChangeListener(new RealmChangeListener() {
realmResults1.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>() {
@Override
public void onChange() {
public void onChange(RealmResults<DynamicRealmObject> object) {
assertEquals("data 0", realmResults1.get(0).get(AllTypes.FIELD_STRING));
assertEquals(3L, realmResults1.get(0).get(AllTypes.FIELD_LONG));
assertEquals("data 0", realmResults1.get(1).get(AllTypes.FIELD_STRING));
Expand Down Expand Up @@ -480,9 +479,9 @@ public void onChange() {
}
});

realmResults2.addChangeListener(new RealmChangeListener() {
realmResults2.addChangeListener(new RealmChangeListener<RealmResults<DynamicRealmObject>>() {
@Override
public void onChange() {
public void onChange(RealmResults<DynamicRealmObject> object) {
assertEquals("data 2", realmResults2.get(0).get(AllTypes.FIELD_STRING));
assertEquals(1L, realmResults2.get(0).get(AllTypes.FIELD_LONG));
assertEquals("data 2", realmResults2.get(1).get(AllTypes.FIELD_STRING));
Expand Down

0 comments on commit c0a13d7

Please sign in to comment.