Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Realm World Tour Tokyo Recent Java Updates

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
March 19, 2017

Realm World Tour Tokyo Recent Java Updates

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

March 19, 2017
Tweet

Transcript

  1. Java Updates Makoto Yamazaki #RealmWorld

  2. Realm Java 3.0.0 my@realm.io

  3. Realm Java 2.3.0(৽ػೳ) • จࣈྻʹର͢Δlikeݕࡧ my@realm.io query.like("text", "*");
 query.like("text", "?ohn*");

    ?: ೚ҙͷϢχίʔυจࣈ1จࣈ *: 0จࣈҎ্ͷϢχίʔυจࣈ
  4. Realm Java 3.0.0(৽ػೳ) • ৄࡉͳมߋ௨஌(Fine-grained Collection Notification) • RealmListͷมߋ௨஌αϙʔτ •

    RealmListͷObservableαϙʔτ • RealmResultsͷଈ࣌ߋ৽ͷ෮׆ͱɺεφοϓγϣοτػೳ • ϦϯΫϑΟʔϧυͰͷιʔτ • RealmObjectͷϦεφʔ͕࡟আ࣌ʹ΋ݺ͹ΕΔΑ͏ʹͳͬͨ my@realm.io
  5. Realm Java 3.0.0(ඇޓ׵ͳมߋ) • RealmResults#distinct()͕৽ͨͳRealmResultsΛฦ͢ • RealmResultsͷଈ࣌ߋ৽ • RealmObjectͷϦεφʔ͕࡟আ࣌ʹ΋ݺ͹ΕΔΑ͏ʹͳͬͨ my@realm.io

  6. ैདྷͷίϨΫγϣϯ௨஌ my@realm.io public interface RealmChangeListener<T> {
 /**
 * Called when

    a transaction is committed.
 */
 void onChange(T element);
 }
  7. ैདྷͷίϨΫγϣϯ௨஌ my@realm.io RealmChangeListener<RealmResults<Dog>> listener; final RealmResults<Dog> puppies = realm.where(Dog.class)
 .lessThan("age",

    2).findAll();
 listener = new RealmChangeListener<RealmResults<Dog>>() {
 @Override
 public void onChange(RealmResults<Dog> collection) {
 listView.notifyDatasetChanged();
 }
 };
 puppies.addChangeListener(listener);
  8. ৄࡉͳίϨΫγϣϯ௨஌ my@realm.io public interface OrderedRealmCollectionChangeListener<T> {
 void onChange(T collection, OrderedCollectionChangeSet

    changeSet); } public interface OrderedCollectionChangeSet {
 int[] getDeletions();
 int[] getInsertions();
 int[] getChanges();
 
 Range[] getDeletionRanges();
 Range[] getInsertionRanges();
 Range[] getChangeRanges();
 
 class Range {
 public final int startIndex;
 public final int length;
 } }
  9. ৄࡉͳίϨΫγϣϯ௨஌ my@realm.io OrderedRealmCollectionChangeListener<RealmResults<Dog>> listener; final RealmResults<Dog> puppies = realm.where(Dog.class)
 .lessThan("age",

    2).findAll();
 listener = new OrderedRealmCollectionChangeListener<RealmResults<Dog>>() {
 @Override
 public void onChange(RealmResults<Dog> collection, OrderedCollectionChangeSet changeSet) {
 ...
 }
 };
 puppies.addChangeListener(listener);
  10. ৄࡉͳίϨΫγϣϯ௨஌ my@realm.io public void onChange(Object collection, OrderedCollectionChangeSet changeSet) {
 if

    (changeSet == null) {
 notifyDataSetChanged();
 return;
 }
 OrderedCollectionChangeSet.Range[] deletions = changeSet.getDeletionRanges();
 for (int i = deletions.length - 1; i >= 0; i--) {
 OrderedCollectionChangeSet.Range range = deletions[i];
 notifyItemRangeRemoved(range.startIndex, range.length);
 }
 
 OrderedCollectionChangeSet.Range[] insertions = changeSet.getInsertionRanges();
 for (OrderedCollectionChangeSet.Range range : insertions) {
 notifyItemRangeInserted(range.startIndex, range.length);
 }
 
 OrderedCollectionChangeSet.Range[] modifications = changeSet.getChangeRanges();
 for (OrderedCollectionChangeSet.Range range : modifications) {
 notifyItemRangeChanged(range.startIndex, range.length);
 }
 }
  11. General header jp@realm.io RecyclerViewͷdemo

  12. Realm Android Adapters my@realm.io https://github.com/realm/realm-android-adapters/ dependencies { compile 'io.realm:android-adapters:2.0.0' }

    class MyRecyclerViewAdapter extends RealmRecyclerViewAdapter<Dog, ViewHolder> {
 ...
 }

  13. εφοϓγϣοτ my@realm.io • RealmResultsʹଈ࠲ʹมߋ͕൓ө͞ΕΔΑ͏ʹͳͬͨ • OrderedRealmCollectionSnapshot RealmResults#createSnapshot()Λ௥Ճ • OrderedRealmCollectionSnapshotࣗମʹ͸มߋ͕൓ө͞Εͳ͍

  14. RealmResultsͱεφοϓγϣοτ my@realm.io OrderedRealmCollection<Guest> uninvited = realm.where(Guest.class)
 .equalTo("invited", false)
 .findAll();
 


    for (i = 0; i < uninvited.size(); i++) {
 realm.beginTransaction(); uninvitedGuests.get(i).invited = true;
 realm.commitTransaction();
 }

  15. RealmResultsͱεφοϓγϣοτ my@realm.io OrderedRealmCollection<Guest> uninvited = realm.where(Guest.class)
 .equalTo("invited", false)
 .findAll().createSnapshot();
 


    for (i = 0; i < uninvited.size(); i++) {
 realm.beginTransaction();
 uninvitedGuests.get(i).invited = true;
 realm.commitTransaction();
 }

  16. ϦϯΫϑΟʔϧυͰͷιʔτ my@realm.io public class Person extends RealmObject{
 public String name;


    public Dog dog;
 }
 public class Dog extends RealmObject{
 public String name;
 public int age;
 }
 RealmResults<Person> persons = realm.where(Person.class) .findAllSorted("dog.age", Sort.ASCENDING);
  17. Realm Java 3.1ͷ༧ఆ • LinkingObjectαϙʔτ • RealmObjectͷৄࡉͳมߋ௨஌ • ಉظঢ়گͷ௨஌ػೳ my@realm.io

  18. LinkingObjects my@realm.io public class Person extends RealmObject{
 public String name;


    public Dog dog;
 } 
 public class Dog extends RealmObject{
 public String name;
 public int age; @LinkingObjects("dog") public RealmResults<Person> owners;
 } RealmResults<Person> owners; owners = realm.where(Dog.class).findAll().first().owners; owners.size();