How to download a file with progress updates using reactive extensions on Android
<p>I am currently programming an app that needs to do lots combining of api-calls and is therefore using rxjava for the first time since it seems more convenient for handling async events and the Android lifecycles. </p>

<p>However the app also needs sometimes to load static datasets packaged in a zip archive. I try to use rx for this operation as well for consistency and it works well, but I dont really grasp how to subscribe to progress-events to update the UI with the file download progress. </p>

<p>This is the code I am using now for downloading a file which makes use of the okhttp-library:</p>

<pre><code>downloadService.downloadFile(filename)
    .flatMap(new Func1&lt;Response&lt;ResponseBody&gt;, Observable&lt;File&gt;&gt;()
    {
        @Override
        public Observable&lt;File&gt; call(final Response&lt;ResponseBody&gt; responseBodyResponse)
        {
            return Observable.create(new Observable.OnSubscribe&lt;File&gt;()
            {
                @Override
                public void call(Subscriber&lt;? super File&gt; subscriber)
                {
                    try
                    {
                        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsoluteFile(), filename);
                        BufferedSink sink = Okio.buffer(Okio.sink(file));
                        sink.writeAll(responseBodyResponse.body().source());
                        sink.close();
                        subscriber.onNext(file);
                        subscriber.onCompleted();
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                        subscriber.onError(e);
                    }
                }
            });
        }
    })
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Observer&lt;File&gt;()
    {
        @Override
        public void onCompleted()
        {
            Log.d("downloadZipFile", "onCompleted");
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
            Log.d("downloadZipFile", "Error " + e.getMessage());
        }

        @Override
        public void onNext(File file) {
            Log.d("downloadZipFile", "File downloaded to " + file.getAbsolutePath());
        }
    });
</code></pre>

<p>What is a good way of implementing a subscription to progress events?</p>