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

import android.content.Context;

import com.naijab.nextzytimeline.base.BaseMvpPresenter;
import com.naijab.nextzytimeline.ui.people.model.PeopleManager;
import com.naijab.nextzytimeline.ui.people.model.PeopleModel;

import io.realm.Realm;

public class AddPeopleFragmentPresenter extends BaseMvpPresenter<AddPeopleFragmentInterface.View>
        implements AddPeopleFragmentInterface.Presenter {

    private Realm realm;

    public static AddPeopleFragmentInterface.Presenter create() {
        return new AddPeopleFragmentPresenter();
    }

    @Override
    public void onViewStart() {
        super.onViewStart();
        realm = Realm.getDefaultInstance();
        String name = PeopleManager.getInstance().getPeople().get(4).getName();
        String job = PeopleManager.getInstance().getPeople().get(4).getJob();
        String photos = PeopleManager.getInstance().getPeople().get(4).getPhoto();
        getView().response(name + " " + job + " " + photos);
    }

    @Override
    public void onViewStop() {
        super.onViewStop();
        realm.close();
    }


    @Override
    public void saveIntoRealm(PeopleModel peopleModel, Context context) {
        PeopleManager.getInstance().saveRealm(peopleModel, context, new PeopleManager.onSaveCallBack() {
            @Override
            public void onSaveSuccess(String message) {
                getView().response(message);
            }

            @Override
            public void onSaveError(String message) {
                getView().response(message);
            }
        });
    }

    @Override
    public void deleteAllRealm(Context context) {
        PeopleManager.getInstance().deleteAll(context, new PeopleManager.onDeleteCallBack() {
            @Override
            public void onDeleteSuccess(String message) {
                getView().response(message);
            }

            @Override
            public void onDeleteError(String message) {
                getView().response(message);
            }
        });
    }
}

@@ -723,19 +723,15 @@
     
-Str
 in
-g name
+t num
  = P
@@ -773,245 +773,65 @@
 e().
-get(4).getName();%0A        String job = PeopleManager.getInstance().getPeople().get(4).getJob();%0A        String photos = PeopleManager.getInstance().getPeople().get(4).getPhoto();%0A        getView().response(name + %22 %22 + job + %22 %22 + photos
+size();%0A        getView().response(%22Size of data: %22 + num
 );%0A 
@@ -1248,32 +1248,78 @@
 ponse(message);%0A
+                getView().saveIsFinish(true);%0A
             %7D%0A%0A 

Edit People Presenter