Search in sources :

Example 1 with SharedPreferenceCookieManager

use of org.wikipedia.dataclient.SharedPreferenceCookieManager in project apps-android-wikipedia by wikimedia.

the class CookieManagerTypeAdapter method read.

@Override
public SharedPreferenceCookieManager read(JsonReader in) throws IOException {
    Map<String, List<Cookie>> map = new HashMap<>();
    in.beginObject();
    while (in.hasNext()) {
        String key = in.nextName();
        List<Cookie> list = new ArrayList<>();
        map.put(key, list);
        in.beginArray();
        HttpUrl url = HttpUrl.parse(WikiSite.DEFAULT_SCHEME + "://" + key);
        while (in.hasNext()) {
            String str = in.nextString();
            if (url != null) {
                list.add(Cookie.parse(url, str));
            }
        }
        in.endArray();
    }
    in.endObject();
    return new SharedPreferenceCookieManager(map);
}
Also used : Cookie(okhttp3.Cookie) HashMap(java.util.HashMap) SharedPreferenceCookieManager(org.wikipedia.dataclient.SharedPreferenceCookieManager) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HttpUrl(okhttp3.HttpUrl)

Example 2 with SharedPreferenceCookieManager

use of org.wikipedia.dataclient.SharedPreferenceCookieManager in project apps-android-wikipedia by wikimedia.

the class OkHttpConnectionFactory method createClient.

@NonNull
private static OkHttpClient createClient() {
    SharedPreferenceCookieManager cookieManager = SharedPreferenceCookieManager.getInstance();
    // TODO: consider using okhttp3.CookieJar implementation instead of JavaNetCookieJar wrapper
    CookieJar cookieJar = new JavaNetCookieJar(cookieManager);
    return new OkHttpClient.Builder().cookieJar(cookieJar).cache(NET_CACHE).addInterceptor(new HttpLoggingInterceptor().setLevel(Prefs.getRetrofitLogLevel())).addInterceptor(new UnsuccessfulResponseInterceptor()).addInterceptor(new StatusResponseInterceptor(RbSwitch.INSTANCE)).addNetworkInterceptor(new StripMustRevalidateResponseInterceptor()).addInterceptor(new CommonHeaderRequestInterceptor()).addInterceptor(new DefaultMaxStaleRequestInterceptor()).addInterceptor(new CacheControlRequestInterceptor()).addInterceptor(new OfflineCacheInterceptor(SAVE_CACHE)).addInterceptor(new WikipediaZeroResponseInterceptor(WikipediaApp.getInstance().getWikipediaZeroHandler())).addInterceptor(new TestStubInterceptor()).build();
}
Also used : JavaNetCookieJar(okhttp3.JavaNetCookieJar) OkHttpClient(okhttp3.OkHttpClient) SharedPreferenceCookieManager(org.wikipedia.dataclient.SharedPreferenceCookieManager) JavaNetCookieJar(okhttp3.JavaNetCookieJar) CookieJar(okhttp3.CookieJar) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) NonNull(android.support.annotation.NonNull)

Aggregations

SharedPreferenceCookieManager (org.wikipedia.dataclient.SharedPreferenceCookieManager)2 NonNull (android.support.annotation.NonNull)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Cookie (okhttp3.Cookie)1 CookieJar (okhttp3.CookieJar)1 HttpUrl (okhttp3.HttpUrl)1 JavaNetCookieJar (okhttp3.JavaNetCookieJar)1 OkHttpClient (okhttp3.OkHttpClient)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1