use of com.mnnyang.gzuclassschedule.data.http.HttpCallback 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() {
}
});
}
Aggregations