From 67a455747b309236712ccac16c52a372ebf0fd17 Mon Sep 17 00:00:00 2001 From: Thorben Primke Date: Mon, 25 Apr 2016 21:43:46 -0700 Subject: [PATCH] Update to Realm 89.1 --- build.gradle | 2 +- .../example/MainActivity.java | 2 +- example/build.gradle | 4 +-- .../realm/RealmBasedRecyclerViewAdapter.java | 25 +++++++++++-------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 6f78c77..72ad69c 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:1.3.0' - classpath "io.realm:realm-gradle-plugin:0.88.2" + classpath "io.realm:realm-gradle-plugin:0.89.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/example/app/src/main/java/co/moonmonkeylabs/realmrecyclerview/example/MainActivity.java b/example/app/src/main/java/co/moonmonkeylabs/realmrecyclerview/example/MainActivity.java index e4bba18..7bd2a8f 100644 --- a/example/app/src/main/java/co/moonmonkeylabs/realmrecyclerview/example/MainActivity.java +++ b/example/app/src/main/java/co/moonmonkeylabs/realmrecyclerview/example/MainActivity.java @@ -325,7 +325,7 @@ protected Void doInBackground(Void... params) { instance.where(QuoteModel.class).equalTo("id", id).findFirst(); if (quoteModel != null) { instance.beginTransaction(); - quoteModel.removeFromRealm(); + quoteModel.deleteFromRealm(); instance.commitTransaction(); } instance.close(); diff --git a/example/build.gradle b/example/build.gradle index 3a81316..c5c6379 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -5,9 +5,9 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0-alpha5' + classpath 'com.android.tools.build:gradle:2.1.0-rc1' - classpath "io.realm:realm-gradle-plugin:0.88.2" + classpath "io.realm:realm-gradle-plugin:0.89.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/library/src/main/java/io/realm/RealmBasedRecyclerViewAdapter.java b/library/src/main/java/io/realm/RealmBasedRecyclerViewAdapter.java index c8de249..8d41d5f 100644 --- a/library/src/main/java/io/realm/RealmBasedRecyclerViewAdapter.java +++ b/library/src/main/java/io/realm/RealmBasedRecyclerViewAdapter.java @@ -38,6 +38,8 @@ import difflib.Delta; import difflib.DiffUtils; import difflib.Patch; +import io.realm.internal.RealmObjectProxy; +import io.realm.internal.Row; import io.realm.internal.TableOrView; /** @@ -334,13 +336,13 @@ public void close() { public void updateRealmResults(RealmResults queryResults) { if (listener != null) { if (realmResults != null) { - realmResults.realm.removeChangeListener(listener); + realmResults.removeChangeListener(listener); } } realmResults = queryResults; if (realmResults != null) { - realmResults.realm.addChangeListener(listener); + realmResults.addChangeListener(listener); } updateRowWrappers(); @@ -384,10 +386,13 @@ private List getIdsOfRealmResults() { private Object getRealmRowId(int realmIndex) { Object rowPrimaryId; + RealmObjectProxy proxy = (RealmObjectProxy) realmResults.get(realmIndex); + Row row = proxy.realmGet$proxyState().getRow$realm(); + if (animatePrimaryIdType == RealmFieldType.INTEGER) { - rowPrimaryId = realmResults.get(realmIndex).row.getLong(animatePrimaryColumnIndex); + rowPrimaryId = row.getLong(animatePrimaryColumnIndex); } else if (animatePrimaryIdType == RealmFieldType.STRING) { - rowPrimaryId = realmResults.get(realmIndex).row.getString(animatePrimaryColumnIndex); + rowPrimaryId = row.getString(animatePrimaryColumnIndex); } else { throw new IllegalStateException("Unknown animatedIdType"); } @@ -396,11 +401,9 @@ private Object getRealmRowId(int realmIndex) { String rowPrimaryIdStr = (rowPrimaryId instanceof String) ? (String) rowPrimaryId : String.valueOf(rowPrimaryId); if (animateExtraIdType == RealmFieldType.INTEGER) { - return rowPrimaryIdStr + String.valueOf( - realmResults.get(realmIndex).row.getLong(animateExtraColumnIndex)); + return rowPrimaryIdStr + String.valueOf(row.getLong(animateExtraColumnIndex)); } else if (animateExtraIdType == RealmFieldType.STRING) { - return rowPrimaryIdStr + - realmResults.get(realmIndex).row.getString(animateExtraColumnIndex); + return rowPrimaryIdStr + row.getString(animateExtraColumnIndex); } else { throw new IllegalStateException("Unknown animateExtraIdType"); } @@ -422,7 +425,9 @@ private void updateRowWrappers() { final long headerIndex = realmResults.getTable().getColumnIndex(headerColumnName); int i = 0; for (RealmObject result : realmResults) { - String header = createHeaderFromColumnValue(result.row.getString(headerIndex)); + String rawHeader = ((RealmObjectProxy) result) + .realmGet$proxyState().getRow$realm().getString(headerIndex); + String header = createHeaderFromColumnValue(rawHeader); if (!TextUtils.equals(lastHeader, header)) { // Insert new header view and update section data. sectionFirstPosition = i + headerCount; @@ -573,7 +578,7 @@ public void removeFooter() { public void onItemSwipedDismiss(int position) { final BaseRealm realm = realmResults.realm; realm.beginTransaction(); - realmResults.get(position).removeFromRealm(); + realmResults.get(position).deleteFromRealm(); realm.commitTransaction(); } }