diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java index 6633b8ffa..46fa942d4 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -20,9 +20,10 @@ import android.os.AsyncTask; import android.os.Process; import com.hippo.ehviewer.client.data.GalleryApiDetail; -import com.hippo.ehviewer.client.data.GalleryInfo; +import com.hippo.ehviewer.client.data.GalleryWithJpnTitle; import com.hippo.ehviewer.network.EhHttpRequest; import com.hippo.httpclient.HttpClient; +import com.hippo.httpclient.HttpRequest; import com.hippo.yorozuya.PriorityThreadFactory; import java.util.List; @@ -126,6 +127,22 @@ public final class EhClient { */ public static final int METHOD_GET_POPULAR = 3; + /** + * Get popular + * + * + * + * + * + * + * + * + * + * + *
paraminfo
listenerthe listener for callback
+ */ + public static final int METHOD_GET_POPULAR_JPN = 4; + /** * Get gallery detail * @@ -149,7 +166,7 @@ public final class EhClient { * * */ - public static final int METHOD_GET_GALLERY_DETAIL = 4; + public static final int METHOD_GET_GALLERY_DETAIL = 5; /** * Get gallery preview set @@ -174,7 +191,7 @@ public final class EhClient { * * */ - public static final int METHOD_GET_PREVIEW_SET = 5; + public static final int METHOD_GET_PREVIEW_SET = 6; private final ThreadPoolExecutor mRequestThreadPool; @@ -245,6 +262,29 @@ public final class EhClient { } } + private void fillJpnTitle(HttpRequest httpRequest, List list, int source) throws Exception { + int length = list.size(); + int[] gids = new int[length]; + String[] tokens = new String[length]; + for (int i = 0; i < length; i++) { + GalleryWithJpnTitle gi = list.get(i); + gids[i] = gi.gid; + tokens[i] = gi.token; + } + + List galleryApiDetails = EhEngine.getGalleryApiDetail( + mHttpClient, httpRequest, gids, tokens, source); + + for (int i = 0; i < length; i++) { + GalleryWithJpnTitle gi = list.get(i); + GalleryApiDetail gad = galleryApiDetails.get(i); + if (gi.gid == gad.gid) { + gi.titleJpn = gad.titleJpn; + } + } + } + + @SuppressWarnings("unchecked") @Override protected Object doInBackground(Object... params) { try { @@ -253,35 +293,24 @@ public final class EhClient { return EhEngine.signIn(mHttpClient, mEhHttpRequest, (String) params[0], (String) params[1]); case METHOD_GET_GALLERY_LIST: return EhEngine.getGalleryList(mHttpClient, mEhHttpRequest, (String) params[0], (Integer) params[1]); - case METHOD_GET_GALLERY_LIST_JPN: - GalleryListParser.Result result = EhEngine.getGalleryList( - mHttpClient, mEhHttpRequest, (String) params[0], (Integer) params[1]); + case METHOD_GET_GALLERY_LIST_JPN: { + GalleryListParser.Result result = EhEngine.getGalleryList(mHttpClient, mEhHttpRequest, (String) params[0], (Integer) params[1]); mEhHttpRequest.clear(); - List galleryInfos = result.galleryInfos; - int length = galleryInfos.size(); - int[] gids = new int[length]; - String[] tokens = new String[length]; - for (int i = 0; i < length; i++) { - GalleryInfo gi = galleryInfos.get(i); - gids[i] = gi.gid; - tokens[i] = gi.token; - } - - List galleryApiDetails = EhEngine.getGalleryApiDetail( - mHttpClient, mEhHttpRequest, gids, tokens, (Integer) params[1]); - - for (int i = 0; i < length; i++) { - GalleryInfo gi = galleryInfos.get(i); - GalleryApiDetail gad = galleryApiDetails.get(i); - if (gi.gid == gad.gid) { - gi.titleJpn = gad.titleJpn; - } - } + fillJpnTitle(mEhHttpRequest, (List) result.galleryInfos, (Integer) params[1]); return result; + } case METHOD_GET_POPULAR: return EhEngine.getPopular(mHttpClient, mEhHttpRequest); + case METHOD_GET_POPULAR_JPN: { + PopularParser.Result result = EhEngine.getPopular(mHttpClient, mEhHttpRequest); + + mEhHttpRequest.clear(); + fillJpnTitle(mEhHttpRequest, (List) result.galleryInfos, (Integer) params[0]); + + return result; + } case METHOD_GET_GALLERY_DETAIL: return EhEngine.getGalleryDetail(mHttpClient, mEhHttpRequest, (String) params[0], (Integer) params[1]); case METHOD_GET_PREVIEW_SET: diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 592abf902..2e3b3b4c2 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -24,7 +24,6 @@ import com.hippo.httpclient.HttpClient; import com.hippo.httpclient.HttpRequest; import com.hippo.httpclient.HttpResponse; import com.hippo.httpclient.JsonPoster; -import com.hippo.yorozuya.Say; import org.json.JSONArray; import org.json.JSONObject; @@ -177,15 +176,8 @@ class EhEngine { json.put("gidlist", ja); httpRequest.setUrl(getApiUrl(source)); httpRequest.setHttpImpl(new JsonPoster(json)); - - Say.f("EhEngine", json.toString()); - HttpResponse response = httpClient.execute(httpRequest); String body = response.getString(); - - Say.f("EhEngine", body); - - List list = GalleryApiParser.parse(body); if (list.size() != gids.length) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java b/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java index edfab2935..6990cac40 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java @@ -57,6 +57,9 @@ public class GalleryDetailParser { public static final int REQUEST_PREVIEW = 0x8; public static final int REQUEST_COMMENT = 0x10; + // TODO Can't Sort comment it like this, + // If the comment is modified, this time is modifing time. + // Leave it to cookie private static final CommentSort COMMENT_SORTER = new CommentSort(); public static GalleryDetail parse(String body, int source, int request) throws Exception { @@ -113,18 +116,18 @@ public class GalleryDetailParser { + ".+?" + "]*onclick=\"return popUp\\('([^']+)'[^)]+\\)\">Torrent Download \\( (\\d+) \\)" // 6 torrentUrl, 7 torrentCount + ".+?" - + "
]+><[^<>]*alt=\"([\\w|\\-]+)\"[^<>]*>
" // 8 category + + "
]+><[^<>]*alt=\"([\\w\\-]+)\"[^<>]*>
" // 8 category + "
]+>([^<>]+)" // 9 uploader + ".+?" - + "]*>Posted:]*>([\\w|\\-|\\s|:]+)" // 10 posted + + "]*>Posted:]*>([\\w\\-\\s:]+)" // 10 posted + "]*>Parent:]*>(?:]*>)?([^<>]+)(?:)?" // 11 parent + "]*>Visible:]*>([^<>]+)" // 12 visible + "]*>Language:]*>([^<>]+)(?:]*>[^<>]*)?" // 13 language + "]*>File Size:]*>([^<>]+)(?:]*>([^<>]+))?" // 14 File size, 15 resize - + "]*>Length:]*>([\\d|,]+) pages" // 16 pageCount - + "]*>Favorited:<[^<>]*>([^<>]+)" // 17 Favorite times "([\d|,]+) times" or "Once" or "Never" + + "]*>Length:]*>([\\d,]+) pages" // 16 pageCount + + "]*>Favorited:<[^<>]*>([^<>]+)" // 17 Favorite times "([\d,]+) times" or "Once" or "Never" + ".+?" - + "([\\d|,]+)" // 18 ratedTimes + + "([\\d,]+)" // 18 ratedTimes + "" + "]*>([^<>]+)" // 19 rating "Average: x.xx" or "Not Yet Rated" + ".+?" diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryBase.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryBase.java index 682a3b06e..0587c917a 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryBase.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryBase.java @@ -21,7 +21,7 @@ import java.text.SimpleDateFormat; import java.util.Locale; import java.util.TimeZone; -public class GalleryBase { +public abstract class GalleryBase { public static final DateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US); diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java index 27d1b6dc1..749f5e271 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java @@ -18,7 +18,7 @@ package com.hippo.ehviewer.client.data; import java.util.regex.Pattern; -public class GalleryInfo extends GalleryBase { +public class GalleryInfo extends GalleryWithJpnTitle { /** * ISO 639-1 @@ -74,8 +74,6 @@ public class GalleryInfo extends GalleryBase { "[(\\[]dutch[)\\]]", }; - public String titleJpn; - /** * Will not be recond */ diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryWithJpnTitle.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryWithJpnTitle.java new file mode 100644 index 000000000..e28362bce --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryWithJpnTitle.java @@ -0,0 +1,22 @@ +/* + * 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.data; + +public abstract class GalleryWithJpnTitle extends GalleryBase { + + public String titleJpn; +} diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java b/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java index 34d328ae8..9513f26e8 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java @@ -18,7 +18,5 @@ package com.hippo.ehviewer.client.data; public class LofiGalleryInfo extends GalleryInfo { - public String titleJpn; - public String[] tags; } 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 10ba3302e..ebcec3055 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 @@ -913,18 +913,20 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper, protected void getPageData(int taskId, int type, int page) { EhClient client = EhApplication.getEhClient(getStageActivity()); + int source = Settings.getEhSource(); int mode = mListUrlBuilder.getMode(); if (mode == ListUrlBuilder.MODE_POPULAR) { PopularListener listener = new PopularListener(taskId); listener.setGalleryListHelper(this); mListener = listener; EhRequest request = new EhRequest(); - request.setMethod(EhClient.METHOD_GET_POPULAR); + request.setMethod(mJpnTitle ? + EhClient.METHOD_GET_POPULAR_JPN : EhClient.METHOD_GET_POPULAR); request.setEhListener(listener); + request.setArgs(source); client.execute(request); } else { try { - int source = Settings.getEhSource(); mListUrlBuilder.setPageIndex(page); String url = mListUrlBuilder.build(source); GalleryListListener listener = new GalleryListListener(taskId,