package com.stu.assistant.presenter;


import com.stu.assistant.activity.RegisterActivity;
import com.stu.assistant.base.BasePresenter;
import com.stu.assistant.bean.UserInfoBean;
import com.stu.assistant.uitls.MyToast;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class RegisterPresenter extends BasePresenter {
    RegisterActivity mActivity;

    public RegisterPresenter(RegisterActivity mActivity) {
        this.mActivity = mActivity;
    }

    public void registerUser(UserInfoBean userBean, OnRegisterListener listener) {
        mActivity.showProDialog("正在注册....");
        userBean.signUp(new SaveListener<UserInfoBean>() {
            @Override
            public void done(UserInfoBean objectId, BmobException e) {
                mActivity.dismissProDialog();
                if (e == null) {
                    MyToast.show("注册成功");
                    listener.registerListener(userBean);
                } else {
                    MyToast.show("注册失败:" + e.getMessage());
                }
            }
        });
    }

    public interface OnRegisterListener {
        void registerListener(UserInfoBean userInfoBean);
    }
}
