How to use flipper with volley?

126 views Asked by At

I want to add flipper support to my volley network calls since some of the legacy calls are still written in volley. I was trying to implement this solution but couldn't make it work.

Class OkHttpStack -

public class OkHttpStackApi extends HurlStack {
    private final OkHttpClient client;

    public OkHttpStackApi() {
        this(new OkHttpClient());
    }

    public OkHttpStackApi(OkHttpClient client) {
        if (client == null) {
            throw new NullPointerException("Client must not be null.");
        }
        this.client = client;
    }

    @Override
    protected HttpURLConnection createConnection(URL url) throws IOException {
        return new OkUrlFactory(client).open(url);
    }
}

CustomVolleyRequestQueue -

public class CustomVolleyRequestQueue {

    private static CustomVolleyRequestQueue mInstance;
    private static Context mCtx;
    private RequestQueue mRequestQueue;

    private CustomVolleyRequestQueue(Context context) {
        mCtx = context;
        mRequestQueue = getRequestQueue();
    }

    public static synchronized CustomVolleyRequestQueue getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new CustomVolleyRequestQueue(context);
        }
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {

            mRequestQueue = Volley.newRequestQueue(mCtx, new OkHttpStackApi());
            // Don't forget to start the volley request queue
            mRequestQueue.start();
        }
        return mRequestQueue;
    }
}

I'm not able to figure out anything since I have always been working with Retrofit and was easily able to add support to it.

0

There are 0 answers