LearnModel.java 11.3 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 LearnModel implements ICommonModel {

    private MyServer mServers;

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

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

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

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

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

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

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

        if (api == 4 && intent == 3)
            GetLearningDurationChartData(commonView, api, intent, params);

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

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

    }

    private void InsertLearningProgress(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 6 && intent == 1)
            mServers.InsertLearningProgress(params[0], params[1], params[2], params[3], params[4], Integer.valueOf(params[5]), Integer.valueOf(params[6]), Integer.valueOf(params[7]))
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, intent);
                        }

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

    private void GetHotLessonLst(final ICommonView commonView, final int api, final int intent, String... params) {
        if (api == 5 && intent == 1)
            mServers.GetHotLessonLst(4)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObsever() {
                        @Override
                        public void onNext(Object value) {
                            super.onNext(value);
                            commonView.getData(value, api, intent);
                        }

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });

    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });

    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }

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

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            commonView.onError(e, api);
                        }

                        @Override
                        public void onComplete() {
                            super.onComplete();
                            commonView.onComplete(api);
                        }
                    });
    }
}