2

In my project, I'm using MVP design pattern, RxJava,RxAndroid and Retrofit for consuming the API calls. Currently I am looking for solutions for trying to display an upload progress while I'm sending a picture. I have seen a couple of possible implementations, but I am afraid they do not fit within my implementation. Here's how I consume the API call with the libraries I mentioned:

Subscription subscription = mApiService.modVideoFromVideoController(userHash, videoId, publicVideo, rate)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ModifyVideoResponse>() {
                    @Override
                    public void onCompleted() {
                        Log.d(TAG, "modVideo onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, e.getMessage());
                        Crashlytics.logException(e);
                    }

                    @Override
                    public void onNext(ModifyVideoResponse modifyVideoResponse) {
                        mVideosPresenter.onVideoEdited(position, publicVideo);
                    }
                });
        mCompositeSubscription.add(subscription);

Is there a way to achieve this?

funkycookie
  • 226
  • 2
  • 16
  • A solution would be to emit progress updates via `onNext()` - does your API support this approach? – Egor Oct 11 '16 at 15:12
  • @Egor no, it does not. Are there any other possible solutions that would not involve the backend? – funkycookie Oct 11 '16 at 15:54
  • 1
    http://stackoverflow.com/questions/33338181/is-it-possible-to-show-progress-bar-when-upload-image-via-retrofit-2/33384551#33384551 – R. Zagórski Oct 12 '16 at 07:24

1 Answers1

0

The best way to achieve this is use Side Effects methods.

For progress view hide/show:

Bind this two events with doOnSubscribe() and doFinally(). This are two operators, so we can logically bind them with RxCall.

doOnSubscribe() will be called, when you are attached to Subscriber.

and

doFinaly() will be called at the end. In any cases Success or Error.

Milind Mevada
  • 3,145
  • 1
  • 14
  • 22