From ab9b7e59d9865a52aed7f6d3d8e75084bc15078e Mon Sep 17 00:00:00 2001 From: seven332 Date: Wed, 23 Jul 2014 11:15:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20lofi=20=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/values-zh-rCN/strings.xml | 2 +- res/values-zh-rHK/strings.xml | 2 +- res/values-zh-rTW/strings.xml | 2 +- res/values/strings.xml | 2 +- .../hippo/ehviewer/GallerysDownloader.java | 2 +- src/com/hippo/ehviewer/ListUrls.java | 95 +++--- src/com/hippo/ehviewer/data/GalleryInfo.java | 9 +- .../hippo/ehviewer/data/LofiGalleryInfo.java | 70 +++++ src/com/hippo/ehviewer/ehclient/EhClient.java | 286 ++++++++++++------ src/com/hippo/ehviewer/ehclient/EhInfo.java | 99 +++--- .../hippo/ehviewer/ehclient/ListParser.java | 223 ++++++++++---- .../hippo/ehviewer/network/HttpHelper.java | 2 +- .../ehviewer/ui/AbstractGalleryActivity.java | 60 +++- .../ehviewer/ui/DetailSectionFragment.java | 4 +- .../hippo/ehviewer/ui/FavouriteActivity.java | 13 +- .../ehviewer/ui/MangaDetailActivity.java | 10 +- .../hippo/ehviewer/ui/MangaListActivity.java | 46 +-- src/com/hippo/ehviewer/util/Config.java | 40 +-- .../ehviewer/widget/RefreshTextView.java | 34 ++- 19 files changed, 663 insertions(+), 338 deletions(-) create mode 100644 src/com/hippo/ehviewer/data/LofiGalleryInfo.java diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index b6fe9a383..6e9bd6387 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -64,7 +64,7 @@ 切换至标签搜索模式 - 第 %d 页,共 %d 页 + 第 %d 页,共 %s 页 跳至: 非法页面 diff --git a/res/values-zh-rHK/strings.xml b/res/values-zh-rHK/strings.xml index b5ffbb884..85d38217b 100644 --- a/res/values-zh-rHK/strings.xml +++ b/res/values-zh-rHK/strings.xml @@ -52,7 +52,7 @@ 切換至標籤搜索模式 - 第 %d 頁,共 %d 頁 + 第 %d 頁,共 %s 頁 跳至: 非法頁面 diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml index d628d17bb..dd6b146fc 100644 --- a/res/values-zh-rTW/strings.xml +++ b/res/values-zh-rTW/strings.xml @@ -52,7 +52,7 @@ 切換至標籤搜索模式 - 第 %d 頁,共 %d 頁 + 第 %d 頁,共 %s 頁 跳至: 非法頁面 diff --git a/res/values/strings.xml b/res/values/strings.xml index b1f247d45..6706ab077 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -66,7 +66,7 @@ Switch To Tag Search Mode - Page %d, %d pages in total + Page %d, %s pages in total Jump to : Invalid page diff --git a/src/com/hippo/ehviewer/GallerysDownloader.java b/src/com/hippo/ehviewer/GallerysDownloader.java index b37abf382..81c100212 100644 --- a/src/com/hippo/ehviewer/GallerysDownloader.java +++ b/src/com/hippo/ehviewer/GallerysDownloader.java @@ -96,7 +96,7 @@ public class GallerysDownloader implements Runnable { dp.reset(); // For get more page url one time hh.setPreviewMode(Config.PREVIEW_MODE_NORMAL); - String body = hh.get(EhClient.getDetailUrl(mGalleryInfo.gid, mGalleryInfo.token, page)); + String body = hh.get(EhClient.getDetailUrl(mGalleryInfo.gid, mGalleryInfo.token, page, Config.getMode())); if (body == null) continue; diff --git a/src/com/hippo/ehviewer/ListUrls.java b/src/com/hippo/ehviewer/ListUrls.java index 785cd2d83..d056649de 100644 --- a/src/com/hippo/ehviewer/ListUrls.java +++ b/src/com/hippo/ehviewer/ListUrls.java @@ -19,16 +19,17 @@ package com.hippo.ehviewer; import java.io.UnsupportedEncodingException; import com.hippo.ehviewer.ehclient.EhClient; +import com.hippo.ehviewer.util.Config; public class ListUrls { - - public static final boolean NUM_CATEGORY = true; - + + public static final boolean NUM_CATEGORY = false; + public static final int NORMAL = 0x0; public static final int UPLOADER = 0x1; public static final int TAG = 0x2; public static final int POPULAR = 0x3; - + // Search type public static final int MISC = 0x1; public static final int DOUJINSHI = 0x2; @@ -41,10 +42,10 @@ public class ListUrls { public static final int NON_H = 0x100; public static final int WESTERN = 0x200; public static final int UNKNOWN = 0x400; - + public static final int ALL_TYPE = UNKNOWN - 1; //DOUJINSHI|MANGA|ARTIST_CG|GAME_CG|WESTERN|NON_H|IMAGE_SET|COSPLAY|ASIAN_PORN|MISC; - + // advance search type public static final int SNAME = 0x1; public static final int STAGS = 0x2; @@ -54,117 +55,121 @@ public class ListUrls { public static final int STD1 = 0x20; public static final int STD2 = 0x40; public static final int SH = 0x80; - + public static final int DEFAULT_ADVANCE = SNAME | STAGS; public static final int DEFAULT_MIN_RATING = 2; - + private int mMode = NORMAL; - + private int page = 0; private int type = ALL_TYPE; - + private int advsearchType = -1; private int minRating = -1; - + private String search = null; - + private String mTag = null; - + public ListUrls() {} - + public ListUrls(int t) { type = t; page = 0; } - + public ListUrls(int t, int p) { type = t; page = p; } - + public ListUrls(int t, String s) { type = t; search = s; } - + public ListUrls(int t, String s, int p) { type = t; search = s; page = p; } - + public void setType(int type) { this.type = type; } - + public int getType() { return type; } - + public String getSearch() { return search; } - + public void setAdvance(boolean enabled) { if (enabled && advsearchType == -1) advsearchType = DEFAULT_ADVANCE; else if (!enabled) advsearchType = -1; } - + public void setAdvance(int advanceType) { advsearchType = advanceType; } - + public void setAdvance(int advanceType, int minRating) { advsearchType = advanceType; this.minRating = minRating; } - + public boolean isAdvance() { return advsearchType != -1; } - + public int getAdvanceType() { return advsearchType; } - + public boolean isMinRating() { return minRating != -1; } - + public int getMinRating() { return minRating; } - + public void setPage(int p) { page = p; } - + public int getPage() { return page; } - + public int getMode() { return mMode; } - + public void setMode(int mode) { mMode = mode; } - + public void setTag(String tag) { mMode = TAG; mTag = tag; } - + public String getTag() { return mTag; } - + public String getUrl() { - StringBuilder url = new StringBuilder(EhClient.getUrlHeader()); - + return getUrl(Config.getMode()); + } + + public String getUrl(int mode) { + StringBuilder url = new StringBuilder(EhClient.getUrlHeader(mode)); + if (mMode == TAG) { // Add tag url.append("tag/"); @@ -183,15 +188,15 @@ public class ListUrls { url.append('+'); url.append(searcheItem); } - + // Add page url.append("/").append(page); } else url.append(page); } else if (mMode == POPULAR) { - + } else { - + // Add type if (NUM_CATEGORY) { url.append(type); @@ -239,7 +244,7 @@ public class ListUrls { else url.append("f_misc=1&"); } - + // Add search if (search != null) { url.append("f_search="); @@ -259,13 +264,13 @@ public class ListUrls { } url.append("&"); } - + // Add page url.append("page=").append(page).append("&"); - + // Add foot url.append("f_apply=Apply+Filter"); - + // Is advance search if (isAdvance()) { url.append("&advsearch=1"); @@ -285,13 +290,13 @@ public class ListUrls { url.append("&f_sdt2=on"); if((advsearchType & SH) != 0) url.append("&f_sh=on"); - + // Set min star if (isMinRating()) url.append("&f_sr=on&f_srdd=").append(minRating); } } - + return url.toString(); } } diff --git a/src/com/hippo/ehviewer/data/GalleryInfo.java b/src/com/hippo/ehviewer/data/GalleryInfo.java index 24e95a7fd..8be9bc564 100644 --- a/src/com/hippo/ehviewer/data/GalleryInfo.java +++ b/src/com/hippo/ehviewer/data/GalleryInfo.java @@ -19,7 +19,8 @@ package com.hippo.ehviewer.data; import android.os.Parcel; import android.os.Parcelable; -public class GalleryInfo implements Parcelable{ +public class GalleryInfo implements Parcelable { + public int gid; public String token; public String title; @@ -28,7 +29,7 @@ public class GalleryInfo implements Parcelable{ public String thumb; public String uploader; public float rating; - + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override @@ -50,12 +51,12 @@ public class GalleryInfo implements Parcelable{ return new GalleryInfo[size]; } }; - + @Override public int describeContents() { return 0; } - + @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(gid); diff --git a/src/com/hippo/ehviewer/data/LofiGalleryInfo.java b/src/com/hippo/ehviewer/data/LofiGalleryInfo.java new file mode 100644 index 000000000..184f2774f --- /dev/null +++ b/src/com/hippo/ehviewer/data/LofiGalleryInfo.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2014 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.data; + +import android.os.Parcel; +import android.os.Parcelable; + +public class LofiGalleryInfo extends GalleryInfo { + + /** + * It could be null, please check before use. + */ + public String[] lofiTags; + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public LofiGalleryInfo createFromParcel(Parcel source) { + int length; + + LofiGalleryInfo p = new LofiGalleryInfo(); + p.gid = source.readInt(); + p.token = source.readString(); + p.title = source.readString(); + p.posted = source.readString(); + p.category = source.readInt(); + p.thumb = source.readString(); + p.uploader = source.readString(); + p.rating = source.readFloat(); + + length = source.readInt(); + if (length > 0) { + p.lofiTags = new String[length]; + for (int i = 0; i < length; i++) + p.lofiTags[i] = source.readString(); + } + + return p; + } + + @Override + public LofiGalleryInfo[] newArray(int size) { + return new LofiGalleryInfo[size]; + } + }; + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + + int length = lofiTags == null ? 0 : lofiTags.length; + dest.writeInt(length); + for (int i = 0; i < length; i++) + dest.writeString(lofiTags[i]); + } +} diff --git a/src/com/hippo/ehviewer/ehclient/EhClient.java b/src/com/hippo/ehviewer/ehclient/EhClient.java index 822fe0b51..c61ce3c11 100644 --- a/src/com/hippo/ehviewer/ehclient/EhClient.java +++ b/src/com/hippo/ehviewer/ehclient/EhClient.java @@ -34,6 +34,7 @@ import android.os.Message; import com.hippo.ehviewer.Analytics; import com.hippo.ehviewer.AppContext; +import com.hippo.ehviewer.AppHandler; import com.hippo.ehviewer.ListUrls; import com.hippo.ehviewer.R; import com.hippo.ehviewer.data.Comment; @@ -62,25 +63,23 @@ public class EhClient { public static final int FAVORITE_SLOT_NUM = 10; - public static final int G = 0x0; - public static final int EX = 0x1; - public static final int LOFI_460x = 0x2; - public static final int LOFI_780x = 0x3; - public static final int LOFI_980x = 0x4; + public static final int MODE_G = 0x0; + public static final int MODE_EX = 0x1; + public static final int MODE_LOFI = 0x2; - public static final String G_API = "http://g.e-hentai.org/api.php"; - public static final String EX_API = "http://exhentai.org/api.php"; + public static final String API_G = "http://g.e-hentai.org/api.php"; + public static final String API_EX = "http://exhentai.org/api.php"; public static final long APIUID = 1363542; public static final String APIKEY = "f4b5407ab1727b9d08d7"; - private static final String loginUrl = "http://forums.e-hentai.org/index.php?act=Login&CODE=01"; - private static final String forumsUrl = "http://forums.e-hentai.org/index.php"; + private static final String LOGIN_URL = "http://forums.e-hentai.org/index.php?act=Login&CODE=01"; + private static final String FORUMS_URL = "http://forums.e-hentai.org/index.php"; - public static final String G_HEADER = "http://g.e-hentai.org/"; - public static final String EX_HEADER = "http://exhentai.org/"; - public static final String LOFI_HEADER = "http://lofi.e-hentai.org/"; + public static final String HEADER_G = "http://g.e-hentai.org/"; + public static final String HEADER_EX = "http://exhentai.org/"; + public static final String HEADER_LOFI = "http://lofi.e-hentai.org/"; - private static final String EHVIEWER_API = "http://www.ehviewer.com/API"; + private static final String API_EHVIEWER = "http://www.ehviewer.com/API"; /* Avatar get code */ public static final int GET_AVATAR_OK = 0x0; @@ -89,6 +88,7 @@ public class EhClient { private final AppContext mAppContext; private final ThreadPool mThreadPool; + private final Handler mHandler; private final EhInfo mInfo; public static String getUrlHeader() { @@ -97,80 +97,113 @@ public class EhClient { public static String getUrlHeader(int mode) { switch (mode) { - case EX: - return EX_HEADER; - case LOFI_460x: - case LOFI_780x: - case LOFI_980x: - return LOFI_HEADER; + case MODE_EX: + return HEADER_EX; + case MODE_LOFI: + return HEADER_LOFI; + case MODE_G: default: - return G_HEADER; + return HEADER_G; } } - public static String getDetailUrl(int gid, String token) { - return getDetailUrl(gid, token, 0, Config.getMode()); + /** + * Get gellary detail url in default mode + * @param gid + * @param token + * @return + */ + public String getDetailUrl(int gid, String token) { + return getDetailUrl(gid, token, 0, mInfo.getMode()); } - - public static String getDetailUrl(int gid, String token, int pageNum) { - return getDetailUrl(gid, token, pageNum, Config.getMode()); + /** + * Get gellary detail url in default mode + * @param gid + * @param token + * @return + */ + public String getDetailUrl(int gid, String token, int pageNum) { + return getDetailUrl(gid, token, pageNum, mInfo.getMode()); } + /** + * Get gellary detail url in target mode + * @param gid + * @param token + * @return + */ public static String getDetailUrl(int gid, String token, int pageNum, int mode) { + StringBuilder sb = new StringBuilder(); switch (mode) { - case EX: - return EX_HEADER + "g/" + gid + "/" + token + "/?p=" + pageNum; - case LOFI_460x: - case LOFI_780x: - case LOFI_980x: - return LOFI_HEADER + "g/" + gid + "/" + token + "/?p=" + pageNum; + case MODE_EX: + sb.append(HEADER_EX); + break; + case MODE_LOFI: + sb.append(HEADER_LOFI); + break; + case MODE_G: default: - return G_HEADER + "g/" + gid + "/" + token + "/?p=" + pageNum; + sb.append(HEADER_G); + break; } + return sb.append("g/").append(gid).append("/").append(token) + .append("/?p=").append(pageNum).toString(); } - public static String getPageUrl(String gid, String token, int pageNum) { - return getPageUrl(gid, token, pageNum, Config.getMode()); + public String getPageUrl(String gid, String token, int pageNum) { + return getPageUrl(gid, token, pageNum, mInfo.getMode()); } public static String getPageUrl(String gid, String token, int pageNum, int mode) { + StringBuilder sb = new StringBuilder(); switch (mode) { - case EX: - return EX_HEADER + "s/" + token + "/" + gid + "-" + pageNum; - case LOFI_460x: - case LOFI_780x: - case LOFI_980x: - return LOFI_HEADER + "s/" + token + "/" + gid + "-" + pageNum; + case MODE_EX: + sb.append(HEADER_EX); + break; + case MODE_LOFI: + sb.append(HEADER_LOFI); + break; + case MODE_G: default: - return G_HEADER + "s/" + token + "/" + gid + "-" + pageNum; + sb.append(HEADER_G); + break; } + return sb.append("s/").append(token).append("/").append(gid) + .append("-").append(pageNum).toString(); } - public static String getApiUrl() { - return getApiUrl(Config.getMode()); + public String getApiUrl() { + return getApiUrl(mInfo.getAPIMode()); } public static String getApiUrl(int mode) { switch (mode) { - case EX: - return EX_API; + case MODE_EX: + return API_EX; + case MODE_G: default: - return G_API; + return API_G; } } - public static String getFavoriteUrl(int index, int page) { - return getFavoriteUrl(Config.getMode(), index, page); + public String getFavoriteUrl(int index, int page) { + return getFavoriteUrl(mInfo.getAPIMode(), index, page); } public static String getFavoriteUrl(int mode, int index, int page) { + StringBuilder sb = new StringBuilder(); switch (mode) { - case EX: - return EX_HEADER + "favorites.php?favcat=" + index + "&page=" + page; + case MODE_EX: + sb.append(HEADER_EX); + break; + case MODE_G: default: - return G_HEADER + "favorites.php?favcat=" + index + "&page=" + page; + sb.append(HEADER_G); + break; } + return sb.append("favorites.php?favcat=").append(index).append("&page=") + .append(page).toString(); } public interface OnGetMangaUrlListener { @@ -196,6 +229,7 @@ public class EhClient { public EhClient(AppContext appContext) { mAppContext = appContext; mThreadPool = mAppContext.getNetworkThreadPool(); + mHandler = AppHandler.getInstance(); mInfo = EhInfo.getInstance(appContext); } @@ -235,10 +269,9 @@ public class EhClient { return mInfo.getAvatar(); } - private static final int GET_PAGE_LIST = 0x5; private static final int GET_MANGA_URL = 0x6; - private static Handler mHandler = new Handler() { + private static Handler mHandler1 = new Handler() { @Override public void handleMessage(Message msg) { @@ -287,7 +320,7 @@ public class EhClient { listener.onFailure(eMsg); } }); - hp.postForm(loginUrl, new String[][] { + hp.postForm(LOGIN_URL, new String[][] { new String[] { "UserName", username }, new String[] { "PassWord", password }, new String[] { "submit", "Log me in" }, @@ -306,7 +339,7 @@ public class EhClient { Matcher m; // Get user profile url HttpHelper hp = new HttpHelper(mAppContext); - body = hp.get(forumsUrl); + body = hp.get(FORUMS_URL); if (body == null) { listener.onGetAvatar(GET_AVATAR_ERROR); return; @@ -346,45 +379,91 @@ public class EhClient { // Get Gallery List public interface OnGetGListListener { - public void onSuccess(Object checkFlag, List lmdArray, - int indexPerPage, int maxPage); + public void onSuccess(Object checkFlag, List giList, + int maxPage); public void onFailure(Object checkFlag, String eMsg); } - public void getGList(final String url, final Object checkFlag, + private class GetGListResponder implements Runnable { + + private final boolean isOk; + private final OnGetGListListener listener; + private final Object checkFlag; + private final List giList; + private final int maxPage; + private final String eMesg; + + public GetGListResponder(OnGetGListListener listener, Object checkFlag, + List giList, int maxPage) { + this.isOk = true; + this.listener = listener; + this.checkFlag = checkFlag; + this.giList = giList; + this.maxPage = maxPage; + this.eMesg = null; + } + + public GetGListResponder(OnGetGListListener listener, Object checkFlag, String eMesg) { + this.isOk = false; + this.listener = listener; + this.checkFlag = checkFlag; + this.giList = null; + this.maxPage = 0; + this.eMesg = eMesg; + } + + @Override + public void run() { + if (isOk) + listener.onSuccess(checkFlag, giList, maxPage); + else + listener.onFailure(checkFlag, eMesg); + } + } + + public void getGList(String url, Object checkFlag, + OnGetGListListener listener) { + getGList(url, mInfo.getMode(), checkFlag, listener); + } + + public void getGList(final String url, final int mode, final Object checkFlag, final OnGetGListListener listener) { new Thread(new Runnable() { @Override public void run() { HttpHelper hp = new HttpHelper(mAppContext); - hp.setOnRespondListener(new HttpHelper.OnRespondListener() { - @Override - public void onSuccess(Object obj) { - String body = (String)obj; - // If no element, it might be a notice - if (!body.contains("<")) { - listener.onFailure(checkFlag, body); - return; - } - ListParser parser = new ListParser(); - switch (parser.parser(body)) { + String body = hp.get(url); + GetGListResponder responder; + if (body != null) { // Get ok + // If no element, it might be a notice + if (!body.contains("<")) { + responder = new GetGListResponder(listener, checkFlag, body); + } else { + final ListParser parser = new ListParser(); + switch (parser.parser(body, mode)) { case ListParser.ALL: - listener.onSuccess(checkFlag, parser.giList, parser.indexPerPage, parser.maxPage); + responder = new GetGListResponder(listener, checkFlag, + parser.giList, parser.pageNum); break; case ListParser.NOT_FOUND: - listener.onSuccess(checkFlag, new ArrayList(), parser.indexPerPage, 0); + responder = new GetGListResponder(listener, checkFlag, + parser.giList, 0); + break; + case ListParser.INDEX_ERROR: + responder = new GetGListResponder(listener, checkFlag, + "index error"); // TODO break; case ListParser.PARSER_ERROR: - listener.onFailure(checkFlag, "parser error"); // TODO + default: + responder = new GetGListResponder(listener, checkFlag, "parser error"); // TODO break; } } - @Override - public void onFailure(String eMsg) { - listener.onFailure(checkFlag, eMsg); - } - }); - hp.get(url); + } else { + responder = new GetGListResponder(listener, checkFlag, hp.getEMsg()); + } + + mHandler.post(responder); } }).start(); } @@ -558,7 +637,7 @@ public class EhClient { Message msg = new Message(); msg.what = GET_MANGA_URL; msg.obj = new GetMangaUrlPackage(checkFlag, task.strs, listener, task.eMsg); - mHandler.sendMessage(msg); + mHandler1.sendMessage(msg); } }); } @@ -1043,18 +1122,22 @@ public class EhClient { } public String getAddFavouriteUrl(int gid, String token) { - return getAddFavouriteUrl(gid, token, Config.getMode()); + return getAddFavouriteUrl(gid, token, mInfo.getAPIMode()); } - public String getAddFavouriteUrl(int gid, String token, int mode) { + public static String getAddFavouriteUrl(int gid, String token, int mode) { + StringBuilder sb = new StringBuilder(); switch (mode) { - case EX: - return EX_HEADER + "gallerypopups.php?gid=" - + gid + "&t=" + token + "&act=addfav"; + case MODE_EX: + sb.append(HEADER_EX); + break; + case MODE_G: default: - return G_HEADER + "gallerypopups.php?gid=" - + gid + "&t=" + token + "&act=addfav"; + sb.append(HEADER_G); + break; } + return sb.append("gallerypopups.php?gid=").append(gid).append("&t=") + .append(token).append("&act=addfav").toString(); } /** @@ -1123,6 +1206,7 @@ public class EhClient { ListUrls.UNKNOWN }; + // TODO How about "Private" private static String CATEGORY_STRINGS[][] = { new String[]{"misc"}, new String[]{"doujinshi"}, @@ -1130,8 +1214,8 @@ public class EhClient { new String[]{"artistcg", "Artist CG Sets"}, new String[]{"gamecg", "Game CG Sets"}, new String[]{"imageset", "Image Sets"}, - new String[]{"cosplay", "Asian Porn"}, - new String[]{"asianporn"}, + new String[]{"cosplay"}, + new String[]{"asianporn", "Asian Porn"}, new String[]{"non-h"}, new String[]{"western"}, new String[]{"unknown"} @@ -1160,22 +1244,26 @@ public class EhClient { // modifyFavorite public interface OnModifyFavoriteListener { - void onSuccess(List gis, - int indexPerPage, int maxPage); + void onSuccess(List gis, int maxPage); void onFailure(String eMsg); } public String getModifyFavoriteUrl() { - return getModifyFavoriteUrl(Config.getMode()); + return getModifyFavoriteUrl(mInfo.getMode()); } - public String getModifyFavoriteUrl(int mode) { + public static String getModifyFavoriteUrl(int mode) { + StringBuilder sb = new StringBuilder(); switch (mode) { - case EX: - return EX_HEADER + "favorites.php"; + case MODE_EX: + sb.append(HEADER_EX); + break; + case MODE_G: default: - return G_HEADER + "favorites.php"; + sb.append(HEADER_G); + break; } + return sb.append("favorites.php").toString(); } /** @@ -1198,11 +1286,11 @@ public class EhClient { public void onSuccess(Object obj) { String body = (String)obj; ListParser parser = new ListParser(); - int re = parser.parser(body); + int re = parser.parser(body, MODE_G); // Only MODE_G and MODE_EX if (re == ListParser.ALL) { - listener.onSuccess(parser.giList, parser.indexPerPage, parser.maxPage); + listener.onSuccess(parser.giList, parser.pageNum); } else if (re == ListParser.NOT_FOUND) { - listener.onSuccess(parser.giList, parser.indexPerPage, parser.maxPage); + listener.onSuccess(parser.giList, parser.pageNum); } else if (re == ListParser.PARSER_ERROR) { listener.onFailure("parser error"); // TODO } @@ -1298,7 +1386,7 @@ public class EhClient { listener.onFailure(eMsg); } }); - hp.postJson(EHVIEWER_API, json); + hp.postJson(API_EHVIEWER, json); } }).start(); } diff --git a/src/com/hippo/ehviewer/ehclient/EhInfo.java b/src/com/hippo/ehviewer/ehclient/EhInfo.java index 93c3eea9d..32545d3bf 100644 --- a/src/com/hippo/ehviewer/ehclient/EhInfo.java +++ b/src/com/hippo/ehviewer/ehclient/EhInfo.java @@ -25,33 +25,33 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.util.List; -import com.hippo.ehviewer.R; -import com.hippo.ehviewer.util.Config; -import com.hippo.ehviewer.util.Util; - import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Config; +import com.hippo.ehviewer.util.Util; + /** - * + * * @author Hippo * */ public class EhInfo { - + private static final String TAG = EhInfo.class.getSimpleName(); private static final String PREF_NAME = "eh_info"; private static final String DIR_NAME = "file"; private static final String AVATAR_NAME = "avatar.png"; private static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.PNG; private static Bitmap DEFAULT_AVATAR; - + public static final String EX_HOST = "exhentai.org"; public static final String[] COOKIABLE_HOSTS = {"exhentai.org", "g.e-hentai.org", "forums.e-hentai.org"}; - + private static final String KEY_LOGIN = "login"; private static final boolean DEFAULT_LOGIN = false; private static final String KEY_USERNAME = "username"; @@ -61,9 +61,11 @@ public class EhInfo { private static final String DEFAULT_MEMBER_ID = "1936857"; private static final String KEY_PASS_HASH = "ipb_pass_hash"; private static final String DEFAULT_PASS_HASH = "725e2726990bc34ae3852bb4f7c7879a"; - - private Context mContext; + + private final Context mContext; private final SharedPreferences mInfoPref; + private int mMode; + private int mAPIMode; private String mUconfig; private boolean mIsLogin; private String mUsername; @@ -74,13 +76,13 @@ public class EhInfo { private int mExculdeTagGroup; private String mExculdeLanguage; private static EhInfo sInstance; - + private Bitmap getAvatarFromFile() { File dir = mContext.getDir(DIR_NAME, 0); File avatarFile = new File(dir, AVATAR_NAME); if (!avatarFile.exists()) return null; - + InputStream is = null; try { is = new FileInputStream(avatarFile); @@ -91,26 +93,29 @@ public class EhInfo { Util.closeStreamQuietly(is); } } - + private EhInfo(final Context context){ mContext = context; mInfoPref = mContext.getSharedPreferences(PREF_NAME, 0); if (DEFAULT_AVATAR == null) DEFAULT_AVATAR = BitmapFactory.decodeStream( context.getResources().openRawResource(R.drawable.default_avatar)); - + + mMode = Config.getMode(); + mAPIMode = Config.getAPIMode(); + mIsLogin = mInfoPref.getBoolean(KEY_LOGIN, DEFAULT_LOGIN); mUsername = mInfoPref.getString(KEY_USERNAME, DEFAULT_NAME); mDisplayname = mInfoPref.getString(KEY_DISPLAYNAME, DEFAULT_NAME); mAvatar = getAvatarFromFile(); - + mDefaultCat = Config.getDefaultCat(); mPreviewMode = Config.getPreviewMode(); mExculdeTagGroup = Config.getExculdeTagGroup(); mExculdeLanguage = Config.getExculdeLanguage(); updateUconfig(); }; - + private String getUconfigString(String previewMode) { return "cats_" + mDefaultCat + "-ts_" + (previewMode == null ? mPreviewMode : previewMode) @@ -118,22 +123,22 @@ public class EhInfo { + "-xl_" + mExculdeLanguage + "-tl_m-uh_y-tr_2-prn_n-dm_l-ar_0-rc_0-rx_0-ry_0-sa_y-oi_n-qb_n-tf_n-hp_-hk_-ms_n-mt_n"; } - + private void updateUconfig() { mUconfig = getUconfigString(null); } - + public final static EhInfo getInstance(final Context context) { if (sInstance == null) sInstance = new EhInfo(context.getApplicationContext()); return sInstance; } - + private String getCookie(String cookieStr, String key) { String value = null; int index1 = -1; int index2 = -1; - + if ((index1 = cookieStr.indexOf(key + "=")) != -1) { index1 += key.length() + 1; // size of key + "=" if ((index2 = cookieStr.indexOf(";", index1)) != -1) @@ -143,11 +148,11 @@ public class EhInfo { } return value; } - + public void storeCookie(HttpURLConnection conn) { String ipb_member_id; String ipb_pass_hash; - + List cookieList = conn.getHeaderFields().get("Set-Cookie"); if (cookieList == null) return; @@ -155,7 +160,7 @@ public class EhInfo { for (String str : cookieList) { ipb_member_id = getCookie(str, KEY_MEMBER_ID); ipb_pass_hash = getCookie(str, KEY_PASS_HASH); - + if (ipb_member_id != null) editor.putString(KEY_MEMBER_ID, ipb_member_id); if (ipb_pass_hash != null) @@ -163,32 +168,48 @@ public class EhInfo { } editor.apply(); } - + public void setCookie(HttpURLConnection conn) { setCookie(conn, null); } - + public void setCookie(HttpURLConnection conn, String previewMode) { String cookie = "ipb_member_id=" + mInfoPref.getString(KEY_MEMBER_ID, DEFAULT_MEMBER_ID) + "; ipb_pass_hash=" + mInfoPref.getString(KEY_PASS_HASH, DEFAULT_PASS_HASH) + "; uconfig=" + (previewMode == null ? mUconfig : getUconfigString(previewMode)); conn.setRequestProperty("Cookie", cookie); } - + + public int getMode() { + return mMode; + } + + public void setMode(int mode) { + mMode = mode; + } + + public int getAPIMode() { + return mAPIMode; + } + + public void setAPIMode(int apiMode) { + mAPIMode = apiMode; + } + public boolean isLogin() { return mIsLogin; } - + public void login(String username, String displayname) { mIsLogin = true; mUsername = username; mDisplayname = displayname; - + mInfoPref.edit().putBoolean(KEY_LOGIN, true) .putString(KEY_USERNAME, username) .putString(KEY_DISPLAYNAME, displayname).apply(); } - + public void logout() { mIsLogin = false; // Remove avatar @@ -199,27 +220,27 @@ public class EhInfo { File avatarFile = new File(dir, AVATAR_NAME); avatarFile.delete(); } - + mInfoPref.edit().putBoolean(KEY_LOGIN, false) .putString(KEY_MEMBER_ID, DEFAULT_MEMBER_ID) .putString(KEY_PASS_HASH, DEFAULT_PASS_HASH).apply(); } - + public String getUsername() { return mUsername; } - + public String getDisplayname() { return mDisplayname; } - + public Bitmap getAvatar() { return isLogin() && mAvatar != null ? mAvatar : DEFAULT_AVATAR; } - + public void setAvatar(Bitmap avatar) { mAvatar = avatar; - + File dir = mContext.getDir(DIR_NAME, 0); File avatarFile = new File(dir, AVATAR_NAME); OutputStream os = null; @@ -232,22 +253,22 @@ public class EhInfo { Util.closeStreamQuietly(os); } } - + public void setDefaultCat(int defaultCat) { mDefaultCat = defaultCat; updateUconfig(); } - + public void setPreviewMode(String previewMode) { mPreviewMode = previewMode; updateUconfig(); } - + public void setExculdeTagGroup(int exculdeTagGroup) { mExculdeTagGroup = exculdeTagGroup; updateUconfig(); } - + public void setExculdeLanguage(String exculdeLanguage) { mExculdeLanguage = exculdeLanguage; updateUconfig(); diff --git a/src/com/hippo/ehviewer/ehclient/ListParser.java b/src/com/hippo/ehviewer/ehclient/ListParser.java index a0749e370..db2293281 100644 --- a/src/com/hippo/ehviewer/ehclient/ListParser.java +++ b/src/com/hippo/ehviewer/ehclient/ListParser.java @@ -21,81 +21,156 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.hippo.ehviewer.data.GalleryInfo; +import com.hippo.ehviewer.data.LofiGalleryInfo; import com.hippo.ehviewer.util.Util; public class ListParser { - + + public static final int TARGET_PAGE_IS_LAST = -1; + public static final int ALL = 0x1; public static final int NOT_FOUND = 0x2; public static final int PARSER_ERROR = -1; - - public int indexPerPage = 25; - public int maxPage; - + public static final int INDEX_ERROR = -2; + + public int pageNum; + public ArrayList giList; - - public int parser(String pageContext) { - + + /** + * If NOT_FOUND maxPage is 0, + * if can not get maxPage, set it Integer.MAX_VALUE + * + * @param pageContext + * @param mode + * @return + */ + public int parser(String body, int mode) { + Pattern p; Matcher m; - - giList = new ArrayList(indexPerPage); - - p = Pattern.compile("]+>([\\d]+)]+>(?:]+>)?&"); - m = p.matcher(pageContext); - if (m.find()) { - maxPage = Integer.parseInt(m.group(1)); - } else if (pageContext.contains("No hits found

")) { - maxPage = 0; - return NOT_FOUND; - } else { - return PARSER_ERROR; - } - - p = Pattern.compile("(?:)?(?:)?" // category - + "(.+?)" // posted - + "" - + "(?:" - + "|init~([^<>\"~]+~[^<>\"~]+)~([^<>]+))" // thumb and title - + "" - + ".+?" - + "" // url and title - + ".+?" - + "
\"]+)\">" // rating - + ".+?" - + "
(.+?)"); // uploader - m = p.matcher(pageContext); - while (m.find()) { - GalleryInfo gi = new GalleryInfo(); - - gi.category = EhClient.getType(m.group(1)); - gi.posted = m.group(2); - if (m.group(3) == null) { - gi.thumb = Util.htmlUnsescape("http://" - + m.group(5).replace('~', '/')); - gi.title = Util.htmlUnsescape(m.group(6)); - } else { - gi.thumb = Util.htmlUnsescape(m.group(3)); - gi.title = Util.htmlUnsescape(m.group(4)); + + giList = new ArrayList(25); + + switch (mode) { + case EhClient.MODE_LOFI: + p = Pattern.compile("" // detail url + + "" // thumb url + + ".+?(.+?)" // title + + ".+?Posted:(.+?)" // Posted and uploader + + "Category:(.+?)" // Category + + "Tags:(.+?)" // Tags + + "Rating:(.+?)"); // rating + m = p.matcher(body); + DetailUrlParser dup = new DetailUrlParser(); + while (m.find()) { + LofiGalleryInfo lgi = new LofiGalleryInfo(); + String[] pau = new String[2]; + + if (dup.parser(m.group(1))) { + lgi.gid = dup.gid; + lgi.token = dup.token; + } else { + continue; + } + lgi.thumb = Util.htmlUnsescape(m.group(2)); + lgi.title = Util.htmlUnsescape(m.group(3)); + if (getPostedAndUploader(m.group(4), pau)) { + lgi.posted = pau[0]; + lgi.uploader = pau[1]; + } else { + continue; + } + lgi.category = EhClient.getType(m.group(5)); + String tags = m.group(6); + if (tags.equals("-")) + lgi.lofiTags = null; + else + lgi.lofiTags = tags.split(", "); + String rating = m.group(7); + if (rating.equals("-")) + lgi.rating = Float.NaN; + else + lgi.rating = getStartNum(rating); + + giList.add(lgi); } - - Pattern pattern = Pattern - .compile("/(\\d+)/(\\w+)"); - Matcher matcher = pattern.matcher(m.group(7)); - if (matcher.find()) { - gi.gid = Integer.parseInt(matcher.group(1)); - gi.token = matcher.group(2); - } else - continue; - - gi.rating = Float.parseFloat(getRate(m.group(9))); - gi.uploader = m.group(10); - giList.add(gi); + + if (giList.size() == 0) { + if (body.contains("No hits found
")) { + pageNum = 0; + return NOT_FOUND; + } else if (body.contains("No more hits found
")) { + return INDEX_ERROR; + } else { + return PARSER_ERROR; + } + } else { + if (!body.contains("Next Page >")) + pageNum = TARGET_PAGE_IS_LAST; + else + pageNum = Integer.MAX_VALUE; + return ALL; + } + + case EhClient.MODE_G: + case EhClient.MODE_EX: + default: + p = Pattern.compile("]+>([\\d]+)]+>(?:]+>)?&"); + m = p.matcher(body); + if (m.find()) { + pageNum = Integer.parseInt(m.group(1)); + } else if (body.contains("No hits found

")) { + pageNum = 0; + return NOT_FOUND; + } else { + return PARSER_ERROR; + } + + p = Pattern.compile("(?:)?(?:)?" // category + + "(.+?)" // posted + + "" + + "(?:" + + "|init~([^<>\"~]+~[^<>\"~]+)~([^<>]+))" // thumb and title + + "" + + ".+?" + + "" // url and title + + ".+?" + + "
\"]+)\">" // rating + + ".+?" + + "
(.+?)"); // uploader + m = p.matcher(body); + while (m.find()) { + GalleryInfo gi = new GalleryInfo(); + + gi.category = EhClient.getType(m.group(1)); + gi.posted = m.group(2); + if (m.group(3) == null) { + gi.thumb = Util.htmlUnsescape("http://" + + m.group(5).replace('~', '/')); + gi.title = Util.htmlUnsescape(m.group(6)); + } else { + gi.thumb = Util.htmlUnsescape(m.group(3)); + gi.title = Util.htmlUnsescape(m.group(4)); + } + + Pattern pattern = Pattern + .compile("/(\\d+)/(\\w+)"); + Matcher matcher = pattern.matcher(m.group(7)); + if (matcher.find()) { + gi.gid = Integer.parseInt(matcher.group(1)); + gi.token = matcher.group(2); + } else + continue; + + gi.rating = Float.parseFloat(getRate(m.group(9))); + gi.uploader = m.group(10); + giList.add(gi); + } + return ALL; } - indexPerPage = giList.size(); - return ALL; } - + private String getRate(String rawRate) { Pattern p = Pattern.compile("\\d+px"); Matcher m = p.matcher(rawRate); @@ -120,4 +195,26 @@ public class ListParser { re = Integer.toString(rate); return re; } + + private static final String PAU_SPACER = " by "; + + private boolean getPostedAndUploader(String raw, String[] pau) { + int index = raw.indexOf(PAU_SPACER); + if (index == -1) { + return false; + } else { + pau[0] = raw.substring(0, index); + pau[1] = raw.substring(index + PAU_SPACER.length()); + return true; + } + } + + private int getStartNum(String str) { + int startNum = 0; + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) == '*') + startNum++; + } + return startNum; + } } diff --git a/src/com/hippo/ehviewer/network/HttpHelper.java b/src/com/hippo/ehviewer/network/HttpHelper.java index b9ac0e07e..81a711873 100644 --- a/src/com/hippo/ehviewer/network/HttpHelper.java +++ b/src/com/hippo/ehviewer/network/HttpHelper.java @@ -290,7 +290,7 @@ public class HttpHelper { private class CheckSpHelper implements RequestHelper { @Override public URL getUrl() throws MalformedURLException { - return new URL(EhClient.EX_HEADER); + return new URL(EhClient.HEADER_EX); } @Override diff --git a/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java b/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java index 40200b50b..6b424c3cb 100644 --- a/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java +++ b/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java @@ -38,6 +38,7 @@ import com.hippo.ehviewer.cache.ImageCache; import com.hippo.ehviewer.data.GalleryInfo; import com.hippo.ehviewer.data.GalleryPopular; import com.hippo.ehviewer.ehclient.EhClient; +import com.hippo.ehviewer.ehclient.ListParser; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.widget.FswView; import com.hippo.ehviewer.widget.HfListView; @@ -45,6 +46,7 @@ import com.hippo.ehviewer.widget.LoadImageView; import com.hippo.ehviewer.widget.OnFitSystemWindowsListener; import com.hippo.ehviewer.widget.RatingView; import com.hippo.ehviewer.widget.RefreshTextView; +import com.hippo.ehviewer.widget.SuperToast; public abstract class AbstractGalleryActivity extends AbstractSlidingActivity implements HfListView.OnFooterRefreshListener, @@ -76,7 +78,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity private int mCurPage; private int mFirstPage = 0; private int mLastPage = 0; - private int mMaxPage; + private int mPageNum; private int mItemPerPage; private int mGetMode; private boolean mIsKeepPosition; @@ -157,7 +159,16 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity } } + protected boolean retry(boolean force) { + if (!force && isRefreshing()) + return false; + + getGallerys(); + return true; + } + /** + * Go to page 0 * If can't refresh return false, * if force is true, must return true * @@ -205,7 +216,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity protected boolean getNextPage(boolean isKeepPosition, boolean force) { if (!force && isRefreshing()) return false; - if (mLastPage >= mMaxPage - 1) + if (mLastPage >= mPageNum - 1) // If last page is the end of the page or more laster, error return false; mGetMode = NEXT_PAGE; @@ -219,7 +230,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity protected boolean getSomewhere(int page, boolean force) { if (!force && isRefreshing()) return false; - if (page >= mMaxPage || page < 0) + if (page >= mPageNum || page < 0) return false; mGetMode = SOMEWHERE; @@ -233,7 +244,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity public boolean jumpTo(int page, boolean force) { if (!force && isRefreshing()) return false; - if (page >= mMaxPage || page < 0) + if (page >= mPageNum || page < 0) return false; if (page >= mFirstPage && page <= mLastPage) { @@ -295,11 +306,11 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity mList.setSelector(new ColorDrawable(Color.TRANSPARENT)); mList.setClipToPadding(false); - mRefreshTextView.setOnRefreshListener(new RefreshTextView.OnRefreshListener() { + mRefreshTextView.setDefaultRefresh("点击重试", new RefreshTextView.OnRefreshListener() { // TODO @Override public void onRefresh() { mRefreshTextView.setRefreshing(true); - refresh(true); + retry(true); } }); } @@ -331,7 +342,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity } public int getMaxPage() { - return mMaxPage; + return mPageNum; } public int getCurPage() { @@ -346,7 +357,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity setGalleryInfos(gis, 1); } - public void setGalleryInfos(List gis, int maxPage) { + public void setGalleryInfos(List gis, int pageNum) { mGiList = gis; mGalleryAdapter.notifyDataSetChanged(); @@ -355,7 +366,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity mCurPage = 0; mFirstPage = 0; mLastPage = 0; - mMaxPage = maxPage; + mPageNum = pageNum; mItemPerPage = mGiList.size(); if (mItemPerPage == 0) @@ -377,7 +388,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity } @Override public Object getItem(int position) { - return mGiList.get(position); + return mGiList == null ? 0 : mGiList.get(position); } @Override public long getItemId(int position) { @@ -499,27 +510,32 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity } public interface OnGetListListener { - public void onSuccess(long taskStamp, List gis, int itemPerPage, int maxPage); + public void onSuccess(long taskStamp, List gis, int maxPage); public void onFailure(long taskStamp, String eMsg); } private final OnGetListListener mListener = new OnGetListListener() { @Override public void onSuccess(long taskStamp, - List gis, int itemPerPage, int maxPage) { + List gis, int pageNum) { if (mTaskStamp != taskStamp) return; - mMaxPage = maxPage; + if (pageNum == ListParser.TARGET_PAGE_IS_LAST) + mPageNum = mTargetPage + 1; + else + mPageNum = pageNum; + + int itemPerPage = gis == null ? 0 : gis.size(); if (mItemPerPage < itemPerPage) mItemPerPage = itemPerPage; - if (mMaxPage == 0) { + if (mPageNum == 0) { onlyShowNone(); mFirstPage = 0; mLastPage = 0; - mGiList = new ArrayList(); + mGiList = gis; mGalleryAdapter.notifyDataSetChanged(); } else { onlyShowList(); @@ -592,13 +608,25 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity switch (mGetMode) { case REFRESH: + case SOMEWHERE: mHlv.setVisibility(View.GONE); mRefreshTextView.setVisibility(View.VISIBLE); - mRefreshTextView.setEmesg(eMsg, true); + if (eMsg.equals("index error")) { + mRefreshTextView.setEmesg(eMsg, "点击回第一页", new RefreshTextView.OnRefreshListener() { + @Override + public void onRefresh() { + mRefreshTextView.setRefreshing(true); + refresh(true); + } + }); + } else { + mRefreshTextView.setEmesg(eMsg, true); + } break; default: mRefreshTextView.setRefreshing(false); mRefreshTextView.setVisibility(View.GONE); + new SuperToast(AbstractGalleryActivity.this, "错误的页面数",SuperToast.ERROR).show(); // TODO } mHlv.setAnyRefreshComplete(false); } diff --git a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java index db3f8f548..9aebf3f46 100644 --- a/src/com/hippo/ehviewer/ui/DetailSectionFragment.java +++ b/src/com/hippo/ehviewer/ui/DetailSectionFragment.java @@ -185,7 +185,7 @@ public class DetailSectionFragment extends Fragment public void handleDetail(GalleryDetail gd) { mGalleryDetail = gd; - mUrl = EhClient.getDetailUrl( + mUrl = mClient.getDetailUrl( mGalleryDetail.gid, mGalleryDetail.token); mThumb.setImageDrawable(null); @@ -328,7 +328,7 @@ public class DetailSectionFragment extends Fragment mWaitPreviewList.setVisibility(View.VISIBLE); mPreviewRefreshButton.setVisibility(View.GONE); - mUrl = EhClient.getDetailUrl( + mUrl = mClient.getDetailUrl( mGalleryDetail.gid, mGalleryDetail.token, mCurPage); mClient.getPreviewList(mUrl, mCurPage, new EhClient.OnGetPreviewListListener() { diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index 8b4e68f94..c862ab216 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -180,7 +180,7 @@ public class FavouriteActivity extends AbstractGalleryActivity Intent intent = new Intent(FavouriteActivity.this, MangaDetailActivity.class); GalleryInfo gi = getGalleryInfo(position); - intent.putExtra("url", EhClient.getDetailUrl(gi.gid, gi.token)); + intent.putExtra("url", mClient.getDetailUrl(gi.gid, gi.token)); intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi); startActivity(intent); } @@ -504,7 +504,7 @@ public class FavouriteActivity extends AbstractGalleryActivity @Override protected String getTargetUrl(int targetPage) { - return EhClient.getFavoriteUrl(mMenuIndex-1, targetPage); + return mClient.getFavoriteUrl(mMenuIndex-1, targetPage); } @Override @@ -512,9 +512,9 @@ public class FavouriteActivity extends AbstractGalleryActivity final OnGetListListener listener) { mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override - public void onSuccess(Object checkFlag, List lmdArray, - int indexPerPage, int maxPage) { - listener.onSuccess(taskStamp, lmdArray, indexPerPage, maxPage); + public void onSuccess(Object checkFlag, List giList, + int maxPage) { + listener.onSuccess(taskStamp, giList, maxPage); } @Override public void onFailure(Object checkFlag, String eMsg) { @@ -535,8 +535,7 @@ public class FavouriteActivity extends AbstractGalleryActivity } @Override - public void onSuccess(List gis, int indexPerPage, - int maxPage) { + public void onSuccess(List gis, int maxPage) { setGalleryInfos(gis, maxPage); mHlv.setRefreshing(false); new SuperToast(FavouriteActivity.this, mSuccStr).show(); diff --git a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java index a3379acff..59374b76d 100644 --- a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java @@ -55,12 +55,6 @@ import com.hippo.ehviewer.widget.AlertButton; import com.hippo.ehviewer.widget.DialogBuilder; import com.hippo.ehviewer.widget.SuperToast; -// TODO I'm going to add an awesome feature. -// When views in ListView or ScrollView or some ViewGroup can -// scroll are under actionbar, They should be seen. -// At that time actionbar's background must be translucent, -// statusbar too in 4.4. When no view under them, just normal. - public class MangaDetailActivity extends AbstractFragmentActivity implements ActionBar.TabListener { @@ -246,7 +240,7 @@ public class MangaDetailActivity extends AbstractFragmentActivity Intent it = new Intent(MangaDetailActivity.this, DownloadService.class); startService(it); mServiceConn.getService().add(String.valueOf(mGalleryDetail.gid), mGalleryDetail.thumb, - EhClient.getDetailUrl(mGalleryDetail.gid, mGalleryDetail.token), + EhClient.getDetailUrl(mGalleryDetail.gid, mGalleryDetail.token, 0, Config.getMode()), mGalleryDetail.title); new SuperToast(this, R.string.toast_add_download).show(); } @@ -298,7 +292,7 @@ public class MangaDetailActivity extends AbstractFragmentActivity ((AlertButton)v).dialog.dismiss(); String comment = et.getText().toString(); ((AppContext)getApplication()).getEhClient() - .comment(EhClient.getDetailUrl(mGalleryDetail.gid, mGalleryDetail.token), + .comment(EhClient.getDetailUrl(mGalleryDetail.gid, mGalleryDetail.token, 0, Config.getMode()), comment, new EhClient.OnCommentListener() { @Override public void onSuccess(List comments) { diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java index 7ad05046c..4e6f00f01 100644 --- a/src/com/hippo/ehviewer/ui/MangaListActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java @@ -71,6 +71,7 @@ import com.hippo.ehviewer.data.Data; import com.hippo.ehviewer.data.GalleryInfo; import com.hippo.ehviewer.data.Tag; import com.hippo.ehviewer.ehclient.EhClient; +import com.hippo.ehviewer.ehclient.EhInfo; import com.hippo.ehviewer.network.Downloader; import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; @@ -130,7 +131,7 @@ public class MangaListActivity extends AbstractGalleryActivity public static final String KEY_TAG = "tag"; public static final String KEY_UPLOADER = "uploader"; - private EhClient mEhClient; + private EhClient mClient; private Resources mResources; private SlidingMenu mSlidingMenu; @@ -193,7 +194,7 @@ public class MangaListActivity extends AbstractGalleryActivity setUserPanel(WAIT); String username = ((EditText) loginDialog.findViewById(R.id.username)).getText().toString(); String password = ((EditText) loginDialog.findViewById(R.id.password)).getText().toString(); - mEhClient.login(username, password, new EhClient.OnLoginListener() { + mClient.login(username, password, new EhClient.OnLoginListener() { @Override public void onSuccess() { setUserPanel(); @@ -215,11 +216,11 @@ public class MangaListActivity extends AbstractGalleryActivity setUserPanel(); break; case EhClient.NO_AVATAR: - new SuperToast(MangaListActivity.this, "无头像").show(); + new SuperToast(MangaListActivity.this, "无头像").show(); // TODO break; case EhClient.GET_AVATAR_ERROR: default: - new SuperToast(MangaListActivity.this, "获取头像失败", SuperToast.ERROR).show(); + new SuperToast(MangaListActivity.this, "获取头像失败", SuperToast.ERROR).show(); // TODO break; } } @@ -258,13 +259,10 @@ public class MangaListActivity extends AbstractGalleryActivity .setPositiveButton(android.R.string.ok, new View.OnClickListener() { @Override public void onClick(View v) { + ((AlertButton)v).dialog.dismiss(); int mode = modeSpinner.getSelectedItemPosition(); - if (mode > 1) { - new SuperToast(MangaListActivity.this, R.string.unfinished).show(); - } else { - ((AlertButton)v).dialog.dismiss(); - Config.setMode(mode); - } + Config.setMode(mode); + EhInfo.getInstance(MangaListActivity.this).setMode(mode); } }).setSimpleNegativeButton().create(); } @@ -529,7 +527,7 @@ public class MangaListActivity extends AbstractGalleryActivity Intent it = new Intent(MangaListActivity.this, DownloadService.class); startService(it); mServiceConn.getService().add(String.valueOf(gi.gid), gi.thumb, - EhClient.getDetailUrl(gi.gid, gi.token), gi.title); + mClient.getDetailUrl(gi.gid, gi.token), gi.title); new SuperToast(MangaListActivity.this, R.string.toast_add_download).show(); break; default: @@ -549,7 +547,9 @@ public class MangaListActivity extends AbstractGalleryActivity LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.jump, null); TextView tv = (TextView)view.findViewById(R.id.list_jump_sum); - tv.setText(String.format(getString(R.string.jump_summary), getCurPage() + 1, getMaxPage())); + // For lofi, can not get page num, so use Integer.MAX_VALUE + tv.setText(String.format(getString(R.string.jump_summary), getCurPage() + 1, + getMaxPage() == Integer.MAX_VALUE ? "未知" : String.valueOf(getMaxPage()))); // TODO tv = (TextView)view.findViewById(R.id.list_jump_to); tv.setText(R.string.jump_to); final EditText et = (EditText)view.findViewById(R.id.list_jump_edit); @@ -922,7 +922,7 @@ public class MangaListActivity extends AbstractGalleryActivity } else if (v == registerButton) { toRegister(); } else if (v == logoutButton) { - mEhClient.logout(); + mClient.logout(); setUserPanel(); } } @@ -964,7 +964,7 @@ public class MangaListActivity extends AbstractGalleryActivity super.onCreate(savedInstanceState); mData = mAppContext.getData(); - mEhClient = mAppContext.getEhClient(); + mClient = mAppContext.getEhClient(); mResources =getResources(); handleIntent(getIntent()); @@ -1190,7 +1190,7 @@ public class MangaListActivity extends AbstractGalleryActivity Intent intent = new Intent(MangaListActivity.this, MangaDetailActivity.class); GalleryInfo gi = getGalleryInfo(position); - intent.putExtra("url", EhClient.getDetailUrl(gi.gid, gi.token)); + intent.putExtra("url", mClient.getDetailUrl(gi.gid, gi.token)); intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi); startActivity(intent); } @@ -1483,7 +1483,7 @@ public class MangaListActivity extends AbstractGalleryActivity private static final int WAIT = 0x2; private void setUserPanel() { - if (mEhClient.isLogin()) + if (mClient.isLogin()) setUserPanel(LOGOUT); else setUserPanel(LOGIN); @@ -1493,7 +1493,7 @@ public class MangaListActivity extends AbstractGalleryActivity switch (state) { case LOGIN: - avatar.setImageBitmap(mEhClient.getAvatar()); + avatar.setImageBitmap(mClient.getAvatar()); userView.setVisibility(View.GONE); loginButton.setVisibility(View.VISIBLE); registerButton.setVisibility(View.VISIBLE); @@ -1501,8 +1501,8 @@ public class MangaListActivity extends AbstractGalleryActivity waitloginoutView.setVisibility(View.GONE); break; case LOGOUT: - avatar.setImageBitmap(mEhClient.getAvatar()); - userView.setText(mEhClient.getDisplayname()); + avatar.setImageBitmap(mClient.getAvatar()); + userView.setText(mClient.getDisplayname()); userView.setVisibility(View.VISIBLE); loginButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); @@ -1510,7 +1510,7 @@ public class MangaListActivity extends AbstractGalleryActivity waitloginoutView.setVisibility(View.GONE); break; case WAIT: - avatar.setImageBitmap(mEhClient.getAvatar()); + avatar.setImageBitmap(mClient.getAvatar()); userView.setVisibility(View.GONE); loginButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); @@ -1534,7 +1534,7 @@ public class MangaListActivity extends AbstractGalleryActivity mClient.getPopular(new EhClient.OnGetPopularListener() { @Override public void onSuccess(List gis, long timeStamp) { - listener.onSuccess(taskStamp, gis, gis.size(), gis.size() == 0 ? 0 : 1); + listener.onSuccess(taskStamp, gis, gis.size() == 0 ? 0 : 1); // Show update time if (timeStamp != -1 && Config.getShowPopularUpdateTime()) new SuperToast(MangaListActivity.this, @@ -1550,8 +1550,8 @@ public class MangaListActivity extends AbstractGalleryActivity mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override public void onSuccess(Object checkFlag, List lmdArray, - int indexPerPage, int maxPage) { - listener.onSuccess(taskStamp, lmdArray, indexPerPage, maxPage); + int pageNum) { + listener.onSuccess(taskStamp, lmdArray, pageNum); } @Override public void onFailure(Object checkFlag, String eMsg) { diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java index 83e227d04..98e4e622b 100644 --- a/src/com/hippo/ehviewer/util/Config.java +++ b/src/com/hippo/ehviewer/util/Config.java @@ -28,10 +28,7 @@ public class Config { @SuppressWarnings("unused") private static final String TAG = "Config"; - private static final String KEY_UPDATE_DATE = "update_date"; - private static final String KEY_MODE = "mode"; - private static final int MODE_DEFAULT = EhClient.EX; private static final String KEY_SCREEN_ORIENTATION = "screen_orientation"; private static final String DEFAULT_SCREEN_ORIENTATION = "0"; @@ -144,21 +141,6 @@ public class Config { mConfigPre.edit().putString(KEY_DOWNLOAD_PATH, path).apply(); } - public static int getMode() { - int mode = mConfigPre.getInt(KEY_MODE, MODE_DEFAULT); - if (mode < EhClient.G || mode > EhClient.LOFI_980x) { - mode = MODE_DEFAULT; - setMode(mode); - } - return mode; - } - - public static void setMode(int mode) { - if (mode < EhClient.G || mode > EhClient.LOFI_980x) - mode = MODE_DEFAULT; - mConfigPre.edit().putInt(KEY_MODE, mode).apply(); - } - /** * Get cover cache size in MB * @@ -322,8 +304,29 @@ public class Config { return Integer.parseInt(mConfigPre.getString(KEY_LIST_MODE, DEFAULT_LIST_MODE)); } + /****** For Mode an API Mode ******/ + private static final String KEY_MODE = "mode"; + private static final int DEFAULT_MODE = EhClient.MODE_G; + private static final String KEY_API_MODE = "api_mode"; + private static final int DEFAULT_API_MODE = EhClient.MODE_G; + + public static int getMode() { + return mConfigPre.getInt(KEY_MODE, DEFAULT_MODE); + } + + public static void setMode(int mode) { + mConfigPre.edit().putInt(KEY_MODE, mode).apply(); + } + + public static int getAPIMode() { + return mConfigPre.getInt(KEY_API_MODE, DEFAULT_API_MODE); + } + + public static void setAPIMode(int apiMode) { + mConfigPre.edit().putInt(KEY_API_MODE, apiMode).apply(); + } /****** For Eh Config ******/ @@ -393,5 +396,4 @@ public class Config { public static int getPreviewPerRow() { return Integer.parseInt(mConfigPre.getString(KEY_PREVIEW_PER_ROW, DEFAULT_PREVIEW_PER_ROW)); } - } diff --git a/src/com/hippo/ehviewer/widget/RefreshTextView.java b/src/com/hippo/ehviewer/widget/RefreshTextView.java index 403de637d..d1dd3924d 100644 --- a/src/com/hippo/ehviewer/widget/RefreshTextView.java +++ b/src/com/hippo/ehviewer/widget/RefreshTextView.java @@ -29,7 +29,8 @@ public class RefreshTextView extends TextView implements View.OnClickListener{ private volatile boolean mIsRefreshing = false; - private volatile boolean mCanRefreshing; + private String mDefaultTip; + private OnRefreshListener mDefaultListener; private OnRefreshListener mListener; private static final String[] REFRESHING_STRINGS = { @@ -61,13 +62,14 @@ public class RefreshTextView extends TextView setOnClickListener(this); } - public void setOnRefreshListener(OnRefreshListener listener) { - mListener = listener; + public void setDefaultRefresh(String tip, OnRefreshListener listener) { + mDefaultTip = tip; + mDefaultListener = listener; } @Override public void onClick(View v) { - if (!mIsRefreshing && mCanRefreshing && mListener != null) + if (!mIsRefreshing && mListener != null) mListener.onRefresh(); } @@ -88,17 +90,35 @@ public class RefreshTextView extends TextView } public void setEmesg(CharSequence emseg, boolean canRefresh) { + if (canRefresh) + setEmesg(emseg, mDefaultTip, mDefaultListener); + else + setEmesg(emseg, null, null); + } + + public void setEmesg(CharSequence emseg, String tip, + OnRefreshListener listener) { mIsRefreshing = false; - mCanRefreshing = canRefresh; + boolean canRefresh = listener == null ? false : true; StringBuilder sb = new StringBuilder("==█ \n(>π<)\n\n"); sb.append(emseg); - if (mCanRefreshing) - sb.append("点击重试"); // TODO; + if (canRefresh) { + sb.append("\n\n").append(tip); + mListener = listener; + } else { + mListener = null; + } setText(sb.toString()); } + /** + * The thread to control refreshing animate + * + * @author Hippo + * + */ private class RefreshingThread extends Thread { int mIndex; @Override