title: How to wrap observable inside another observable in RxJava?
body: <p>I want to wrap retrofit api call in another method where I can additionally show/hide loader, check for network etc. As my api returns observable, the way I ended up is below: </p>
  
  <pre><code>private &lt;T&gt; Observable&lt;T&gt; request(final Observable&lt;T&gt; apiCall, final ViewManager viewManager) {
      return Observable.create(new Action1&lt;Emitter&lt;T&gt;&gt;() {
          @Override
          public void call(final Emitter&lt;T&gt; emitter) {
              if (!NetworkUtils.isConnected(context)) {
                  emitter.onError(new ConnectException("network not connected"));
                  return;
              }
              viewManager.showLoader();
              apiCall.subscribeOn(Schedulers.io())
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribe(new Observer&lt;T&gt;() {
                          @Override
                          public void onCompleted() {
                              viewManager.hideLoader();
                              emitter.onCompleted();
                          }
  
                          @Override
                          public void onError(Throwable e) {
                              viewManager.hideLoader();
                              emitter.onError(e);
                          }
  
                          @Override
                          public void onNext(T response) {
                              emitter.onNext(response);
                          }
                      });
          }
      }, Emitter.BackpressureMode.BUFFER);
  }
  </code></pre>
  
  <p>Is this a standard way of dealing with the problem? How do you wrap an observable inside another observable? Can anyone guide?</p>