package ai.pai.lensman.login;

import android.content.Context;

import ai.pai.lensman.base.BaseInteractor;
import ai.pai.lensman.db.Preferences;

/**
 * Created by chengzhenyu on 2016/8/11.
 */
public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.InteractorListener<String> {

    private Context context;
    private LoginContract.View view;
    private LoginInteractor interactor;

    public LoginPresenter(Context context,LoginContract.View view){
        this.view = view;
        this.context = context;
    }

    @Override
    public void login(String userName, String pwd) {
        view.showProgressView();
        interactor = new LoginInteractor(userName,pwd,this);
        interactor.startJob();
    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {
        if(interactor!=null){
            interactor.cancelJob();
        }
    }


    @Override
    public void onInteractSuccess(String result) {
        view.hideProgressView();
        Preferences.getInstance(context).setLensManId(result);
        view.jumpMain();
    }

    @Override
    public void onInteractFail(String errorMsg) {
        view.hideProgressView();
        view.showLoginHint(errorMsg);
    }

}
