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 2971c8934..0fb9c7ae8 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 @@ -64,7 +64,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { @Mode private int mMode = MODE_NORMAL; - private int mPageIndex = 0; + private int mNextGid = 0; + private int mPrevGid = 0; private int mCategory = EhUtils.NONE; private String mKeyword = null; @@ -86,7 +87,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable { @SuppressWarnings("WrongConstant") protected ListUrlBuilder(Parcel in) { this.mMode = in.readInt(); - this.mPageIndex = in.readInt(); + this.mNextGid = in.readInt(); this.mCategory = in.readInt(); this.mKeyword = in.readString(); this.mAdvanceSearch = in.readInt(); @@ -105,7 +106,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable { */ public void reset() { mMode = MODE_NORMAL; - mPageIndex = 0; + mNextGid = 0; mCategory = EhUtils.NONE; mKeyword = null; mAdvanceSearch = -1; @@ -137,12 +138,12 @@ public class ListUrlBuilder implements Cloneable, Parcelable { mMode = mode; } - public int getPageIndex() { - return mPageIndex; + public void setNextGid(int nextGid) { + mNextGid = nextGid; } - public void setPageIndex(int pageIndex) { - mPageIndex = pageIndex; + public void setPrevGid(int prevGid) { + mPrevGid = prevGid; } public int getCategory() { @@ -233,7 +234,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { */ public void set(ListUrlBuilder lub) { mMode = lub.mMode; - mPageIndex = lub.mPageIndex; + mNextGid = lub.mNextGid; + mPrevGid = lub.mPrevGid; mCategory = lub.mCategory; mKeyword = lub.mKeyword; mAdvanceSearch = lub.mAdvanceSearch; @@ -524,9 +526,11 @@ public class ListUrlBuilder implements Cloneable, Parcelable { if (mSHash != null) { ub.addQuery("f_shash", mSHash); } - // Page index - if (mPageIndex != 0) { - ub.addQuery("page", mPageIndex); + if (mNextGid != 0) { + ub.addQuery("next", mNextGid); + } + if (mPrevGid != 0) { + ub.addQuery("prev", mPrevGid); } // Advance search if (mAdvanceSearch != -1) { @@ -570,8 +574,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { } catch (UnsupportedEncodingException e) { // Empty } - if (mPageIndex != 0) { - sb.append('/').append(mPageIndex); + if (mNextGid != 0) { + sb.append('/').append(mNextGid); } return sb.toString(); } @@ -583,8 +587,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { } catch (UnsupportedEncodingException e) { // Empty } - if (mPageIndex != 0) { - sb.append('/').append(mPageIndex); + if (mNextGid != 0) { + sb.append('/').append(mNextGid); } return sb.toString(); } @@ -600,8 +604,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { } catch (UnsupportedEncodingException e) { // Empty } - if (mPageIndex != 0) { - sb.append("&p=").append(mPageIndex); + if (mNextGid != 0) { + sb.append("&p=").append(mNextGid); } return sb.toString(); } @@ -615,7 +619,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.mMode); - dest.writeInt(this.mPageIndex); + dest.writeInt(this.mNextGid); + dest.writeInt(this.mPrevGid); dest.writeInt(this.mCategory); dest.writeString(this.mKeyword); dest.writeInt(this.mAdvanceSearch); diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.java index 0eae53cd0..c3fce9c8c 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.java @@ -65,8 +65,6 @@ public class FavoritesParser { Result re = new Result(); re.catArray = catArray; re.countArray = countArray; - re.pages = result.pages; - re.nextPage = result.nextPage; re.galleryInfoList = result.galleryInfoList; return re; diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java index 0228efcef..cc13cb524 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryListParser.java @@ -53,6 +53,8 @@ public class GalleryListParser { private static final Pattern PATTERN_PAGES = Pattern.compile("(\\d+) page"); private static final Pattern PATTERN_NEXT_PAGE = Pattern.compile("page=(\\d+)"); + private static final Pattern PATTERN_GETINT = Pattern.compile("[^0-9]"); + private static final String[][] FAVORITE_SLOT_RGB = new String[][]{ new String[]{"0", "0", "0"}, new String[]{"240", "0", "0"}, @@ -297,38 +299,30 @@ public class GalleryListParser { return gi; } + private static int getInt(String str) { + var m = PATTERN_GETINT.matcher(str); + return Integer.parseInt(m.replaceAll("").trim()); + } + public static Result parse(@NonNull String body) throws Exception { Result result = new Result(); Document d = Jsoup.parse(body); try { - Element ptt = d.getElementsByClass("ptt").first(); - Elements es = ptt.child(0).child(0).children(); - result.pages = Integer.parseInt(es.get(es.size() - 2).text().trim()); + Element stt = d.getElementsByClass("searchtext").first(); + assert stt != null; + result.founds = getInt(stt.text()); - Element e = es.get(es.size() - 1); - if (e != null) { - e = e.children().first(); - if (e != null) { - String href = e.attr("href"); - Matcher matcher = PATTERN_NEXT_PAGE.matcher(href); - if (matcher.find()) { - result.nextPage = NumberUtils.parseIntSafely(matcher.group(1), 0); - } - } - } } catch (Throwable e) { ExceptionUtils.throwIfFatal(e); result.noWatchedTags = body.contains("
You do not have any watched tags"); if (body.contains("No hits found
")) { - result.pages = 0; + result.founds = 0; //noinspection unchecked result.galleryInfoList = Collections.EMPTY_LIST; return result; - } else if (d.getElementsByClass("ptt").isEmpty()) { - result.pages = 1; } else { - result.pages = Integer.MAX_VALUE; + result.founds = Integer.MAX_VALUE; } } @@ -364,8 +358,7 @@ public class GalleryListParser { } public static class Result { - public int pages; - public int nextPage; + public int founds; public boolean noWatchedTags; public List