package com.naijab.nextzytimeline.ui.people.model;

import io.realm.Realm;
import io.realm.RealmResults;

public class PeopleManager {

    private static PeopleManager peopleManager;
    private Realm realm = Realm.getDefaultInstance();

    public static PeopleManager getInstance() {
        if (peopleManager == null) {
            peopleManager = new PeopleManager();
        }
        return peopleManager;
    }

    public Realm getRealm(){
        return realm;
    }

    public RealmResults<PeopleModel> getPeople() {
        return realm.where(PeopleModel.class)
                .findAll();
    }

    public PeopleModel getPeople(String id) {
        return realm.where(PeopleModel.class).equalTo("id", id).findFirst();
    }

}

@@ -45,16 +45,106 @@
 model;%0A%0A
+import android.content.Context;%0A%0Aimport com.naijab.nextzytimeline.utility.StringUtility;%0A%0A
 import i
@@ -158,16 +158,16 @@
 .Realm;%0A
-
 import i
@@ -320,16 +320,91 @@
 tance();
+%0A    private RealmResults%3CPeopleModel%3E resultRealm;%0A    private int id = 0;
 %0A%0A    pu
@@ -810,24 +810,24 @@
 tring id) %7B%0A
-
         retu
@@ -896,12 +896,1527 @@
 );%0A    %7D
+%0A    public void saveRealm(final PeopleModel peopleModel,%0A                          final Context context,%0A                          final SaveCallback callBack)%7B%0A%0A        resultRealm = realm.where(PeopleModel.class)%0A                .findAll();%0A%0A        id = resultRealm.size() + 1;%0A%0A        Realm realm = Realm.getDefaultInstance();%0A        realm.executeTransactionAsync(new Realm.Transaction() %7B%0A            @Override%0A            public void execute(Realm bgRealm) %7B%0A%0A                PeopleModel people = bgRealm.createObject(PeopleModel.class, id);%0A                people.setName(peopleModel.getName());%0A                people.setBirthday(peopleModel.getBirthday());%0A                people.setJobstart(peopleModel.getJobstart());%0A                people.setJob(peopleModel.getJob());%0A                people.setGame(peopleModel.getGame());%0A                people.setSmartphone(peopleModel.getSmartphone());%0A                people.setPhoto(peopleModel.getPhoto());%0A            %7D%0A        %7D, new Realm.Transaction.OnSuccess() %7B%0A            @Override%0A            public void onSuccess() %7B%0A                callBack.onSaveSuccess(StringUtility.getSaveSuccess(context));%0A            %7D%0A        %7D, new Realm.Transaction.OnError() %7B%0A            @Override%0A            public void onError(Throwable error) %7B%0A                callBack.onSaveError(error.getMessage());%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public interface SaveCallback %7B%0A        void onSaveSuccess(String message);%0A        void onSaveError(String message);%0A    %7D
 %0A%0A%7D%0A

Edit PeopleManager saveRealm