Search in sources :

Example 26 with Cookie

use of com.firenio.codec.http11.Cookie in project DevRing by LJYcoder.

the class SerializableCookie method decode.

public Cookie decode(String encodedCookie) {
    byte[] bytes = hexStringToByteArray(encodedCookie);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    Cookie cookie = null;
    ObjectInputStream objectInputStream = null;
    try {
        objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableCookie) objectInputStream.readObject()).cookie;
    } catch (IOException e) {
        Log.d(TAG, "IOException in decodeCookie", e);
    } catch (ClassNotFoundException e) {
        Log.d(TAG, "ClassNotFoundException in decodeCookie", e);
    } finally {
        if (objectInputStream != null) {
            try {
                objectInputStream.close();
            } catch (IOException e) {
                Log.d(TAG, "Stream not closed in decodeCookie", e);
            }
        }
    }
    return cookie;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 27 with Cookie

use of com.firenio.codec.http11.Cookie in project DevRing by LJYcoder.

the class SharedPrefsCookiePersistor method loadAll.

@Override
public List<Cookie> loadAll() {
    List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
    for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
        String serializedCookie = (String) entry.getValue();
        Cookie cookie = new SerializableCookie().decode(serializedCookie);
        if (cookie != null) {
            cookies.add(cookie);
        }
    }
    return cookies;
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 28 with Cookie

use of com.firenio.codec.http11.Cookie in project DevRing by LJYcoder.

the class SharedPrefsCookiePersistor method saveAll.

@Override
public void saveAll(Collection<Cookie> cookies) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    for (Cookie cookie : cookies) {
        editor.putString(createCookieKey(cookie), new SerializableCookie().encode(cookie));
    }
    editor.commit();
}
Also used : Cookie(okhttp3.Cookie) SharedPreferences(android.content.SharedPreferences)

Example 29 with Cookie

use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.

the class EhCookieStore method loadForRequest.

@Override
public List<Cookie> loadForRequest(HttpUrl url) {
    List<Cookie> cookies = super.loadForRequest(url);
    boolean checkTips = domainMatch(url, EhUrl.DOMAIN_E);
    if (checkTips) {
        List<Cookie> result = new ArrayList<>(cookies.size() + 1);
        // Add all but skip some
        for (Cookie cookie : cookies) {
            String name = cookie.name();
            if (EhConfig.KEY_CONTENT_WARNING.equals(name)) {
                continue;
            }
            if (EhConfig.KEY_UCONFIG.equals(name)) {
                continue;
            }
            result.add(cookie);
        }
        // Add some
        result.add(sTipsCookie);
        return Collections.unmodifiableList(result);
    } else {
        return cookies;
    }
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList)

Example 30 with Cookie

use of com.firenio.codec.http11.Cookie in project EhViewer by seven332.

the class MyTagsActivity method onCreate.

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.flush();
        cookieManager.removeAllCookies(null);
        cookieManager.removeSessionCookies(null);
    } else {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
        cookieSyncManager.startSync();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
    }
    // Copy cookies from okhttp cookie store to CookieManager
    url = EhUrl.getMyTagsUrl();
    EhCookieStore store = EhApplication.getEhCookieStore(this);
    for (Cookie cookie : store.getCookies(HttpUrl.parse(url))) {
        cookieManager.setCookie(url, cookie.toString());
    }
    setContentView(R.layout.activity_my_tags);
    setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
    webView = findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new MyTagsWebViewClient());
    webView.setWebChromeClient(new DialogWebChromeClient(this));
    webView.loadUrl(url);
    progress = findViewById(R.id.progress);
}
Also used : Cookie(okhttp3.Cookie) EhCookieStore(com.hippo.ehviewer.client.EhCookieStore) DialogWebChromeClient(com.hippo.ehviewer.widget.DialogWebChromeClient) CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

Cookie (okhttp3.Cookie)102 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)20 HttpUrl (okhttp3.HttpUrl)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ObjectInputStream (java.io.ObjectInputStream)16 SharedPreferences (android.content.SharedPreferences)12 Context (android.content.Context)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Test (org.junit.Test)8 Response (okhttp3.Response)7 SerializableCookie (com.lzy.okgo.cookie.SerializableCookie)6 Request (okhttp3.Request)6 SuppressLint (android.annotation.SuppressLint)4 CookieManager (android.webkit.CookieManager)4 EhCookieStore (com.hippo.ehviewer.client.EhCookieStore)4 OnClick (butterknife.OnClick)3 SerializableCookie (com.franmontiel.persistentcookiejar.persistence.SerializableCookie)3