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

Realm Japan meetup #22_Java

Realm Japan meetup #22_Java

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

May 29, 2017
Tweet

Transcript

  1. Realm meetup #22 my@realm.io

  2. #realm_jp my@realm.io

  3. Makoto Yamazaki Realm Inc. / uPhyca Inc. my@realm.io

  4. Recent Updates my@realm.io

  5. Realm Java 3.3.1 (was 3.0.0) my@realm.io

  6. Realm Java 3.1(RMD) • ٯํ޲ͷؔ࿈Λαϙʔτ⭐ • Fine-grained Object NotificationରԠ⭐ •

    RealmObjectͷϦεφʔ͕ແବʹτϦΨʔ͞ΕΔͷΛमਖ਼ • commitͷࡍɺಉ͡εϨου্ͷϦεφʔ͕ଈ࠲ʹݺ͹ΕΔΑ͏ʹͳͬͨ • distinct͕ΠϯσοΫεͷແ͍ϑΟʔϧυʹରͯ͠΋࢖༻Մೳʹ • SamsungͷҰ෦ͷσόΠεͰmemmove໋ྩ͕յΕ͍ͯΔ໰୊ʹରॲ#3651 • Android 7.1.1Ͱ֎෦ετϨʔδ্ͷϑΝΠϧΛ։͚ͳ͍໰୊ʹରॲ#4461 • كʹgetFilesDir()͕nullΛฦ͢໰୊ʹରॲ#4493 • OrderedRealmCollectionSnapshot.get(int)͕ޡͬͨςʔϒϧΛࢀর͢Δ#4554 my@realm.io
  7. Realm Java 3.1(RMP) • ϑΝΠϧϑΥʔϚοτมߋͷͨΊɺ1.3.0Ҏ্ͷαʔόʔ͕ඞཁ • ΫϥΠΞϯτϦηοτ͕ൃੜͨ͠ࡍʹɺچσʔλϕʔεͷύε͕औಘՄೳ • ೝূURL͕pathΛ࣋ͨͳ͍৔߹ɺࣗಈతʹ /auth͕෇༩͞ΕΔ

    • ηογϣϯ։࢝ޙͷϩάϨϕϧมߋΛਖ਼͘͠൓ө#4337 • ௨৴͕෮׆ͨ͠ࡍʹɺಉظͷ࠶։Λ࠷దԽ#4141 my@realm.io
  8. Realm Java 3.2(RMD) • transientͳϑΟʔϧυΛαϙʔτ(@Ignoreѻ͍) • Realm.refresh()ɺ DynamicRealm.refresh()Λ෮׆ • Ream.getInstanceAsync()ɺDynamicRealm.getInstanceAsync()Λ௥Ճ⭐

    • DynamicRealmObject͕Ͱ΋ٯํ޲ͷؔ࿈Λαϙʔτ • Read Only RealmΛαϙʔτ • ҉߸Խ͞ΕͨRealmͰͷΫϥογϡमਖ਼#4343 • τϥϯβΫγϣϯ֎Ͱͷมߋʹର͢Δྫ֎ϝοηʔδมߋ my@realm.io
  9. Realm Java 3.2(RMP) • SyncUser.isAdmin()ɺSyncUser.changePassword()Λ௥Ճ • SyncConfiguration.Builder.waitForInitialRemoteData()Λ௥Ճ • ϞσϧΫϥεʹଘࡏ͠ͳ͍ϑΟʔϧυΛਖ਼͘͠ແࢹ͢ΔΑ͏मਖ਼#4658 my@realm.io

  10. Realm Java 3.3(RMP) • SyncConfigurationʹtrustedRootCA()ͰRootCAͷূ໌ॻΛ౉͢ػೳΛ௥Ճ • SyncConfigurationʹSSLͷূ໌ॻݕূΛແޮԽ͢ΔػೳΛ௥Ճ • 3.2Ͱमਖ਼ͨ͠ϞσϧΫϥεʹଘࡏ͠ͳ͍ϑΟʔϧυνΣοΫΛ࠶౓मਖ਼#4706 my@realm.io

  11. ٯํ޲ͷؔ࿈αϙʔτ 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).findFirst().owners; owners.size(); ͜ͷΦϒδΣΫτΛdogϑΟʔϧυ͔Β ࢀর͍ͯ͠ΔશͯͷPersonΦϒδΣΫτ
  12. ඇಉظͳRealmΠϯελϯεͷऔಘ my@realm.io final RealmConfiguration config = new SyncConfiguration.Builder(user, uri) .waitForInitialRemoteData()

    .build(); Realm.getInstanceAsync(config, new Realm.Callback() { @Override public void onSuccess(Realm r) { realm = r; showData(); } });
  13. Fine-grained Object Notification my@realm.io public interface RealmObjectChangeListener<T extends RealmModel> {

    void onChange(T t, ObjectChangeSet changeSet); } public interface ObjectChangeSet { boolean isDeleted(); String[] getChangedFields(); boolean isFieldChanged(String fieldName); }
  14. Google I/O 2017 my@realm.io

  15. Google I/Oͱ͸ • Google͕ຖ೥։࠵͍ͯ͠Δ։ൃऀ޲͚ΧϯϑΝϨϯε • Googleຊࣾྡͷ໺֎Πϕϯτձ৔(γϣΞϥΠϯ ΞϯϑΟγΞλʔ)Ͱ։࠵ • ΩʔϊʔτɺηογϣϯɺαϯυϘοΫεɺΦϑΟεΞϫʔɺίʔυϥϘ •

    ࠷ۙ͸AndroidɺػցֶशɺVRத৺(Ϋϥ΢υܥ͸Google Could Next΁ • ηογϣϯ͸ଈ࣌youtubeͰެ։͞ΕΔ • Ҏલ͸ߴֹͳ͓౔࢈͕഑ΒΕ͍͕ͯͨɺ࠷ۙ͸߇͑Δ܏޲ my@realm.io
  16. Architecture Components http://developer.android.com/arch my@realm.io

  17. Architecture Components • Google͕ਪ঑͢ΔΞʔΩςΫνϟͷΨΠυͱπʔϧ (ਪ঑Ͱ͋ͬͯඞਢͰ͸ແ͍ • LifecycleOwner, LifecycleObserver, ViewModel, LiveData,

    Room • ঺հಈը https://www.youtube.com/watch?v=vOJCrbr144o&t=25s • ϥΠϑαΠΫϧʹԠͨ͡ॲཧ͕هड़͠΍͘͢ͳΔ • αϯϓϧϓϩδΣΫτ https://github.com/realm/realm-java/pull/4685 • ͍ۙ͏ͪʹRealmͷϒϩάͰऔΓ্͛·͢ my@realm.io
  18. Lifecycle my@realm.io https://developer.android.com/topic/libraries/architecture/lifecycle.html#lc

  19. LifecycleObserver my@realm.io public class MyObserver implements LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) void

    onCreate() { } @OnLifecycleEvent(Lifecycle.Event.ON_START) void onStart() { } @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) void onResume() { } @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) void onPause() { } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) void onStop() { } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) void onDestroy() { } } public class MyActivity extends LifecycleActivity { @Override protected void onCreate(Bundle savedInstanceState) { ... getLifecycle().addObserver(new MyObserver()); } }
  20. ViewModel my@realm.io https://developer.android.com/topic/libraries/architecture/ viewmodel.html#the_lifecycle_of_a_viewmodel

  21. ViewModel my@realm.io public class ExampleViewModel extends ViewModel { private final

    Realm realm; private final LiveRealmObject<Person> livePerson; public ExampleViewModel() { realm = Realm.getDefaultInstance(); livePerson = new LiveRealmObject<>(realm.where(Person.class) .findAllSorted("name").first()); } public LiveRealmObject<Person> getPerson() { return livePerson; } @Override protected void onCleared() { realm.close(); super.onCleared(); } }
  22. ViewModel my@realm.io @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(...);

    exampleViewModel = ViewModelProviders.of(this) .get(ExampleViewModel.class); exampleViewModel.getPerson() .observe(this, person -> updateViews(person)); }
  23. Kotlin support my@realm.io https://goo.gl/maps/fL44p7ang2r

  24. Realm Javaͷݱঢ় • Kotlin͸αϙʔτ͍ͯ͠·͢ʂ • ͞ΒʹKotlinαϙʔτΛॆ࣮ͤ͞Δํ޲ • POC: Kotlin Extension

    Library https://github.com/realm/realm-java/pull/4684 • Realm಺ͰͷKotlinͷར༻ͷ֦େ • Enable Kotlin for unit tests https://github.com/realm/realm-java/pull/4719 my@realm.io
  25. ݱঢ়ͷKotlinαϙʔτ open class User : RealmObject() { @PrimaryKey var id:

    Long = 0 var name: String = "" var description: Sting? = null } my@realm.io
  26. Kotlinαϙʔτͷॆ࣮ • POC: Kotlin Extension Library #4684 ͰΞΠσΟΞืूத • KClass,

    KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺ • @NotNull, @NullableΞϊςʔγϣϯ෇༩ʹΑΔ਌࿨ੑ޲্ • Ϟσϧఆٛʹ࢖ΘΕͨඇNullܕΛ@Requiredѻ͍ʹ my@realm.io Any idea?
  27. Ξϯέʔτͷճ౴Λ͓ئ͍͠·͢ jp@realm.io http://bit.ly/RealmJP_22