オフラインファーストなアプリケーション開発

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
March 09, 2017

 オフラインファーストなアプリケーション開発

DroidKaigi 2017 Day1
16:00-16:50 Room 3

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

March 09, 2017
Tweet

Transcript

  1. 6.

    my@realm.io ϞόΠϧ Billions of Minutes Online (USA) 0 250 500

    750 1000 1250 1500 Jun 2013 Jun 2014 Jun 2015 Desktop Mobile App Mobile Browser
  2. 14.

    my@realm.io Realm Mobile Platform ෳ਺σόΠεͷσʔλϕʔεΛϦΞϧλΠϜಉظ ΦϑϥΠϯͰ΋ϩʔΧϧͷσʔλϕʔε͕࢖͑Δ ΦϑϥΠϯ࣌ͷมߋিಥΛࣗಈղܾ SD SD SD

    SDK SD Object Store Sync
 Server RMP Dashboar d Event Auth System Encryption Layer Rules Engine Data Connect ors Real-time Sync
  3. 18.

    Ϟσϧͷఆٛ my@realm.io public class Task extends RealmObject { @PrimaryKey public

    String id = UUID.randomUUID().toString(); @Required
 public Date createdAt = new Date();
 
 public String text;
 public boolean completed; }
  4. 20.

    σʔλͷૠೖ my@realm.io final Task task = new Task();
 task.text =

    "原稿を書く"; realm.executeTransactionAsync(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) {
 realm.insert(task);
 }
 });
  5. 22.

    σʔλͷߋ৽ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がタップされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.completed = true; }
 });
  6. 23.

    σʔλͷ࡟আ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がスワイプされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.deleteFromRealm(); }
 });
  7. 24.

    มߋ௨஌ my@realm.io completedTasks.addChangeListener(
 new OrderedRealmCollectionChangeListener<RealmResults<Task>>() {
 @Override
 public void onChange(RealmResults<Task>

    tasks,
 OrderedCollectionChangeSet changeSet) {
 // changeSetから、追加/削除/更新があった要素を取得 可能
 }
 });
  8. 27.

    ηοτΞοϓ my@realm.io // in build.gradle buildscript { repositories { jcenter()

    } dependencies { classpath "io.realm:realm-gradle-plugin:3.0.0" } } // in app/build.gradle apply plugin: 'realm-android'
  9. 29.

    σʔλͷߋ৽ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がタップされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.completed = true; }
 });
  10. 30.

    มߋ௨஌ my@realm.io completedTasks.addChangeListener(
 new OrderedRealmCollectionChangeListener<RealmResults<Task>>() {
 @Override
 public void onChange(RealmResults<Task>

    tasks,
 OrderedCollectionChangeSet changeSet) {
 // changeSetから、追加/削除/更新があった要素を取得可能
 }
 });
  11. 32.

    ϩάΠϯ my@realm.io // 認証 SyncCredentials credential = SyncCredentials.usernamePassword(email, password, false);


    SyncUser user = SyncUser.login(credential, RealmTasksApplication.AUTH_URL);
 SyncConfiguration defaultConfig = new SyncConfiguration.Builder(user, RealmTasksApplication.REALM_URL) .build();
 Realm.setDefaultConfiguration(defaultConfig);