package com.sxyz.rfid.presenter.imp;


import androidx.appcompat.app.AppCompatActivity;

import com.sxyz.rfid.presenter.ILoginPresenter;
import com.sxyz.rfid.presenter.model.LoginModel;
import com.sxyz.rfid.presenter.view.ILoginView;
import com.sxyz.rfid.retrofit.callback.Object1Observer;
import com.sxyz.rfid.retrofit.config.Transformer;
import com.sxyz.rfid.retrofit.http.RetrofitUtils;
import com.sxyz.rfid.ui.login.bean.UserBean;
import com.sxyz.rfid.widgets.CustomProgressDialog;

/**
 * @Description: 登录
 * @Author: wuchunyuan（York）
 * @CreateDate: 2020/4/4 14:31
 * @UpdateUser: wuchunyuan（York）
 * @UpdateDate: 2020/4/4 14:31
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class LoginPresenterImpl implements ILoginPresenter {

    private ILoginView view;

    public LoginPresenterImpl(ILoginView view) {
        this.view = view;
    }

    @Override
    public void doLogin(AppCompatActivity activity, UserBean mUserBean) {
        RetrofitUtils.getInstance().getApiService().getLogin(mUserBean)
                .compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<LoginModel>() {

                    @Override
                    public void onSuccess(LoginModel loginModel) {
                        view.loginSuccess(loginModel);
                    }

                    @Override
                    public void onFailed(Throwable throwable) {
                    }
                });
    }
}
