use of rx.Subscription in project GeekNews by codeestX.
the class MainPresenter method registerEvent.
void registerEvent() {
Subscription rxSubscription = RxBus.getDefault().toObservable(NightModeEvent.class).compose(RxUtil.<NightModeEvent>rxSchedulerHelper()).map(new Func1<NightModeEvent, Boolean>() {
@Override
public Boolean call(NightModeEvent nightModeEvent) {
return nightModeEvent.getNightMode();
}
}).subscribe(new CommonSubscriber<Boolean>(mView, "切换模式失败ヽ(≧Д≦)ノ") {
@Override
public void onNext(Boolean aBoolean) {
mView.useNightMode(aBoolean);
}
});
addSubscrebe(rxSubscription);
}
use of rx.Subscription in project GeekNews by codeestX.
the class MainPresenter method checkVersion.
@Override
public void checkVersion(final String currentVersion) {
Subscription rxSubscription = mRetrofitHelper.fetchVersionInfo().compose(RxUtil.<MyHttpResponse<VersionBean>>rxSchedulerHelper()).compose(RxUtil.<VersionBean>handleMyResult()).filter(new Func1<VersionBean, Boolean>() {
@Override
public Boolean call(VersionBean versionBean) {
return Integer.valueOf(currentVersion.replace(".", "")) < Integer.valueOf(versionBean.getCode().replace(".", ""));
}
}).map(new Func1<VersionBean, String>() {
@Override
public String call(VersionBean bean) {
StringBuilder content = new StringBuilder("版本号: v");
content.append(bean.getCode());
content.append("\r\n");
content.append("版本大小: ");
content.append(bean.getSize());
content.append("\r\n");
content.append("更新内容:\r\n");
content.append(bean.getDes().replace("\\r\\n", "\r\n"));
return content.toString();
}
}).subscribe(new CommonSubscriber<String>(mView) {
@Override
public void onNext(String s) {
mView.showUpdateDialog(s);
}
});
addSubscrebe(rxSubscription);
}
use of rx.Subscription in project GeekNews by codeestX.
the class MainPresenter method checkPermissions.
@Override
public void checkPermissions(RxPermissions rxPermissions) {
Subscription rxSubscription = rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean granted) {
if (granted) {
mView.startDownloadService();
} else {
mView.showError("下载应用需要文件写入权限哦~");
}
}
});
addSubscrebe(rxSubscription);
}
use of rx.Subscription in project GeekNews by codeestX.
the class NodePresenter method getTopInfo.
@Override
public void getTopInfo(String node_name) {
Subscription rxSubscription = mRetrofitHelper.fetchNodeInfo(node_name).compose(RxUtil.<NodeBean>rxSchedulerHelper()).subscribe(new CommonSubscriber<NodeBean>(mView) {
@Override
public void onNext(NodeBean nodeBean) {
mView.showTopInfo(nodeBean);
}
});
addSubscrebe(rxSubscription);
}
use of rx.Subscription in project GeekNews by codeestX.
the class NodePresenter method getContent.
@Override
public void getContent(String node_name) {
Subscription rxSubscription = mRetrofitHelper.fetchTopicList(node_name).compose(RxUtil.<List<NodeListBean>>rxSchedulerHelper()).subscribe(new CommonSubscriber<List<NodeListBean>>(mView) {
@Override
public void onNext(List<NodeListBean> nodeListBeen) {
mView.showContent(nodeListBeen);
}
});
addSubscrebe(rxSubscription);
}
Aggregations