@@ -0,0 +1,2017 @@
+package cgeo.geocaching.utils;%0A%0Aimport okhttp3.Call;%0Aimport okhttp3.Callback;%0Aimport okhttp3.OkHttpClient;%0Aimport okhttp3.Request;%0Aimport okhttp3.Response;%0Aimport rx.Single;%0Aimport rx.Single.OnSubscribe;%0Aimport rx.SingleSubscriber;%0Aimport rx.functions.Action0;%0Aimport rx.subscriptions.Subscriptions;%0A%0Aimport java.io.IOException;%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0Apublic class RxOkHttpUtils %7B%0A%0A    private RxOkHttpUtils() %7B%0A        // Do not instantiate%0A    %7D%0A%0A    /**%0A     * Create a Single for running a cancellable request.%0A     *%0A     * @param client the client to use for this request%0A     * @param request the request%0A     * @return a Single containing the response or an IOException%0A     */%0A    public static Single%3CResponse%3E request(final OkHttpClient client, final Request request) %7B%0A        return Single.create(new OnSubscribe%3CResponse%3E() %7B%0A            @Override%0A            public void call(final SingleSubscriber%3C? super Response%3E singleSubscriber) %7B%0A                final Call call = client.newCall(request);%0A                final AtomicBoolean completed = new AtomicBoolean(false);%0A                singleSubscriber.add(Subscriptions.create(new Action0() %7B%0A                    @Override%0A                    public void call() %7B%0A                        if (!completed.get()) %7B%0A                            call.cancel();%0A                        %7D%0A                    %7D%0A                %7D));%0A                call.enqueue(new Callback() %7B%0A                    @Override%0A                    public void onFailure(final Call call, final IOException e) %7B%0A                        completed.set(true);%0A                        singleSubscriber.onError(e);%0A                    %7D%0A%0A                    @Override%0A                    public void onResponse(final Call call, final Response response) throws IOException %7B%0A                        completed.set(true);%0A                        singleSubscriber.onSuccess(response);%0A                    %7D%0A                %7D);%0A            %7D%0A        %7D);%0A    %7D%0A%0A%7D%0A

Add utility class to run a OkHttp requests as a RxJava Single