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

Realm Japan meetup #22_Java

Realm Japan meetup #22_Java

zaki50

May 29, 2017
Tweet

More Decks by zaki50

Other Decks in Technology

Transcript

  1. 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 [email protected]
  2. Realm Java 3.2(RMD) • transientͳϑΟʔϧυΛαϙʔτ(@Ignoreѻ͍) • Realm.refresh()ɺ DynamicRealm.refresh()Λ෮׆ • Ream.getInstanceAsync()ɺDynamicRealm.getInstanceAsync()Λ௥Ճ⭐

    • DynamicRealmObject͕Ͱ΋ٯํ޲ͷؔ࿈Λαϙʔτ • Read Only RealmΛαϙʔτ • ҉߸Խ͞ΕͨRealmͰͷΫϥογϡमਖ਼#4343 • τϥϯβΫγϣϯ֎Ͱͷมߋʹର͢Δྫ֎ϝοηʔδมߋ [email protected]
  3. ٯํ޲ͷؔ࿈αϙʔτ [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).findFirst().owners; owners.size(); ͜ͷΦϒδΣΫτΛdogϑΟʔϧυ͔Β ࢀর͍ͯ͠ΔશͯͷPersonΦϒδΣΫτ
  4. ඇಉظͳRealmΠϯελϯεͷऔಘ [email protected] 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(); } });
  5. Fine-grained Object Notification [email protected] public interface RealmObjectChangeListener<T extends RealmModel> {

    void onChange(T t, ObjectChangeSet changeSet); } public interface ObjectChangeSet { boolean isDeleted(); String[] getChangedFields(); boolean isFieldChanged(String fieldName); }
  6. Google I/Oͱ͸ • Google͕ຖ೥։࠵͍ͯ͠Δ։ൃऀ޲͚ΧϯϑΝϨϯε • Googleຊࣾྡͷ໺֎Πϕϯτձ৔(γϣΞϥΠϯ ΞϯϑΟγΞλʔ)Ͱ։࠵ • ΩʔϊʔτɺηογϣϯɺαϯυϘοΫεɺΦϑΟεΞϫʔɺίʔυϥϘ •

    ࠷ۙ͸AndroidɺػցֶशɺVRத৺(Ϋϥ΢υܥ͸Google Could Next΁ • ηογϣϯ͸ଈ࣌youtubeͰެ։͞ΕΔ • Ҏલ͸ߴֹͳ͓౔࢈͕഑ΒΕ͍͕ͯͨɺ࠷ۙ͸߇͑Δ܏޲ [email protected]
  7. 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ͷϒϩάͰऔΓ্͛·͢ [email protected]
  8. LifecycleObserver [email protected] 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()); } }
  9. ViewModel [email protected] 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(); } }
  10. ViewModel [email protected] @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(...);

    exampleViewModel = ViewModelProviders.of(this) .get(ExampleViewModel.class); exampleViewModel.getPerson() .observe(this, person -> updateViews(person)); }
  11. 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 [email protected]
  12. ݱঢ়ͷKotlinαϙʔτ open class User : RealmObject() { @PrimaryKey var id:

    Long = 0 var name: String = "" var description: Sting? = null } [email protected]
  13. Kotlinαϙʔτͷॆ࣮ • POC: Kotlin Extension Library #4684 ͰΞΠσΟΞืूத • KClass,

    KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺ • @NotNull, @NullableΞϊςʔγϣϯ෇༩ʹΑΔ਌࿨ੑ޲্ • Ϟσϧఆٛʹ࢖ΘΕͨඇNullܕΛ@Requiredѻ͍ʹ [email protected] Any idea?