AccountModel.java 4.6 KB
package com.hh.xuetubao.model;

import com.hh.xuetubao.MyServer;
import com.hh.xuetubao.Utils.BaseObsever;
import com.hh.xuetubao.Utils.HttpUtils;
import com.hh.xuetubao.Utils.NetConfig;
import com.hh.xuetubao.mvp.ICommonModel;
import com.hh.xuetubao.mvp.ICommonView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class AccountModel implements ICommonModel {

    private MyServer mServers;

    @Override
    public void getModel(ICommonView commonView, int api, int intent, String... params) {
        mServers = HttpUtils.getInstance().getServer(NetConfig.accountUrl);

        if (api == 1 && intent == 1) {  // - > 验证码
            sendValidateCode(commonView, api, intent, params);
        }
        if (api == 1 && intent == 2) {  // - > 验证码登录
            mobileLogin(commonView, api, intent, params);
        }
        if (api == 1 && intent == 3) {  // - > 微信绑定手机号
            bd_phone(commonView, api, intent, params);
        }
        if (api == 1 && intent == 4) {  // - > 机构登录
            jg_login(commonView, api, intent, params);
        }
        if(api == 1 && intent == 5){  // 忘记密码
            forget_pas(commonView, api, intent, params);
        }

    }

    /*  获取验证码 */
    private void sendValidateCode(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 1 && intent == 1)
            mServers.sendValidateCode(params[0], Integer.valueOf(params[1]))
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, intent);
                        }

                    });
    }

    /* 验证码登录 */
    private void mobileLogin(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 1 && intent == 2)
            mServers.mobileLogin(params[0], params[1],Integer.valueOf(params[2]))
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, intent);
                        }

                    });
    }

    /*  微信绑定手机号 */
    private void bd_phone(final ICommonView commonView, final int api, final int tag, String... params) {
        if (api == 1 && tag == 3) {
            mServers.bd_phone(params[0], params[1], params[2])
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, tag);
                        }
                    });
        }
    }

    /*  机构登录 */
    private void jg_login(final ICommonView commonView, final int api, final int tag, String... params) {
        if (api == 1 && tag == 4) {
            mServers.AccountLogin(params[0], params[1])
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, tag);
                        }
                    });
        }
    }

    /* 忘记密码 */
    private void forget_pas(final ICommonView commonView, final int api, final int tag, String... params) {
        if (api == 1 && tag == 5) {
            mServers.Forget_Pas(params[0], params[1], params[2])
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, tag);
                        }
                    });
        }
    }

}