Search in sources :

Example 1 with DownCourseWrapper

use of com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper in project GzuClassSchedule by mnnyang.

the class HomePresenter method downShare.

/**
 * 下载解析分享
 */
@Override
public void downShare(String url) {
    if (TextUtils.isEmpty(url)) {
        mView.showMassage("分享为空");
        return;
    }
    mView.showLoading("导入中");
    new MyHttpUtils().downShare(url, new HttpCallback<DownCourseWrapper>() {

        @Override
        public void onSuccess(DownCourseWrapper downCourseWrapper) {
            if (mView == null) {
                // view被销毁
                return;
            }
            mView.stopLoading();
            if (downCourseWrapper == null || downCourseWrapper.getData() == null) {
                mView.showMassage("导入数据为空");
                return;
            }
            long newGroupId = writeShare(downCourseWrapper.getData());
            // 通知更新
            // 切换到当前课表
            Preferences.putLong(app.mContext.getString(R.string.app_preference_current_cs_name_id), newGroupId);
            mView.showMassage("导入成功!");
            EventBus.getDefault().post(new CourseDataChangeEvent());
            mView.cloudToLocalSucceed();
        }

        @Override
        public void onFail(String errMsg) {
            if (mView == null) {
                // view被销毁
                return;
            }
            mView.stopLoading();
            mView.showMassage(errMsg);
        }
    });
}
Also used : MyHttpUtils(com.mnnyang.gzuclassschedule.data.http.MyHttpUtils) CourseDataChangeEvent(com.mnnyang.gzuclassschedule.utils.event.CourseDataChangeEvent) DownCourseWrapper(com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)

Example 2 with DownCourseWrapper

use of com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper in project GzuClassSchedule by mnnyang.

the class HomePresenter method downCourse.

/**
 * 下载course
 */
@Override
public void downCourse() {
    if (TextUtils.isEmpty(Cache.instance().getEmail())) {
        mView.pleaseLoginIn();
        return;
    }
    mView.showLoading("同步中");
    new MyHttpUtils().downCourse(new HttpCallback<DownCourseWrapper>() {

        @Override
        public void onSuccess(DownCourseWrapper bean) {
            if (mView == null) {
                // view被销毁
                return;
            }
            mView.stopLoading();
            if (bean != null) {
                if (bean.getCode() == 1) {
                    overWriteLocal(bean.getData());
                    mView.stopLoading();
                    EventBus.getDefault().post(new CourseDataChangeEvent());
                    mView.cloudToLocalSucceed();
                } else {
                    mView.showMassage("同步失败:" + bean.getMsg());
                }
            } else {
                mView.showMassage("同步失败");
            }
        }

        @Override
        public void onFail(String errMsg) {
            if (mView == null) {
                // view被销毁
                return;
            }
            mView.stopLoading();
            mView.showMassage(errMsg);
        }
    });
}
Also used : MyHttpUtils(com.mnnyang.gzuclassschedule.data.http.MyHttpUtils) CourseDataChangeEvent(com.mnnyang.gzuclassschedule.utils.event.CourseDataChangeEvent) DownCourseWrapper(com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)

Aggregations

DownCourseWrapper (com.mnnyang.gzuclassschedule.data.beanv2.DownCourseWrapper)2 MyHttpUtils (com.mnnyang.gzuclassschedule.data.http.MyHttpUtils)2 CourseDataChangeEvent (com.mnnyang.gzuclassschedule.utils.event.CourseDataChangeEvent)2