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

Realm World Tour Tokyo Recent Java Updates

zaki50
March 19, 2017

Realm World Tour Tokyo Recent Java Updates

zaki50

March 19, 2017
Tweet

More Decks by zaki50

Other Decks in Technology

Transcript

  1. Realm Java 3.0.0(৽ػೳ) • ৄࡉͳมߋ௨஌(Fine-grained Collection Notification) • RealmListͷมߋ௨஌αϙʔτ •

    RealmListͷObservableαϙʔτ • RealmResultsͷଈ࣌ߋ৽ͷ෮׆ͱɺεφοϓγϣοτػೳ • ϦϯΫϑΟʔϧυͰͷιʔτ • RealmObjectͷϦεφʔ͕࡟আ࣌ʹ΋ݺ͹ΕΔΑ͏ʹͳͬͨ [email protected]
  2. ैདྷͷίϨΫγϣϯ௨஌ [email protected] 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);
  3. ৄࡉͳίϨΫγϣϯ௨஌ [email protected] 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;
 } }
  4. ৄࡉͳίϨΫγϣϯ௨஌ [email protected] 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);
  5. ৄࡉͳίϨΫγϣϯ௨஌ [email protected] 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);
 }
 }
  6. RealmResultsͱεφοϓγϣοτ [email protected] 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();
 }

  7. RealmResultsͱεφοϓγϣοτ [email protected] 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();
 }

  8. ϦϯΫϑΟʔϧυͰͷιʔτ [email protected] 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);
  9. LinkingObjects [email protected] 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();