use of com.mnnyang.gzuclassschedule.data.http.MyHttpUtils in project GzuClassSchedule by mnnyang.
the class HomePresenter method loadUserInfo.
/**
* 加载用户信息
*/
@Override
public void loadUserInfo() {
if (TextUtils.isEmpty(Cache.instance().getEmail())) {
if (mView == null) {
// 检查到view已经被销毁
return;
}
mView.noSignInPage();
return;
}
new MyHttpUtils().userInfo(new HttpCallback<UserWrapper>() {
@Override
public void onSuccess(UserWrapper userWrapper) {
if (mView == null) {
// view被销毁
return;
}
if (userWrapper != null) {
if (userWrapper.getCode() == 1) {
Cache.instance().setUser(userWrapper.getData());
mView.signInPage(userWrapper.getData());
} else if (userWrapper.getCode() == 3) {
Cache.instance().setEmail("");
mView.noSignInPage();
LogUtil.e(this, userWrapper.toString());
}
}
}
@Override
public void onFail(String errMsg) {
if (mView == null) {
// view被销毁
return;
}
LogUtil.e(this, errMsg);
}
});
}
use of com.mnnyang.gzuclassschedule.data.http.MyHttpUtils 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);
}
});
}
use of com.mnnyang.gzuclassschedule.data.http.MyHttpUtils in project GzuClassSchedule by mnnyang.
the class SignPresenter method signIn.
@Override
public void signIn(String email, String password) {
if (mView == null) {
// 检查到view已经被销毁
return;
}
if (isOkOfVerifyInput(email, password)) {
return;
}
mView.showLoading("登录中");
email = email.trim();
password = password.trim();
new MyHttpUtils().login(email, password, new HttpCallback<BaseBean>() {
@Override
public void onSuccess(BaseBean baseBean) {
if (mView == null) {
// 检查到view已经被销毁
return;
}
mView.stopLoading();
if (baseBean != null) {
if (baseBean.getCode() == 1) {
mView.signInSucceed(baseBean);
} else {
mView.signInFailed(baseBean.getMsg());
}
} else {
mView.showMassage("返回的数据有误!");
}
}
@Override
public void onFail(String errMsg) {
if (mView == null) {
// 检查到view已经被销毁
return;
}
mView.stopLoading();
mView.showMassage(errMsg);
}
});
}
use of com.mnnyang.gzuclassschedule.data.http.MyHttpUtils in project GzuClassSchedule by mnnyang.
the class HomePresenter method createShare.
/**
* 建立分享
*/
@Override
public void createShare(final long groupId, final String groupName) {
mView.showLoading("建立分享中");
Observable.create(new ObservableOnSubscribe<ShareBean>() {
@Override
public void subscribe(final ObservableEmitter<ShareBean> emitter) throws Exception {
List<CourseV2> list = Cache.instance().getCourseV2Dao().queryBuilder().where(CourseV2Dao.Properties.CouCgId.eq(groupId)).where(CourseV2Dao.Properties.CouDeleted.eq(false)).list();
if (list != null && !list.isEmpty()) {
String json = buildJsonOfGroups(list, groupName);
MyHttpUtils utils = new MyHttpUtils();
utils.uploadShare(json, new HttpCallback<ShareBean>() {
@Override
public void onSuccess(ShareBean bean) {
emitter.onNext(bean);
}
@Override
public void onFail(String errMsg) {
emitter.onError(new Exception(errMsg));
}
});
} else {
emitter.onError(new Exception("该课表没有课程"));
}
}
}).map(new Function<ShareBean, Bitmap>() {
@Override
public Bitmap apply(ShareBean bean) throws Exception {
if (bean == null || TextUtils.isEmpty(bean.getData())) {
return null;
}
Bitmap logo = BitmapFactory.decodeResource(Cache.instance().getContext().getResources(), R.mipmap.ic_launcher_round);
final int width = ScreenUtils.dp2px(150);
String content = Url.URL_SHARE + "?id=" + bean.getData();
return new QRCode().makeQRCodeImage(content, width, width, logo);
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Bitmap>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Bitmap bitmap) {
if (!mView.isActive()) {
return;
}
mView.stopLoading();
if (bitmap == null) {
mView.showMassage("分享失败!");
return;
}
mView.createQRCodeSucceed(bitmap);
}
@Override
public void onError(Throwable e) {
if (!mView.isActive()) {
return;
}
mView.stopLoading();
mView.showMassage(e.getMessage());
}
@Override
public void onComplete() {
}
});
}
use of com.mnnyang.gzuclassschedule.data.http.MyHttpUtils in project GzuClassSchedule by mnnyang.
the class HomePresenter method uploadCourse.
/**
* 上传
*/
@Override
public void uploadCourse() {
if (TextUtils.isEmpty(Cache.instance().getEmail())) {
mView.pleaseLoginIn();
return;
}
mView.showLoading("同步中");
JSONObject result = buildJsonOfAllCourse();
MyHttpUtils utils = new MyHttpUtils();
utils.uploadCourse(result.toString(), new HttpCallback<BaseBean>() {
@Override
public void onSuccess(BaseBean baseBean) {
if (mView == null) {
// view被销毁
return;
}
mView.stopLoading();
if (baseBean != null) {
if (baseBean.getCode() == 1) {
mView.showMassage("同步成功");
} else {
mView.showMassage("同步失败:" + baseBean.getMsg());
}
} else {
mView.showMassage("同步失败");
}
}
@Override
public void onFail(String errMsg) {
if (mView == null) {
// view被销毁
return;
}
mView.stopLoading();
mView.showMassage(errMsg);
}
});
}
Aggregations