I am using Rxjava in conjunction with Retrofit. I want to update status of that image as completed in android database. So the real question is what if second image is uploaded first and after that first is uploaded?. Is onNext() is called sequentially as a images in queue gets executed or the images are uploaded in asynchronous manner. I want to know the required solution for this approach. My code so far is as follows.
tisImageEntities = SelectQuery.getImageByStatus(mContext);
tisImageCount = 0;
Observable.fromIterable(tisImageEntities)
.map(tisImageEntity -> new TisImageUploadEntity(tisImageEntity.projectId,
tisImageEntity.imagePath.substring(tisImageEntity.imagePath.lastIndexOf("/") + 1), "fit.jpg",
tisImageEntity.detail, tisImageEntity.imageType,
getBase64EncodedString(tisImageEntity.imagePath)))
.filter(tisImageUploadEntity -> null!=tisImageUploadEntity.Content)
.flatMap(tisImageUploadEntity -> hitachiRetrofitApi.uploadTisImages(tisImageUploadEntity))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<ResponseBody>() {
@Override
public void onNext(ResponseBody responseBody) {
try {
String response = responseBody.string().toString();
UpdateQuery.updateTisImageStatus(mContext,tisImageEntities.get(tisImageCount).projectId); // here is image staatus updated correctly??
tisImageCount++;
Log.d(TAG, "on next for update entity" + response);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
cancleProgressDialog();
}
@Override
public void onComplete() {
Log.d(TAG, "on complete for update entity");
cancleProgressDialog();
}
});
So in onNext() the update query right? and is it updating the status sequentially? If not then please correct me