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
@@ -16,38 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import com.hippo.okhttp.CookieDB;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CookieDBTest extends TestCase {
|
||||
|
||||
private static final String[] TEST_DOMAIN = {
|
||||
null,
|
||||
"",
|
||||
"asdfghjkl",
|
||||
"asdfghjkl.sds",
|
||||
"asdfghjkl.sds.sddddd",
|
||||
"asdfghjkl.sds.sddddd.aaaaa",
|
||||
"asdfghjkl.sds.sddddd.",
|
||||
"asdfghjkl.sds..",
|
||||
};
|
||||
|
||||
private static final String[] TEST_COOKIES_DOMAIN = {
|
||||
"",
|
||||
"",
|
||||
"asdfghjkl",
|
||||
"asdfghjkl.sds",
|
||||
"sds.sddddd",
|
||||
"sddddd.aaaaa",
|
||||
"sddddd.",
|
||||
".",
|
||||
};
|
||||
|
||||
public void testCookiesDomain() {
|
||||
for (int i = 0; i < TEST_DOMAIN.length; i++) {
|
||||
Assert.assertEquals(TEST_COOKIES_DOMAIN[i], CookieDB.cookiesDomain(TEST_DOMAIN[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
-1
Submodule beerbelly updated: 6163029f62...f13aeed904.
+1
-1
Submodule cardsalon updated: 59b2b36187...0ea892e7ec.
+1
-1
Submodule conaco updated: a6d0f5a7a6...becb4a8c42.
+1
-1
Submodule yorozuya updated: 8d2a07ead6...cd9bd4ca50.
Reference in new issue
Block a user