ExerciseModel.java 8.9 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 ExerciseModel implements ICommonModel {

    private MyServer mServers;

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

        if (api == 1 && intent == 1)
            getCatalogLst(commonView, api, intent, params);

        if (api == 2 && intent == 1)
            GetQuestionBankLst(commonView, api, intent, params);

        if (api == 3 && intent == 1)
            GetSimExerciseInfo(commonView, api, intent, params);

        if (api == 4 && intent == 1)
            GetSimExamQuestions(commonView, api, intent, params);

        if (api == 4 && intent == 2)
            InsertWrongQuestion(commonView, api, intent, params);

        if (api == 5 && intent == 1)
            GetSimExamReportInfo(commonView, api, intent, params);

        if (api == 6 && intent == 1)
            GetWrongCatalogLst(commonView, api, intent, params);

        if (api == 7 && intent == 1)
            GetWrongQuestionsByCatalogOid(commonView, api, intent, params);

        if (api == 7 && intent == 2)
            RemoveWrongQuestion(commonView, api, intent, params);

        if (api == 8 && intent == 1)
            GetRandomQuestions(commonView, api, intent, params);

        if (api == 9 && intent == 1)
            DeleteExamRecordInfo(commonView, api, intent, params);

    }

    private void DeleteExamRecordInfo(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 9 && intent == 1)
            mServers.DeleteExamRecordInfo(params[0])
                    .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 RemoveWrongQuestion(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 7 && intent == 2)
            mServers.RemoveWrongQuestion(params[0], params[1], Integer.valueOf(params[2]), params[3])
                    .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 GetRandomQuestions(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 8 && intent == 1)
            mServers.GetRandomQuestions(params[0], Integer.valueOf(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, intent);
                        }

                    });
    }

    private void GetWrongQuestionsByCatalogOid(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 7 && intent == 1)
            mServers.GetWrongQuestionsByCatalogOid(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 GetWrongCatalogLst(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 6 && intent == 1)
            mServers.GetWrongCatalogLst(params[0])
                    .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 InsertWrongQuestion(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 4 && intent == 2)
            mServers.InsertWrongQuestion(params[0], params[1], Integer.valueOf(params[2]), params[3])
                    .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 GetSimExamReportInfo(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 5 && intent == 1)
            mServers.GetSimExamReportInfo(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, intent);
                        }

                    });
    }

    private void GetSimExamQuestions(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 4 && intent == 1)
            mServers.GetSimExamQuestions(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, intent);
                        }

                    });
    }

    private void GetSimExerciseInfo(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 3 && intent == 1)
            mServers.GetSimExerciseInfo(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, intent);
                        }

                    });
    }

    private void GetQuestionBankLst(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 2 && intent == 1)
            mServers.GetQuestionBankLst(Integer.valueOf(params[0]))
                    .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 getCatalogLst(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 1 && intent == 1)
            mServers.getCatalogLst()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, intent);
                        }

                    });
    }
}