\"]+)\">" // rating
+ + ".+?"
+ + "
(.+?)"); // uploader
+ m = p.matcher(body);
+ while (m.find()) {
+ GalleryInfo gi = new GalleryInfo();
+
+ gi.category = EhUtils.getCategory(ParserUtils.trim(m.group(1)));
+ gi.posted = ParserUtils.trim(m.group(2));
+ gi.thumbHeight = ParserUtils.parseInt(m.group(3));
+ gi.thumbWidth = ParserUtils.parseInt(m.group(4));
+
+ if (m.group(5) == null) {
+ gi.thumb = ParserUtils.trim("http://" + m.group(7).replace('~', '/'));
+ gi.title = ParserUtils.trim(m.group(8));
+ } else {
+ gi.thumb = ParserUtils.trim(m.group(5));
+ gi.title = ParserUtils.trim(m.group(6));
+ }
+
+ Pattern pattern = Pattern
+ .compile("/(\\d+)/(\\w+)");
+ Matcher matcher = pattern.matcher(m.group(9));
+ if (matcher.find()) {
+ gi.gid = ParserUtils.parseInt(matcher.group(1));
+ gi.token = ParserUtils.trim(matcher.group(2));
+ } else {
+ continue;
+ }
+
+ gi.rating = Utils.parseFloatSafely(getRate(m.group(11)), Float.NaN);
+ gi.uploader = ParserUtils.trim(m.group(12));
+ gi.generateSLang();
+
+ list.add(gi);
+ }
+
+ if (list.size() == 0) {
+ throw new ParseException("Can't parse gallery list", body);
+ }
+ }
+
+ return result;
+ }
+
+ private static Result parseLofi(String body) throws Exception {
+ Result result = new Result();
+ Pattern p;
+ Matcher m;
+
+ List list = new ArrayList<>(25);
+ result.galleryInfos = list;
p = Pattern.compile("" // detail url
+ " " // thumb url
+ ".+?(.+?)" // title
@@ -139,8 +162,8 @@ public class GalleryListParser {
lgi.gid = dup.gid;
lgi.token = dup.token;
- lgi.thumb = Utils.unescapeXml(m.group(2));
- lgi.title = Utils.unescapeXml(m.group(3));
+ lgi.thumb = ParserUtils.trim(m.group(2));
+ lgi.title = ParserUtils.trim(m.group(3));
getPostedAndUploader(m.group(4), pau);
lgi.posted = pau[0];
@@ -159,44 +182,29 @@ public class GalleryListParser {
lgi.rating = getStartNum(rating);
lgi.generateSLang();
- giList.add(lgi);
+ list.add(lgi);
}
- if (giList.size() == 0) {
+ if (list.size() == 0) {
if (body.contains("No hits found")) {
- pageNum = 0;
+ result.pages = Result.NOT_FOUND;
} else if (body.contains("No more hits found")) {
throw new EhException("Index is out of range");
} else {
- throw new EhException(PARSE_MESSAGE);
+ throw new ParseException("Can't parse gallery list", body);
}
} else {
if (!body.contains("Next Page >")) {
- pageNum = CURRENT_PAGE_IS_LAST;
+ result.pages = Result.CURRENT_PAGE_IS_LAST;
} else {
- pageNum = Integer.MAX_VALUE;
+ result.pages = Result.KEEP_LOADING;
}
}
+
+ return result;
}
- public void parse(String body, int source) throws Exception {
- AssertUtils.assertNotNull("Body is null when parse gallery list", body);
-
- switch (source) {
- default:
- case EhClient.SOURCE_G:
- case EhClient.SOURCE_EX: {
- parse(body);
- break;
- }
- case EhClient.SOURCE_LOFI: {
- parseLofi(body);
- break;
- }
- }
- }
-
- private String getRate(String rawRate) {
+ private static String getRate(String rawRate) {
Pattern p = Pattern.compile("\\d+px");
Matcher m = p.matcher(rawRate);
int num1;
@@ -204,11 +212,11 @@ public class GalleryListParser {
int rate = 5;
String re;
if (m.find())
- num1 = Integer.parseInt(m.group().replace("px", ""));
+ num1 = ParserUtils.parseInt(m.group().replace("px", ""));
else
return null;
if (m.find())
- num2 = Integer.parseInt(m.group().replace("px", ""));
+ num2 = ParserUtils.parseInt(m.group().replace("px", ""));
else
return null;
rate = rate - num1 / 16;
@@ -223,14 +231,14 @@ public class GalleryListParser {
private static final String PAU_SPACER = " by ";
- private void getPostedAndUploader(String raw, String[] pau) throws AssertException {
+ private static void getPostedAndUploader(String raw, String[] pau) throws AssertException {
int index = raw.indexOf(PAU_SPACER);
AssertUtils.assertNotEqualsEx("Can not parse posted and uploader", index, -1);
pau[0] = raw.substring(0, index);
pau[1] = raw.substring(index + PAU_SPACER.length());
}
- private int getStartNum(String str) {
+ private static int getStartNum(String str) {
int startNum = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '*')
diff --git a/app/src/main/java/com/hippo/ehviewer/client/ParserUtils.java b/app/src/main/java/com/hippo/ehviewer/client/ParserUtils.java
new file mode 100644
index 000000000..816f96e9a
--- /dev/null
+++ b/app/src/main/java/com/hippo/ehviewer/client/ParserUtils.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Hippo Seven
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hippo.ehviewer.client;
+
+import com.hippo.util.Utils;
+
+public class ParserUtils {
+
+ public static String trim(String str) {
+ // Avoid null
+ if (str == null) {
+ str = "";
+ }
+ return Utils.unescapeXml(str).trim();
+ }
+
+ public static int parseInt(String str) {
+ return Integer.parseInt(trim(str).replace(",", ""));
+ }
+}
diff --git a/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java b/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java
index 10f277df4..485b9fe2c 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java
+++ b/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java
@@ -28,22 +28,27 @@ import java.util.List;
public class PopularParser {
- public List galleryInfoList;
- public long timeStamp;
+ public static class Result {
- public void parse(String body) throws Exception {
- galleryInfoList = new ArrayList<>();
+ public long timeStamp;
+ public List galleryInfos;
+ }
+
+ public static Result parse(String body) throws Exception {
+ Result result = new Result();
JSONObject js = new JSONObject(body);
- js = js.getJSONObject("popular");
+ js = js.getJSONObject("popular");
if (!js.has("galleries")) {
if (js.has("error")) {
throw new EhException(js.getString("error"));
} else {
- throw new EhException("Parser error"); // TODO
+ throw new ParseException("Can't parse popular", body);
}
}
+ List list = new ArrayList<>();
+ result.galleryInfos = list;
JSONArray ja = js.getJSONArray("galleries");
for (int i = 0; i < ja.length(); i++) {
JSONObject j = ja.getJSONObject(i);
@@ -57,13 +62,15 @@ public class PopularParser {
gi.uploader = j.getString("uploader");
gi.rating = Float.parseFloat(j.getString("rating"));
gi.generateSLang();
- galleryInfoList.add(gi);
+ list.add(gi);
}
if (js.has("time")) {
- timeStamp = js.getLong("time");
+ result.timeStamp = js.getLong("time");
} else {
- timeStamp = -1;
+ result.timeStamp = -1;
}
+
+ return result;
}
}
diff --git a/app/src/main/java/com/hippo/ehviewer/client/SignInParser.java b/app/src/main/java/com/hippo/ehviewer/client/SignInParser.java
index ad21d2600..8bf8b625b 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/SignInParser.java
+++ b/app/src/main/java/com/hippo/ehviewer/client/SignInParser.java
@@ -20,17 +20,15 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SignInParser {
- public String displayname;
- public boolean parse(String body) throws Exception {
+ public static String parse(String body) throws Exception {
Pattern p;
Matcher m;
p = Pattern.compile("You are now logged in as: (.+?) ");
m = p.matcher(body);
if (m.find()) {
- displayname = m.group(1);
- return true;
+ return m.group(1);
} else {
p = Pattern.compile("(?: The error returned was:\\s*(.+?) )"
+ "|(?:(.+?))");
diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java b/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java
index 8c2b60b05..1220cff90 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java
+++ b/app/src/main/java/com/hippo/ehviewer/client/data/ListUrlBuilder.java
@@ -16,7 +16,8 @@
package com.hippo.ehviewer.client.data;
-import com.hippo.ehviewer.client.EhClient;
+import com.hippo.ehviewer.client.EhConfig;
+import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.util.EhUtils;
import com.hippo.ehviewer.widget.AdvanceSearchTable;
import com.hippo.network.UrlBuilder;
@@ -128,18 +129,18 @@ public class ListUrlBuilder {
case MODE_NORMAL:
case MODE_UPLOADER: {
boolean filter = false;
- UrlBuilder ub = new UrlBuilder(EhClient.getUrlHeader(source));
+ UrlBuilder ub = new UrlBuilder(EhUrl.getUrlHeader(source));
if (mCategory != EhUtils.NONE) {
- ub.addQuery("f_doujinshi", ((mCategory & EhUtils.DOUJINSHI) == 0) ? "0" : "1");
- ub.addQuery("f_manga", ((mCategory & EhUtils.MANGA) == 0) ? "0" : "1");
- ub.addQuery("f_artistcg", ((mCategory & EhUtils.ARTIST_CG) == 0) ? "0" : "1");
- ub.addQuery("f_gamecg", ((mCategory & EhUtils.GAME_CG) == 0) ? "0" : "1");
- ub.addQuery("f_western", ((mCategory & EhUtils.WESTERN) == 0) ? "0" : "1");
- ub.addQuery("f_non-h", ((mCategory & EhUtils.NON_H) == 0) ? "0" : "1");
- ub.addQuery("f_imageset", ((mCategory & EhUtils.IMAGE_SET) == 0) ? "0" : "1");
- ub.addQuery("f_cosplay", ((mCategory & EhUtils.COSPLAY) == 0) ? "0" : "1");
- ub.addQuery("f_asianporn", ((mCategory & EhUtils.ASIAN_PORN) == 0) ? "0" : "1");
- ub.addQuery("f_misc", ((mCategory & EhUtils.MISC) == 0) ? "0" : "1");
+ ub.addQuery("f_doujinshi", ((mCategory & EhConfig.DOUJINSHI) == 0) ? "0" : "1");
+ ub.addQuery("f_manga", ((mCategory & EhConfig.MANGA) == 0) ? "0" : "1");
+ ub.addQuery("f_artistcg", ((mCategory & EhConfig.ARTIST_CG) == 0) ? "0" : "1");
+ ub.addQuery("f_gamecg", ((mCategory & EhConfig.GAME_CG) == 0) ? "0" : "1");
+ ub.addQuery("f_western", ((mCategory & EhConfig.WESTERN) == 0) ? "0" : "1");
+ ub.addQuery("f_non-h", ((mCategory & EhConfig.NON_H) == 0) ? "0" : "1");
+ ub.addQuery("f_imageset", ((mCategory & EhConfig.IMAGE_SET) == 0) ? "0" : "1");
+ ub.addQuery("f_cosplay", ((mCategory & EhConfig.COSPLAY) == 0) ? "0" : "1");
+ ub.addQuery("f_asianporn", ((mCategory & EhConfig.ASIAN_PORN) == 0) ? "0" : "1");
+ ub.addQuery("f_misc", ((mCategory & EhConfig.MISC) == 0) ? "0" : "1");
filter = true;
}
// Search key
@@ -180,10 +181,10 @@ public class ListUrlBuilder {
return ub.build();
}
case MODE_TAG: {
- if (source == EhClient.SOURCE_LOFI) {
+ if (source == EhUrl.SOURCE_LOFI) {
throw new UnsupportedSearchException("Lofi do not support tag search");
}
- StringBuilder sb = new StringBuilder(EhClient.getUrlHeader(source));
+ StringBuilder sb = new StringBuilder(EhUrl.getUrlHeader(source));
sb.append("tag/");
try {
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
diff --git a/app/src/main/java/com/hippo/ehviewer/network/EhHttpClient.java b/app/src/main/java/com/hippo/ehviewer/network/EhHttpClient.java
new file mode 100644
index 000000000..b5d592683
--- /dev/null
+++ b/app/src/main/java/com/hippo/ehviewer/network/EhHttpClient.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2015 Hippo Seven
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hippo.ehviewer.network;
+
+import android.content.Context;
+import android.os.Build;
+import android.webkit.CookieManager;
+import android.webkit.CookieSyncManager;
+
+import com.hippo.ehviewer.client.EhConfig;
+import com.hippo.ehviewer.util.Settings;
+import com.hippo.httpclient.Cookie;
+import com.hippo.httpclient.HttpClient;
+import com.hippo.util.MathUtils;
+import com.hippo.util.Utils;
+
+import java.net.URL;
+
+public class EhHttpClient extends HttpClient {
+
+ private static String[] EHENTAI_DOMAIN = {
+ "exhentai.org",
+ "e-hentai.org"
+ };
+
+ private static final String HOST_EX = "exhentai.org";
+
+ private static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
+ private static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
+ private static final String KEY_IGNEOUS = "igneous";
+ private static final String KEY_YAY = "yay";
+
+ private final CookieManager mCookieManager;
+
+ private EhConfig mEhConfig;
+
+ @SuppressWarnings("deprecation")
+ public EhHttpClient(Context context) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ CookieSyncManager.createInstance(context);
+ }
+
+ mCookieManager = CookieManager.getInstance();
+ mEhConfig = Settings.getEhConfig();
+ }
+
+ private String getDomain(URL uri) {
+ String host = uri.getHost();
+ int length = host.length();
+ int dotCount = 0;
+ int i = length;
+ while(i-- != 0) {
+ char ch = host.charAt(i);
+ if (ch == '.') {
+ dotCount++;
+ }
+ if (dotCount == 2) {
+ // Get it
+ break;
+ }
+ }
+ return host.substring(MathUtils.clamp(i + 1, 0, length));
+ }
+
+ @Override
+ protected void fillCookie(URL url, Cookie cookie) {
+ boolean isSignIn = Settings.getSignIn();
+ String host = url.getHost();
+
+ cookie.putRaw(mCookieManager.getCookie(url.toString()));
+
+ if (Utils.contain(EHENTAI_DOMAIN, getDomain(url)))
+
+
+ if (!isSignIn && HOST_EX.equals(host)) {
+ cookie.put("yay", "louder");
+ } else {
+ cookie.putRaw(mCookieManager.getCookie(url.toString()));
+
+ if (Utils.contain(EHENTAI_DOMAIN, getDomain(url))) {
+ if (Settings.getSignIn()) {
+ // Put login info
+ String ipdMemberId = Settings.getIpdNumberId();
+ String ipdPassHash = Settings.getIpdPassHash();
+ String igneous = Settings.getIgneous();
+ if (ipdMemberId != null) {
+ cookie.put(KEY_IPD_MEMBER_ID, ipdMemberId);
+ }
+ if (ipdPassHash != null) {
+ cookie.put(KEY_IPD_PASS_HASH, ipdPassHash);
+ }
+ if (igneous != null) {
+ cookie.put(KEY_IGNEOUS, igneous);
+ }
+ } else if (HOST_EX.equals(url.getHost())) {
+ cookie.put("yay", "louder");
+ }
+
+ mEhConfig.fillCookie(cookie);
+ }
+ }
+ }
+
+ @Override
+ protected void storeCookie(URL url, String cookieStr) {
+ Cookie cookie = new Cookie();
+ cookie.putRaw(cookieStr);
+
+ String ipdMemberId = cookie.get(KEY_IPD_MEMBER_ID);
+ String ipdPassHash = cookie.get(KEY_IPD_PASS_HASH);
+ String igneous = cookie.get(KEY_IGNEOUS);
+ if (ipdMemberId != null) {
+ Settings.putIpdMemberId(ipdMemberId);
+ }
+ if (ipdPassHash != null) {
+ Settings.putIpdPassHash(ipdPassHash);
+ }
+ if (igneous != null) {
+ Settings.putIgneous(igneous);
+ }
+
+ cookie.remove(KEY_IPD_MEMBER_ID);
+ cookie.remove(KEY_IPD_MEMBER_ID);
+ cookie.remove(KEY_IGNEOUS);
+ cookie.remove(KEY_YAY);
+ cookie.remove(EhConfig.KEY_UCONFIG);
+ cookie.remove(EhConfig.KEY_LOFI_RESOLUTION);
+ cookie.remove(EhConfig.KEY_CONTENT_WARNING);
+
+ mCookieManager.setCookie(url.toString(), cookie.toString());
+ }
+}
diff --git a/app/src/main/java/com/hippo/ehviewer/network/EhHttpRequest.java b/app/src/main/java/com/hippo/ehviewer/network/EhHttpRequest.java
new file mode 100644
index 000000000..9675219eb
--- /dev/null
+++ b/app/src/main/java/com/hippo/ehviewer/network/EhHttpRequest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2015 Hippo Seven
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.hippo.ehviewer.network;
+
+import com.hippo.ehviewer.client.EhConfig;
+import com.hippo.ehviewer.client.EhException;
+import com.hippo.httpclient.Cookie;
+import com.hippo.httpclient.HttpRequest;
+import com.hippo.httpclient.ResponseCodeException;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class EhHttpRequest extends HttpRequest {
+
+ private static final String SAD_PANDA_DISPOSITION = "inline; filename=\"sadpanda.jpg\"";
+ private static final String SAD_PANDA_TYPE = "image/gif";
+ private static final String SAD_PANDA_LENGTH = "9615";
+
+ private EhConfig mEhConfig;
+
+ public void setEhConfig(EhConfig ehConfig) {
+ mEhConfig = ehConfig;
+ }
+
+ @Override
+ protected void fillCookie(URL url, Cookie cookie) {
+ super.fillCookie(url, cookie);
+
+ if (mEhConfig != null) {
+ mEhConfig.fillCookie(cookie);
+ }
+ }
+
+ @Override
+ protected void onAfterConnect(HttpURLConnection conn) throws Exception {
+ super.onAfterConnect(conn);
+
+ final int responseCode = conn.getResponseCode();
+ if (responseCode >= 400) {
+ throw new ResponseCodeException(responseCode);
+ }
+
+ String disposition = conn.getHeaderField("Content-Disposition");
+ String type = conn.getHeaderField("Content-Type");
+ String length = conn.getHeaderField("Content-Length");
+
+ if (SAD_PANDA_DISPOSITION.equals(disposition) && SAD_PANDA_TYPE.equals(type) &&
+ SAD_PANDA_LENGTH.equals(length)) {
+ throw new EhException("Sad Panda");
+ }
+ }
+}
diff --git a/app/src/main/java/com/hippo/ehviewer/network/EhOkHttpClient.java b/app/src/main/java/com/hippo/ehviewer/network/EhOkHttpClient.java
deleted file mode 100644
index baeefa0dc..000000000
--- a/app/src/main/java/com/hippo/ehviewer/network/EhOkHttpClient.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2015 Hippo Seven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hippo.ehviewer.network;
-
-import android.webkit.CookieManager;
-
-import com.hippo.ehviewer.util.Config;
-import com.hippo.network.Cookie;
-import com.hippo.util.MathUtils;
-import com.hippo.util.Utils;
-import com.squareup.okhttp.Interceptor;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
-
-import java.io.IOException;
-import java.net.CookieHandler;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-public class EhOkHttpClient extends OkHttpClient {
-
- public static final String DEFAULT_USER_AGENT =
- "Mozilla/5.0 (Windows NT 6.1; WOW64) " +
- "AppleWebKit/537.36 (KHTML, like Gecko) " +
- "Chrome/39.0.2171.95 Safari/537.36";
- public static final String USER_AGENT =
- System.getProperty("http.agent", DEFAULT_USER_AGENT);
-
- private static String[] EHENTAI_DOMAIN = {
- "exhentai.org",
- "e-hentai.org"
- };
-
- private static final String HOST_EX = "exhentai.org";
- private static final String HOST_LOFI = "lofi.e-hentai.org";
-
- private static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
- private static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
- private static final String KEY_IGNEOUS = "igneous";
- private static final String KEY_UCONFIG = "uconfig";
- private static final String KEY_XRES = "xres";
- private static final String KEY_YAY = "yay";
-
- private static CookieHandler mCookieHandler = new CookieHandler() {
-
- private final CookieManager mCookieManager = CookieManager.getInstance();
-
- public String getDomain(URI uri) {
- String host = uri.getHost();
- int length = host.length();
- int dotCount = 0;
- int i = length;
- while(i-- != 0) {
- char ch = host.charAt(i);
- if (ch == '.') {
- dotCount++;
- }
- if (dotCount == 2) {
- // Get it
- break;
- }
- }
- return host.substring(MathUtils.clamp(i + 1, 0, length));
- }
-
- @Override
- public Map> get(URI uri, Map> requestHeaders) throws IOException {
- boolean isSignIn = Config.getSignIn();
- String host = uri.getHost();
- Cookie cookie = new Cookie();
-
- if (!isSignIn && HOST_EX.equals(host)) {
- cookie.put("yay", "louder");
- } else {
- cookie.putRaw(mCookieManager.getCookie(uri.toString()));
-
- if (isSignIn && Utils.contain(EHENTAI_DOMAIN, getDomain(uri))) {
- String ipdMemberId = Config.getIpdNumberId();
- String ipdPassHash = Config.getIpdPassHash();
- String igneous = Config.getIgneous();
- if (ipdMemberId != null) {
- cookie.put(KEY_IPD_MEMBER_ID, ipdMemberId);
- }
- if (ipdPassHash != null) {
- cookie.put(KEY_IPD_PASS_HASH, ipdPassHash);
- }
- if (igneous != null) {
- cookie.put(KEY_IGNEOUS, igneous);
- }
- // TODO cookie.put(KEY_UCONFIG, Config.getUconfig());
- }
-
- if (HOST_LOFI.equals(host)) {
- // TODO cookie.put(KEY_XRES, Config.getXres());
- }
- }
-
- List cookieList = new ArrayList<>();
- cookieList.add(cookie.toString());
- // Map to return
- Map> cookieMap = new HashMap<>(requestHeaders);
- cookieMap.put("Cookie" , cookieList);
-
- return Collections.unmodifiableMap(cookieMap);
- }
-
- @Override
- public void put(URI uri, Map> responseHeaders) throws IOException {
- Cookie cookie = new Cookie();
-
- List cookieList = responseHeaders.get("Set-Cookie");
- if (cookieList != null) {
- for (String cookieString : cookieList) {
- cookie.putRaw(cookieString);
- }
- }
-
- String ipdMemberId = cookie.get(KEY_IPD_MEMBER_ID);
- String ipdPassHash = cookie.get(KEY_IPD_PASS_HASH);
- String igneous = cookie.get(KEY_IGNEOUS);
- if (ipdMemberId != null) {
- Config.putIpdMemberId(ipdMemberId);
- }
- if (ipdPassHash != null) {
- Config.putIpdPassHash(ipdPassHash);
- }
- if (igneous != null) {
- Config.putIgneous(igneous);
- }
-
- cookie.remove(KEY_IPD_MEMBER_ID);
- cookie.remove(KEY_IPD_MEMBER_ID);
- cookie.remove(KEY_UCONFIG);
- cookie.remove(KEY_XRES);
- cookie.remove(KEY_YAY);
-
- mCookieManager.setCookie(uri.toString(), cookie.toString());
- }
- };
-
- public static class UserAgentInterceptor implements Interceptor {
-
- private String mUserAgent;
-
- public UserAgentInterceptor(String userAgent) {
- mUserAgent = userAgent;
- }
-
- @Override
- public Response intercept(Chain chain) throws IOException {
- Request originalRequest = chain.request();
- Request requestWithUserAgent = originalRequest.newBuilder()
- .removeHeader("User-Agent")
- .addHeader("User-Agent", mUserAgent)
- .build();
- return chain.proceed(requestWithUserAgent);
- }
- }
-
- private static final EhOkHttpClient sInstance = new EhOkHttpClient();
-
- public static EhOkHttpClient getInstance() {
- return sInstance;
- }
-
- private EhOkHttpClient() {
- setCookieHandler(mCookieHandler);
- setConnectTimeout(5, TimeUnit.SECONDS);
- setReadTimeout(5, TimeUnit.SECONDS);
- setFollowRedirects(true);
- networkInterceptors().add(new UserAgentInterceptor(USER_AGENT));
- }
-}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java
index f2627f0ec..399213a03 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java
@@ -31,7 +31,7 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ui.scene.GalleryListScene;
import com.hippo.ehviewer.ui.scene.MainSettingsScene;
import com.hippo.ehviewer.ui.scene.SignInScene;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.ehviewer.widget.DrawerLeftPanel;
import com.hippo.ehviewer.widget.FitStageLayout;
import com.hippo.scene.Announcer;
@@ -130,7 +130,7 @@ public final class ContentActivity extends StageActivity
@Override
protected boolean isShowStats() {
- return Config.getShowApplicationStats();
+ return Settings.getShowApplicationStats();
}
@SuppressLint("RtlHardcoded")
@@ -242,7 +242,7 @@ public final class ContentActivity extends StageActivity
@Override
public void onClickSignOut() {
- Config.putSignIn(false);
+ Settings.putSignIn(false);
Messenger.getInstance().notify(Constants.MESSENGER_ID_SIGN_IN_OR_OUT, null);
}
}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java
index ace86be9a..2acb4f754 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java
@@ -38,14 +38,16 @@ import com.hippo.ehviewer.EhImageKeyFactory;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhException;
+import com.hippo.ehviewer.client.EhRequest;
+import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.OffensiveException;
import com.hippo.ehviewer.client.data.Comment;
import com.hippo.ehviewer.client.data.GalleryDetail;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.data.PreviewSet;
import com.hippo.ehviewer.client.data.TagGroup;
-import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.EhUtils;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.ehviewer.widget.LoadImageView;
import com.hippo.ehviewer.widget.PreviewLayout;
import com.hippo.ehviewer.widget.RatingView;
@@ -118,9 +120,16 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
private GalleryDetail mGalleryDetail;
private void requestGalleryDetail(GalleryInfo gi) {
- EhClient.getInstance().getGalleryDetail(Config.getEhSource(),
- EhClient.getDetailUrl(Config.getEhSource(), gi.gid, gi.token, 0),
- new EhDetailListener());
+ EhClient client = EhApplication.getEhClient(getStageActivity());
+ int source = Settings.getEhSource();
+ String url = EhUrl.getDetailUrl(source, gi.gid, gi.token, 0);
+
+ EhRequest request = new EhRequest();
+ request.setMethod(EhClient.METHOD_GET_GALLERY_DETAIL);
+ request.setEhListener(new EhDetailListener());
+ request.setArgs(url, source);
+ // TODO request.setEhConfig();
+ client.execute(request);
}
private void handleAnnouncer(Announcer announcer) {
@@ -270,7 +279,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
} else if (v == mShare) {
StartActivityHelper.share(getStageActivity(),
- EhClient.getDetailUrl(Config.getEhSource(), gd.gid, gd.token, 0));
+ EhUrl.getDetailUrl(Settings.getEhSource(), gd.gid, gd.token, 0));
}
}
@@ -421,7 +430,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
}
}
- private class EhDetailListener extends EhClient.OnGetGalleryDetailListener {
+ private class EhDetailListener extends EhClient.EhListener {
@Override
public void onSuccess(GalleryDetail galleryDetail) {
@@ -483,28 +492,44 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
}).show(GalleryDetailScene.this);
}
}
+
+ @Override
+ public void onCanceled() {
+
+ }
}
class SimplePreviewHelper implements PreviewLayout.PreviewHelper {
@Override
public void onRequstPreview(PreviewLayout previewLayout, final int index) {
- int source = Config.getEhSource();
- EhClient.getInstance().getPreviewSet(source,
- EhClient.getDetailUrl(source, mGalleryDetail.gid, mGalleryDetail.token, index),
- new EhClient.OnGetPreviewSetListener() {
+ EhClient client = EhApplication.getEhClient(getStageActivity());
+ int source = Settings.getEhSource();
+ String url = EhUrl.getDetailUrl(source, mGalleryDetail.gid, mGalleryDetail.token, index);
- @Override
- public void onSuccess(PreviewSet previewSet) {
- mPreviewLayout.onGetPreview(previewSet, index);
- }
+ EhRequest request = new EhRequest();
+ request.setMethod(EhClient.METHOD_GET_PREVIEW_SET);
+ // TODO request.setEhConfig();
+ request.setArgs(url, source);
+ request.setEhListener(new EhClient.EhListener() {
- @Override
- public void onFailure(Exception e) {
- // TODO
- e.printStackTrace();
- }
- });
+ @Override
+ public void onSuccess(PreviewSet result) {
+ mPreviewLayout.onGetPreview(result, index);
+ }
+
+ @Override
+ public void onFailure(Exception e) {
+ e.printStackTrace();
+ }
+
+ @Override
+ public void onCanceled() {
+
+ }
+ });
+
+ client.execute(request);
}
@Override
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
index 0c7a3e853..466f8ed33 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java
@@ -44,13 +44,16 @@ import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.EhImageKeyFactory;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhClient;
+import com.hippo.ehviewer.client.EhRequest;
+import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.GalleryListParser;
+import com.hippo.ehviewer.client.PopularParser;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.data.ListUrlBuilder;
import com.hippo.ehviewer.client.data.UnsupportedSearchException;
import com.hippo.ehviewer.ui.ContentActivity;
-import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.EhUtils;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.ehviewer.widget.ContentLayout;
import com.hippo.ehviewer.widget.LoadImageView;
import com.hippo.ehviewer.widget.OffsetLayout;
@@ -72,8 +75,6 @@ import com.hippo.widget.FabLayout;
import com.hippo.widget.FloatingActionButton;
import com.hippo.widget.recyclerview.EasyRecyclerView;
-import java.util.List;
-
// TODO remeber the data in ContentHelper after screen dirction change
// TODO Must refresh when change source
// TODO disable click action when animating
@@ -891,22 +892,33 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
@Override
protected void getPageData(int taskId, int type, int page) {
+ EhClient client = EhApplication.getEhClient(getStageActivity());
+
int mode = mListUrlBuilder.getMode();
if (mode == ListUrlBuilder.MODE_POPULAR) {
PopularListener listener = new PopularListener(taskId);
listener.setGalleryListHelper(this);
mListener = listener;
- EhClient.getInstance().getPopular(listener);
+ EhRequest request = new EhRequest();
+ request.setMethod(EhClient.METHOD_GET_POPULAR);
+ request.setEhListener(listener);
+ client.execute(request);
} else {
try {
- int source = Config.getEhSource();
+ int source = Settings.getEhSource();
mListUrlBuilder.setPageIndex(page);
String url = mListUrlBuilder.build(source);
GalleryListListener listener = new GalleryListListener(taskId,
type, page, source);
listener.setGalleryListHelper(this);
mListener = listener;
- EhClient.getInstance().getGalleryList(source, url, listener);
+
+ EhRequest request = new EhRequest();
+ request.setMethod(EhClient.METHOD_GET_GALLERY_LIST);
+ request.setEhListener(listener);
+ request.setArgs(url, source);
+
+ client.execute(request);
} catch (UnsupportedSearchException e) {
onGetPageData(taskId, e);
}
@@ -940,7 +952,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
}
}
- private static class GalleryListListener extends EhClient.OnGetGalleryListListener
+ private static class GalleryListListener extends EhClient.EhListener
implements GalleryListHelperSettable {
private int mTaskId;
@@ -963,18 +975,18 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
}
@Override
- public void onSuccess(List glList, int pageNum) {
+ public void onSuccess(GalleryListParser.Result result) {
if (mHelper != null) {
- if (mSource == EhClient.SOURCE_LOFI) {
- if (pageNum == GalleryListParser.CURRENT_PAGE_IS_LAST) {
+ if (mSource == EhUrl.SOURCE_LOFI) {
+ if (result.pages == GalleryListParser.Result.CURRENT_PAGE_IS_LAST) {
mHelper.setPageCount(mTargetPage);
} else if (mTaskType == ContentLayout.ContentHelper.TYPE_REFRESH) {
mHelper.setPageCount(Integer.MAX_VALUE);
}
} else {
- mHelper.setPageCount(pageNum);
+ mHelper.setPageCount(result.pages);
}
- mHelper.onGetPageData(mTaskId, glList);
+ mHelper.onGetPageData(mTaskId, result.galleryInfos);
mHelper.clearLastGalleryListHelperSettable(this);
}
@@ -988,9 +1000,14 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
mHelper.clearLastGalleryListHelperSettable(this);
}
}
+
+ @Override
+ public void onCanceled() {
+
+ }
}
- private static class PopularListener extends EhClient.OnGetPopularListener
+ private static class PopularListener extends EhClient.EhListener
implements GalleryListHelperSettable {
private int mTaskId;
@@ -1006,10 +1023,10 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
}
@Override
- public void onSuccess(List glList, long timeStamp) {
+ public void onSuccess(PopularParser.Result result) {
if (mHelper != null) {
mHelper.setPageCount(1);
- mHelper.onGetPageData(mTaskId, glList);
+ mHelper.onGetPageData(mTaskId, result.galleryInfos);
mHelper.clearLastGalleryListHelperSettable(this);
}
@@ -1023,6 +1040,11 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
mHelper.clearLastGalleryListHelperSettable(this);
}
}
+
+ @Override
+ public void onCanceled() {
+
+ }
}
private interface GalleryListHelperSettable {
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java
index d158a43b5..4550b9c8b 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java
@@ -23,9 +23,11 @@ import android.widget.EditText;
import android.widget.TextView;
import com.hippo.ehviewer.Constants;
+import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhClient;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.client.EhRequest;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.rippleold.RippleSalon;
import com.hippo.scene.Scene;
import com.hippo.util.Messenger;
@@ -39,11 +41,11 @@ public final class SignInScene extends Scene implements View.OnClickListener,
private TextView mSignUp;
private TextView mSignIn;
- private EhClient.OnSignInListener mSignInListener = new EhClient.OnSignInListener() {
+ private EhClient.EhListener mSignInListener = new EhClient.EhListener() {
@Override
public void onSuccess(String displayname) {
- Config.putSignIn(true);
- Config.putDisplayName(displayname);
+ Settings.putSignIn(true);
+ Settings.putDisplayName(displayname);
Messenger.getInstance().notify(Constants.MESSENGER_ID_SIGN_IN_OR_OUT, displayname);
}
@@ -51,6 +53,11 @@ public final class SignInScene extends Scene implements View.OnClickListener,
public void onFailure(Exception e) {
e.printStackTrace();
}
+
+ @Override
+ public void onCanceled() {
+
+ }
};
@Override
@@ -88,7 +95,13 @@ public final class SignInScene extends Scene implements View.OnClickListener,
if (v == mSignIn) {
String username = mUsername.getText().toString();
String password = mPassword.getText().toString();
- EhClient.getInstance().signIn(username, password, mSignInListener);
+ EhClient client = EhApplication.getEhClient(getStageActivity());
+
+ EhRequest request = new EhRequest();
+ request.setMethod(EhClient.METHOD_SIGN_IN);
+ request.setEhListener(mSignInListener);
+ request.setArgs(username, password);
+ client.execute(request);
}
}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/preference/EHSettingsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/preference/EHSettingsScene.java
index 773427bb4..d83671b1b 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/scene/preference/EHSettingsScene.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/preference/EHSettingsScene.java
@@ -18,10 +18,9 @@ package com.hippo.ehviewer.ui.scene.preference;
import android.content.res.Resources;
-import com.hippo.ehviewer.BuildConfig;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
-import com.hippo.ehviewer.client.EhClient;
+import com.hippo.ehviewer.client.EhUrl;
import com.hippo.scene.preference.ListPreference;
import com.hippo.scene.preference.Preference;
import com.hippo.scene.preference.PreferenceCategory;
@@ -32,8 +31,7 @@ import com.hippo.util.Messenger;
public final class EHSettingsScene extends PreferenceScene {
private static final String KEY_EH_SOURCE = "eh_source";
- private static final int DEFAULT_EH_SOURCE = BuildConfig.DEBUG ?
- EhClient.SOURCE_EX : EhClient.SOURCE_G;
+ private static final int DEFAULT_EH_SOURCE = EhUrl.SOURCE_G;
@Override
protected void onCreate(boolean rebirth) {
diff --git a/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java b/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java
index e66160b27..a31f30512 100644
--- a/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java
+++ b/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java
@@ -18,6 +18,8 @@ package com.hippo.ehviewer.util;
import android.graphics.Color;
+import com.hippo.ehviewer.client.EhConfig;
+
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
@@ -29,16 +31,6 @@ public final class EhUtils {
public static final String EH_DOWNLOAD_FILENAME = ".ehviewer";
public static final int NONE = -1; // Use it for homepage
- public static final int MISC = 0x1;
- public static final int DOUJINSHI = 0x2;
- public static final int MANGA = 0x4;
- public static final int ARTIST_CG = 0x8;
- public static final int GAME_CG = 0x10;
- public static final int IMAGE_SET = 0x20;
- public static final int COSPLAY = 0x40;
- public static final int ASIAN_PORN = 0x80;
- public static final int NON_H = 0x100;
- public static final int WESTERN = 0x200;
public static final int UNKNOWN = 0x400;
public static final int BG_COLOR_DOUJINSHI = 0xfff44336;
@@ -54,16 +46,16 @@ public final class EhUtils {
public static final int BG_COLOR_UNKNOWN = Color.BLACK;
private static final int[] CATEGORY_VALUES = {
- MISC,
- DOUJINSHI,
- MANGA,
- ARTIST_CG,
- GAME_CG,
- IMAGE_SET,
- COSPLAY,
- ASIAN_PORN,
- NON_H,
- WESTERN,
+ EhConfig.MISC,
+ EhConfig.DOUJINSHI,
+ EhConfig.MANGA,
+ EhConfig.ARTIST_CG,
+ EhConfig.GAME_CG,
+ EhConfig.IMAGE_SET,
+ EhConfig.COSPLAY,
+ EhConfig.ASIAN_PORN,
+ EhConfig.NON_H,
+ EhConfig.WESTERN,
UNKNOWN };
private static final String[][] CATEGORY_STRINGS = {
@@ -102,25 +94,25 @@ public final class EhUtils {
public static int getCategoryColor(int category) {
switch (category) {
- case DOUJINSHI:
+ case EhConfig.DOUJINSHI:
return BG_COLOR_DOUJINSHI;
- case MANGA:
+ case EhConfig.MANGA:
return BG_COLOR_MANGA;
- case ARTIST_CG:
+ case EhConfig.ARTIST_CG:
return BG_COLOR_ARTIST_CG;
- case GAME_CG:
+ case EhConfig.GAME_CG:
return BG_COLOR_GAME_CG;
- case WESTERN:
+ case EhConfig.WESTERN:
return BG_COLOR_WESTERN;
- case NON_H:
+ case EhConfig.NON_H:
return BG_COLOR_NON_H;
- case IMAGE_SET:
+ case EhConfig.IMAGE_SET:
return BG_COLOR_IMAGE_SET;
- case COSPLAY:
+ case EhConfig.COSPLAY:
return BG_COLOR_COSPLAY;
- case ASIAN_PORN:
+ case EhConfig.ASIAN_PORN:
return BG_COLOR_ASIAN_PORN;
- case MISC:
+ case EhConfig.MISC:
return BG_COLOR_MISC;
default:
return BG_COLOR_UNKNOWN;
diff --git a/app/src/main/java/com/hippo/ehviewer/util/Config.java b/app/src/main/java/com/hippo/ehviewer/util/Settings.java
similarity index 76%
rename from app/src/main/java/com/hippo/ehviewer/util/Config.java
rename to app/src/main/java/com/hippo/ehviewer/util/Settings.java
index 0785eb821..795bb8e05 100644
--- a/app/src/main/java/com/hippo/ehviewer/util/Config.java
+++ b/app/src/main/java/com/hippo/ehviewer/util/Settings.java
@@ -1,11 +1,11 @@
/*
- * Copyright (C) 2015 Hippo Seven
+ * Copyright 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,64 +21,60 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.hippo.ehviewer.BuildConfig;
-import com.hippo.ehviewer.client.EhClient;
+import com.hippo.ehviewer.client.EhConfig;
+import com.hippo.ehviewer.client.EhUrl;
-public final class Config {
+public final class Settings {
- private static SharedPreferences sConfigPre;
-
- private Config() {
- }
+ private static SharedPreferences sSettingsPre;
public static void initialize(Context context) {
- sConfigPre = PreferenceManager.getDefaultSharedPreferences(context);
+ sSettingsPre = PreferenceManager.getDefaultSharedPreferences(context);
}
public static boolean getBoolean(String key, boolean defValue) {
- return sConfigPre.getBoolean(key, defValue);
+ return sSettingsPre.getBoolean(key, defValue);
}
public static void putBoolean(String key, boolean value) {
- sConfigPre.edit().putBoolean(key, value).apply();
+ sSettingsPre.edit().putBoolean(key, value).apply();
}
public static int getInt(String key, int defValue) {
- return sConfigPre.getInt(key, defValue);
+ return sSettingsPre.getInt(key, defValue);
}
public static void putInt(String key, int value) {
- sConfigPre.edit().putInt(key, value).apply();
+ sSettingsPre.edit().putInt(key, value).apply();
}
public static long getLong(String key, long defValue) {
- return sConfigPre.getLong(key, defValue);
+ return sSettingsPre.getLong(key, defValue);
}
public static void putLong(String key, long value) {
- sConfigPre.edit().putLong(key, value).apply();
+ sSettingsPre.edit().putLong(key, value).apply();
}
public static float getFloat(String key, float defValue) {
- return sConfigPre.getFloat(key, defValue);
+ return sSettingsPre.getFloat(key, defValue);
}
public static void putFloat(String key, float value) {
- sConfigPre.edit().putFloat(key, value).apply();
+ sSettingsPre.edit().putFloat(key, value).apply();
}
public static String getString(String key, String defValue) {
- return sConfigPre.getString(key, defValue);
+ return sSettingsPre.getString(key, defValue);
}
public static void putString(String key, String value) {
- sConfigPre.edit().putString(key, value).apply();
+ sSettingsPre.edit().putString(key, value).apply();
}
- /****** ******/
-
+ /****** EH ******/
private static final String KEY_EH_SOURCE = "eh_source";
- private static final int DEFAULT_EH_SOURCE = BuildConfig.DEBUG ?
- EhClient.SOURCE_EX : EhClient.SOURCE_G;
+ private static final int DEFAULT_EH_SOURCE = EhUrl.SOURCE_G;
private static final String KEY_SIGN_IN = "sign_in";
private static final boolean DEFAULT_SIGN_IN = false;
private static final String KEY_DISPLAY_NAME = "display_name";
@@ -92,14 +88,14 @@ public final class Config {
public static int getEhSource() {
int value = getInt(KEY_EH_SOURCE, DEFAULT_EH_SOURCE);
- if (value < EhClient.SOURCE_G || value > EhClient.SOURCE_LOFI) {
+ if (value < EhUrl.SOURCE_G || value > EhUrl.SOURCE_LOFI) {
value = DEFAULT_EH_SOURCE;
}
return value;
}
public static void putEhSource(int value) {
- if (value < EhClient.SOURCE_G || value > EhClient.SOURCE_LOFI) {
+ if (value < EhUrl.SOURCE_G || value > EhUrl.SOURCE_LOFI) {
value = DEFAULT_EH_SOURCE;
}
putInt(KEY_EH_SOURCE, value);
@@ -152,9 +148,14 @@ public final class Config {
}
}
+ /****** EhConfig ******/
+ private static EhConfig sEhConfig = new EhConfig();
+
+ public static EhConfig getEhConfig() {
+ return sEhConfig;
+ }
/****** Advance ******/
-
private static final String KEY_SHOW_APPLICATION_STATS = "show_application_stats";
private static final boolean DEFAULT_SHOW_APPLICATION_STATS = BuildConfig.DEBUG;
diff --git a/app/src/main/java/com/hippo/ehviewer/widget/CategoryTable.java b/app/src/main/java/com/hippo/ehviewer/widget/CategoryTable.java
index 13a92b7a3..6522ed564 100644
--- a/app/src/main/java/com/hippo/ehviewer/widget/CategoryTable.java
+++ b/app/src/main/java/com/hippo/ehviewer/widget/CategoryTable.java
@@ -25,7 +25,7 @@ import android.view.ViewGroup;
import android.widget.TableLayout;
import com.hippo.ehviewer.R;
-import com.hippo.ehviewer.util.EhUtils;
+import com.hippo.ehviewer.client.EhConfig;
import com.hippo.util.Utils;
import com.hippo.widget.CheckTextView;
@@ -86,16 +86,16 @@ public class CategoryTable extends TableLayout {
* @param category target category
*/
public void setCategory(int category) {
- mDoujinshi.setChecked(!Utils.int2boolean(category & EhUtils.DOUJINSHI), false);
- mManga.setChecked(!Utils.int2boolean(category & EhUtils.MANGA), false);
- mArtistCG.setChecked(!Utils.int2boolean(category & EhUtils.ARTIST_CG), false);
- mGameCG.setChecked(!Utils.int2boolean(category & EhUtils.GAME_CG), false);
- mWestern.setChecked(!Utils.int2boolean(category & EhUtils.WESTERN), false);
- mNonH.setChecked(!Utils.int2boolean(category & EhUtils.NON_H), false);
- mImageSets.setChecked(!Utils.int2boolean(category & EhUtils.IMAGE_SET), false);
- mCosplay.setChecked(!Utils.int2boolean(category & EhUtils.COSPLAY), false);
- mAsianPorn.setChecked(!Utils.int2boolean(category & EhUtils.ASIAN_PORN), false);
- mMisc.setChecked(!Utils.int2boolean(category & EhUtils.MISC), false);
+ mDoujinshi.setChecked(!Utils.int2boolean(category & EhConfig.DOUJINSHI), false);
+ mManga.setChecked(!Utils.int2boolean(category & EhConfig.MANGA), false);
+ mArtistCG.setChecked(!Utils.int2boolean(category & EhConfig.ARTIST_CG), false);
+ mGameCG.setChecked(!Utils.int2boolean(category & EhConfig.GAME_CG), false);
+ mWestern.setChecked(!Utils.int2boolean(category & EhConfig.WESTERN), false);
+ mNonH.setChecked(!Utils.int2boolean(category & EhConfig.NON_H), false);
+ mImageSets.setChecked(!Utils.int2boolean(category & EhConfig.IMAGE_SET), false);
+ mCosplay.setChecked(!Utils.int2boolean(category & EhConfig.COSPLAY), false);
+ mAsianPorn.setChecked(!Utils.int2boolean(category & EhConfig.ASIAN_PORN), false);
+ mMisc.setChecked(!Utils.int2boolean(category & EhConfig.MISC), false);
}
/**
@@ -104,16 +104,16 @@ public class CategoryTable extends TableLayout {
*/
public int getCategory() {
int category = 0;
- if (!mDoujinshi.isChecked()) category |= EhUtils.DOUJINSHI;
- if (!mManga.isChecked()) category |= EhUtils.MANGA;
- if (!mArtistCG.isChecked()) category |= EhUtils.ARTIST_CG;
- if (!mGameCG.isChecked()) category |= EhUtils.GAME_CG;
- if (!mWestern.isChecked()) category |= EhUtils.WESTERN;
- if (!mNonH.isChecked()) category |= EhUtils.NON_H;
- if (!mImageSets.isChecked()) category |= EhUtils.IMAGE_SET;
- if (!mCosplay.isChecked()) category |= EhUtils.COSPLAY;
- if (!mAsianPorn.isChecked()) category |= EhUtils.ASIAN_PORN;
- if (!mMisc.isChecked()) category |= EhUtils.MISC;
+ if (!mDoujinshi.isChecked()) category |= EhConfig.DOUJINSHI;
+ if (!mManga.isChecked()) category |= EhConfig.MANGA;
+ if (!mArtistCG.isChecked()) category |= EhConfig.ARTIST_CG;
+ if (!mGameCG.isChecked()) category |= EhConfig.GAME_CG;
+ if (!mWestern.isChecked()) category |= EhConfig.WESTERN;
+ if (!mNonH.isChecked()) category |= EhConfig.NON_H;
+ if (!mImageSets.isChecked()) category |= EhConfig.IMAGE_SET;
+ if (!mCosplay.isChecked()) category |= EhConfig.COSPLAY;
+ if (!mAsianPorn.isChecked()) category |= EhConfig.ASIAN_PORN;
+ if (!mMisc.isChecked()) category |= EhConfig.MISC;
return category;
}
diff --git a/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java b/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java
index eaddca445..a1063fa92 100644
--- a/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java
+++ b/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java
@@ -30,7 +30,7 @@ import android.widget.TextView;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.rippleold.RippleSalon;
import com.hippo.util.Messenger;
import com.hippo.widget.DrawerListView;
@@ -135,11 +135,11 @@ public class DrawerLeftPanel extends LinearLayout implements FitPaddingImpl {
mUserPanelOriginalPaddingTop = mUserPanel.getPaddingTop();
mDrawerListViewOriginalPaddingBottom = mDrawerListView.getPaddingBottom();
- mSignIn = Config.getSignIn();
+ mSignIn = Settings.getSignIn();
if (mSignIn) {
// TODO
mAvatar.setImageResource(DEFAULT_AVATAR_ID);
- mUsename.setText(Config.getDisplayName());
+ mUsename.setText(Settings.getDisplayName());
mAction.setText(getContext().getString(R.string.signout));
} else {
mAvatar.setImageResource(DEFAULT_AVATAR_ID);
diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
index 9c0f4c445..7f5a2ad7a 100644
--- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
+++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java
@@ -51,8 +51,8 @@ import com.hippo.drawable.DrawerArrowDrawable;
import com.hippo.effect.ViewTransition;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
-import com.hippo.ehviewer.client.EhClient;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.client.EhUrl;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.util.MathUtils;
import com.hippo.util.Messenger;
import com.hippo.util.ViewUtils;
@@ -162,7 +162,7 @@ public class SearchBar extends CardView implements View.OnClickListener,
}
});
- setSource(Config.getEhSource());
+ setSource(Settings.getEhSource());
}
@Override
@@ -192,7 +192,7 @@ public class SearchBar extends CardView implements View.OnClickListener,
Drawable searchImage = resources.getDrawable(R.drawable.ic_search);
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
ssb.append(String.format(resources.getString(R.string.search_bar_hint),
- EhClient.getReadableHost(source)));
+ EhUrl.getReadableHost(source)));
int textSize = (int) (mEditText.getTextSize() * 1.25);
searchImage.setBounds(0, 0, textSize, textSize);
ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
diff --git a/app/src/main/java/com/hippo/network/Cookie.java b/app/src/main/java/com/hippo/network/Cookie.java
deleted file mode 100644
index bd7824b95..000000000
--- a/app/src/main/java/com/hippo/network/Cookie.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2015 Hippo Seven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hippo.network;
-
-import com.hippo.util.Utils;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Cookie {
-
- private static final String KEY_DOMAIN = "domain";
- private static final String KEY_PATH = "path";
- private static final String KEY_EXPIRES = "expires";
-
- private static final String[] UNSUPPORT_KEY = {
- KEY_DOMAIN,
- KEY_PATH,
- KEY_EXPIRES
- };
-
- private Map mItems = new HashMap<>();
-
- public void putRaw(String cookieString) {
- if (cookieString != null) {
- String[] pieces = cookieString.split(";");
- for (String p : pieces) {
- int index = p.indexOf('=');
- if (index != -1) {
- String key = p.substring(0, index).trim();
- String value = p.substring(index + 1).trim();
- if (!Utils.contain(UNSUPPORT_KEY, key)) {
- mItems.put(key, value);
- }
- }
- }
- }
- }
-
- public void put(String key, String value) {
- if (!Utils.contain(UNSUPPORT_KEY, key)) {
- mItems.put(key, value);
- }
- }
-
- public void remove(String key) {
- mItems.remove(key);
- }
-
- public String get(String key) {
- return mItems.get(key);
- }
-
- public String toString() {
- StringBuilder sb = new StringBuilder();
- String separator1 = "; ";
- String separator2 = "=";
- boolean first = true;
-
- for (String key : mItems.keySet()) {
- String value = mItems.get(key);
- if (first) {
- first = false;
- } else {
- sb.append(separator1);
- }
- sb.append(key).append(separator2).append(value);
- }
-
- return sb.toString();
- }
-}
diff --git a/app/src/main/java/com/hippo/network/ResponseCodeException.java b/app/src/main/java/com/hippo/network/ResponseCodeException.java
deleted file mode 100644
index 5eabfc9ea..000000000
--- a/app/src/main/java/com/hippo/network/ResponseCodeException.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2015 Hippo Seven
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.hippo.network;
-
-import android.util.SparseArray;
-
-public class ResponseCodeException extends Exception {
-
- private static final SparseArray ERROR_MESSAGE_ARRAY;
- private static final String DEFAULT_ERROR_MESSAGE = "Error response code";
-
- private final int mResponseCode;
- private final String mMessage;
-
- static {
- ERROR_MESSAGE_ARRAY = new SparseArray<>(24);
-
- ERROR_MESSAGE_ARRAY.append(400, "Bad Request");
- ERROR_MESSAGE_ARRAY.append(401, "Unauthorized");
- ERROR_MESSAGE_ARRAY.append(402, "Payment Required");
- ERROR_MESSAGE_ARRAY.append(403, "Forbidden");
- ERROR_MESSAGE_ARRAY.append(404, "Not Found");
- ERROR_MESSAGE_ARRAY.append(405, "Method Not Allowed");
- ERROR_MESSAGE_ARRAY.append(406, "Not Acceptable");
- ERROR_MESSAGE_ARRAY.append(407, "Proxy Authentication Required");
- ERROR_MESSAGE_ARRAY.append(408, "Request Timeout");
- ERROR_MESSAGE_ARRAY.append(409, "Conflict");
- ERROR_MESSAGE_ARRAY.append(410, "Gone");
- ERROR_MESSAGE_ARRAY.append(411, "Length Required");
- ERROR_MESSAGE_ARRAY.append(412, "Precondition Failed");
- ERROR_MESSAGE_ARRAY.append(413, "Request Entity Too Large");
- ERROR_MESSAGE_ARRAY.append(414, "Request-URI Too Long");
- ERROR_MESSAGE_ARRAY.append(415, "Unsupported Media Type");
- ERROR_MESSAGE_ARRAY.append(416, "Requested Range Not Satisfiable");
- ERROR_MESSAGE_ARRAY.append(417, "Expectation Failed");
-
- ERROR_MESSAGE_ARRAY.append(500, "Internal Server Error");
- ERROR_MESSAGE_ARRAY.append(501, "Not Implemented");
- ERROR_MESSAGE_ARRAY.append(502, "Bad Gateway");
- ERROR_MESSAGE_ARRAY.append(503, "Service Unavailable");
- ERROR_MESSAGE_ARRAY.append(504, "Gateway Timeout");
- ERROR_MESSAGE_ARRAY.append(505, "HTTP Version Not Supported");
- }
-
- public ResponseCodeException(int responseCode) {
- mResponseCode = responseCode;
- mMessage = ERROR_MESSAGE_ARRAY.get(responseCode, DEFAULT_ERROR_MESSAGE);
- }
-
- public ResponseCodeException(int responseCode, String message) {
- mResponseCode = responseCode;
- mMessage = message;
- }
-
- public int getResponseCode() {
- return mResponseCode;
- }
-
- public boolean isIdentifiedResponseCode() {
- return !DEFAULT_ERROR_MESSAGE.equals(mMessage);
- }
-
- @Override
- public String getMessage() {
- return mMessage;
- }
-
- @Override
- public String getLocalizedMessage() {
- return getMessage();
- }
-
-}
diff --git a/app/src/main/java/com/hippo/scene/preference/ListPreference.java b/app/src/main/java/com/hippo/scene/preference/ListPreference.java
index ce7fa8afc..df3a34181 100644
--- a/app/src/main/java/com/hippo/scene/preference/ListPreference.java
+++ b/app/src/main/java/com/hippo/scene/preference/ListPreference.java
@@ -19,7 +19,7 @@ package com.hippo.scene.preference;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Settings;
import com.hippo.scene.Scene;
import com.hippo.scene.SimpleDialog;
@@ -62,7 +62,7 @@ public class ListPreference extends Preference {
}
private int getValuePosition() {
- return getValuePosition(Config.getInt(getKey(), mDefaultValue));
+ return getValuePosition(Settings.getInt(getKey(), mDefaultValue));
}
private int getValuePosition(int value) {
@@ -77,7 +77,7 @@ public class ListPreference extends Preference {
@Override
protected void storeValue(Object newValue) {
- Config.putInt(getKey(), (Integer) newValue);
+ Settings.putInt(getKey(), (Integer) newValue);
}
@Override
diff --git a/app/src/main/java/com/hippo/scene/preference/SwitchPreference.java b/app/src/main/java/com/hippo/scene/preference/SwitchPreference.java
index 75b48b025..127939699 100644
--- a/app/src/main/java/com/hippo/scene/preference/SwitchPreference.java
+++ b/app/src/main/java/com/hippo/scene/preference/SwitchPreference.java
@@ -24,7 +24,7 @@ import android.view.LayoutInflater;
import android.widget.FrameLayout;
import com.hippo.ehviewer.R;
-import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Settings;
public class SwitchPreference extends Preference {
@@ -59,7 +59,7 @@ public class SwitchPreference extends Preference {
}
private boolean getValue() {
- return Config.getBoolean(getKey(), mDefaultValue);
+ return Settings.getBoolean(getKey(), mDefaultValue);
}
private SwitchCompat getSwitch(RecyclerView.ViewHolder viewHolder) {
@@ -68,7 +68,7 @@ public class SwitchPreference extends Preference {
@Override
protected void storeValue(Object newValue) {
- Config.putBoolean(getKey(), (Boolean) newValue);
+ Settings.putBoolean(getKey(), (Boolean) newValue);
}
@Override
diff --git a/app/src/main/java/com/hippo/util/ExceptionUtils.java b/app/src/main/java/com/hippo/util/ExceptionUtils.java
index 1ee98cc0b..74d853464 100644
--- a/app/src/main/java/com/hippo/util/ExceptionUtils.java
+++ b/app/src/main/java/com/hippo/util/ExceptionUtils.java
@@ -23,7 +23,7 @@ import android.support.annotation.Nullable;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhException;
-import com.hippo.network.ResponseCodeException;
+import com.hippo.httpclient.ResponseCodeException;
import org.apache.http.conn.ConnectTimeoutException;
diff --git a/app/src/main/res/layout/item_gallery_list_detail.xml b/app/src/main/res/layout/item_gallery_list_detail.xml
index 917cb53e9..83a712401 100644
--- a/app/src/main/res/layout/item_gallery_list_detail.xml
+++ b/app/src/main/res/layout/item_gallery_list_detail.xml
@@ -19,6 +19,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ auto:cardElevation="4dp"
auto:forceNoElevation="true">
| |