我正在尝试获取一个List
文档,然后尝试将每个文档发送到服务器并从数据库和电话中删除。问题是它看起来永远不会到达. subscribe
方法了Fragment
,就好像被卡在了。flatMap
执行sendToServer(..)
方法。请问有什么帮助吗?
分段:
disposable = mViewModel.singleSend()
.subscribe(sent -> DialogUtils.showMessage(R.string.success)
, t -> DialogUtils.showMessage(R.string.error_binding_data)
);
视图模型:
public Single<Boolean> singleSend() {
return sendMediaAttachement()
.map(list -> !list.contains(false))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public @NonNull Single<List<Boolean>> sendMediaAttachement() {
return mRepository.getAttachedDocs(getMantenValue().getID())
.concatMap(docs -> Flowable.fromIterable(docs))
.flatMap(doc -> mRepository.sendToServer(doc, getFileFromAttachedDoc(doc)),
(doc, wsResult) -> {
if (wsResult.isSuccessful()) deleteDoc(doc);
return wsResult.isSuccessful();
})
.toList();
}
public void deleteDoc(DocumentoAdjunto doc) {
addDisposable(mRepository.delete(doc)
.subscribe(deleted -> {
if (deleted)
FileUtils.deleteFile(getFileFromAttachedDoc(doc)); //returns void
}, t -> getToastMessageInteger().setValue(R.string.file_not_deleted)));
}
存储库:
public @NonNull Flowable<WSResult> sendToServer(DocumentoAdjunto doc, File file) {
return mRemoteDataSource.uploadFile(doc, file)
.map(this::parse)
.toFlowable()
.doOnError(Timber::e)
.subscribeOn(Schedulers.io());
}
public Single<Boolean> delete(DocumentoAdjunto doc) {
return mLocalDataSource.delete(doc)
.doOnError(Timber::e)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}