Add EhConfig for each request
This commit is contained in:
1 parent
740ab2950c
commit
6b569ee82d
9 files changed
+71
-49
No files matched your search
@@ -20,16 +20,25 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
public class Settings {
|
||||
|
||||
private static Context sContext;
|
||||
private static SharedPreferences sSettingsPre;
|
||||
private static EhConfig sEhConfig;
|
||||
|
||||
public static void initialize(Context context) {
|
||||
sContext = context.getApplicationContext();
|
||||
sSettingsPre = PreferenceManager.getDefaultSharedPreferences(sContext);
|
||||
sEhConfig = loadEhConfig();
|
||||
}
|
||||
|
||||
private static EhConfig loadEhConfig() {
|
||||
EhConfig ehConfig= new EhConfig();
|
||||
// TODO
|
||||
return ehConfig;
|
||||
}
|
||||
|
||||
public static boolean getBoolean(String key, boolean defValue) {
|
||||
@@ -101,4 +110,14 @@ public class Settings {
|
||||
public static void putShowWarning(boolean value) {
|
||||
putBoolean(KEY_SHOW_WARNING, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static EhConfig getEhConfig() {
|
||||
return sEhConfig;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -488,7 +488,7 @@ public class EhConfig implements Cloneable {
|
||||
* key: {@link #KEY_PREVIEW_SIZE}<br/>
|
||||
* value: {@link #PREVIEW_SIZE_NORMAL}, {@link #PREVIEW_SIZE_LARGE}
|
||||
*/
|
||||
public String previewSize = PREVIEW_SIZE_NORMAL;
|
||||
public String previewSize = PREVIEW_SIZE_LARGE;
|
||||
|
||||
/**
|
||||
* Preview row<br/>
|
||||
@@ -650,16 +650,12 @@ public class EhConfig implements Cloneable {
|
||||
KEY_MULTI_PAGE_THUMB + "_" + multiPageThumb;
|
||||
}
|
||||
|
||||
/*
|
||||
public void fillCookie(Cookie cookie) {
|
||||
public String uconfig() {
|
||||
if (mDirty) {
|
||||
mDirty = false;
|
||||
updateUconfig();
|
||||
}
|
||||
|
||||
cookie.put(KEY_UCONFIG, mUconfig);
|
||||
cookie.put(KEY_LOFI_RESOLUTION, lofiResolution);
|
||||
cookie.put(KEY_CONTENT_WARNING, contentWarning);
|
||||
return mUconfig;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -19,10 +19,12 @@ package com.hippo.ehviewer.client;
|
||||
import com.hippo.okhttp.CookieDBStore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class EhCookieStore extends CookieDBStore {
|
||||
|
||||
@@ -61,19 +63,52 @@ public class EhCookieStore extends CookieDBStore {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cookie> loadForRequest(HttpUrl url, Request request) {
|
||||
List<Cookie> cookies = super.loadForRequest(url, request);
|
||||
Object tag = request.tag();
|
||||
|
||||
if (url.host().equals(EhUrl.DOMAIN_EX) && tag instanceof EhConfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
|
||||
List<Cookie> result = new ArrayList<>(cookies.size() + 1);
|
||||
// Add all but skip uconfig
|
||||
for (Cookie cookie: cookies) {
|
||||
if (EhConfig.KEY_UCONFIG.equals(cookie.name())) {
|
||||
continue;
|
||||
}
|
||||
result.add(cookie);
|
||||
}
|
||||
// Add uconfig from EhConfig
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(EhUrl.DOMAIN_EX)
|
||||
.path("/")
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
|
||||
return Collections.unmodifiableList(result);
|
||||
} else {
|
||||
return cookies;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
|
||||
List<Cookie> cs = new ArrayList<>(cookies.size() + 2);
|
||||
List<Cookie> result = new ArrayList<>(cookies.size() + 2);
|
||||
|
||||
for (Cookie cookie: cookies) {
|
||||
cs.add(cookie);
|
||||
result.add(cookie);
|
||||
|
||||
// Save id and hash for exhentai
|
||||
if (EhUrl.DOMAIN_E.equals(cookie.domain()) &&
|
||||
(KEY_IPD_MEMBER_ID.equals(cookie.name()) ||
|
||||
KEY_IPD_PASS_HASH.equals(cookie.name()))) {
|
||||
cs.add(newCookie(cookie, EhUrl.DOMAIN_EX));
|
||||
result.add(newCookie(cookie, EhUrl.DOMAIN_EX));
|
||||
}
|
||||
}
|
||||
|
||||
super.saveFromResponse(url, cs);
|
||||
super.saveFromResponse(url, Collections.unmodifiableList(result));
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,17 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.okhttp.ChromeRequestBuilder;
|
||||
|
||||
public class EhRequestBuilder extends ChromeRequestBuilder {
|
||||
|
||||
public EhRequestBuilder(String url) {
|
||||
super(url);
|
||||
this(url, Settings.getEhConfig());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public EhRequestBuilder(String url, EhConfig ehConfig) {
|
||||
super(url);
|
||||
tag(ehConfig);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user