Skip to content

Commit

Permalink
在云端收藏列表新增排序功能,可按收藏时间和上传时间进行排序
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojieonly committed Sep 24, 2024
1 parent 1650485 commit f42d15f
Show file tree
Hide file tree
Showing 25 changed files with 7,518 additions and 155 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/com/hippo/ehviewer/client/EhConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ public class EhConfig implements Cloneable {
public static final String ARCHIVER_PATH = "Ehviewer/Archiver/";
public static final String TORRENT_PATH = "Ehviewer/Torrent/";

/**
* favorites list sort by Favorited Time or Published Time
*/
public static final String ORDER_BY_FAV_TIME = "f";
public static final String ORDER_BY_PUB_TIME = "p";

/**
* Load images through the Hentai@Home Network<br/>
* key: {@link #KEY_LOAD_FROM_HAH}<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public String build() {
if (isValidFavCat(mFavCat)) {
ub.addQuery("favcat", Integer.toString(mFavCat));
} else if (mFavCat == FAV_CAT_ALL) {
ub.addQuery("favcat", "all");
// ub.addQuery("favcat", "all");
}
if (!TextUtils.isEmpty(mKeyword)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,21 @@ public static class Result {
public String prevHref;
public String nextHref;
public String lastHref;
public String favOrder;
public List<GalleryInfo> galleryInfoList;
}

public static Result parse(String body) throws Exception {
if (body.contains("This page requires you to log on.</p>")) {
throw new EhException(GetText.getString(R.string.need_sign_in));
}
Result re = new Result();

String[] catArray = new String[10];
int[] countArray = new int[10];

Document d;
try {
Document d = Jsoup.parse(body);
d = Jsoup.parse(body);
Element ido = JsoupUtils.getElementByClass(d, "ido");
//noinspection ConstantConditions
Elements fps = ido.getElementsByClass("fp");
Expand All @@ -67,15 +70,27 @@ public static Result parse(String body) throws Exception {
countArray[i] = ParserUtils.parseInt(fp.child(0).text(), 0);
catArray[i] = ParserUtils.trim(fp.child(2).text());
}
Elements orders = JsoupUtils.getElementsByClass(d,"searchnav");
if (null!=orders&&!orders.isEmpty()){
Element order = orders.first();
if (null!=order){
Elements selects = order.getElementsByTag("select");
if (!selects.isEmpty()){
Element sel = selects.get(0);
Elements result = sel.getElementsByAttribute("selected");
re.favOrder = result.attr("value");
}
}
}
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
e.printStackTrace();
throw new ParseException("Parse favorites error", body);
}

GalleryListParser.Result result = GalleryListParser.parse(body, MODE_NORMAL);
GalleryListParser.Result result = GalleryListParser.parse(d,body, MODE_NORMAL);


Result re = new Result();
re.catArray = catArray;
re.countArray = countArray;
re.pages = result.pages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ private static int parsePages(Document d, String body) throws ParseException {
}

public static Result parse(@NonNull String body, int mode) throws Exception {
Result result = new Result();
Document d;
try{
d = Jsoup.parse(body);
}catch (Exception ignored){
return result;
try {
d = Jsoup.parse(body);
return parse(d, body, mode);
} catch (Exception ignored) {
return new Result();
}
}

public static Result parse(@NonNull Document d,@NonNull String body, int mode) throws Exception {
Result result = new Result();
try {
Element ptt = d.getElementsByClass("ptt").first();
if (ptt == null) {
Expand All @@ -107,61 +110,61 @@ public static Result parse(@NonNull String body, int mode) throws Exception {

assert searchNav != null;
Element element = searchNav.getElementById("uFirst");
if (element!=null){
if (element != null) {
result.firstHref = element.attr("href");
}else {
} else {
result.firstHref = "";
}
element = searchNav.getElementById("uprev");
if (element!=null){
if (element != null) {
result.prevHref = element.attr("href");
}else {
} else {
result.prevHref = "";
}
element = searchNav.getElementById("unext");
if (element!=null){
if (element != null) {
result.nextHref = element.attr("href");
}else {
} else {
result.nextHref = "";
}
element = searchNav.getElementById("ulast");
if (element!=null){
if (element != null) {
result.lastHref = element.attr("href");
}else {
} else {
result.lastHref = "";
}

element = d.getElementsByClass("searchtext").first();

if (element!=null){
if (element != null) {
String text = element.text();
Matcher matcher = PATTERN_RESULT_COUNT_PAGE.matcher(text);
if (matcher.find()){
if (matcher.find()) {
String findString = matcher.group();
String[] resultArr = findString.split(" ");
if (resultArr.length>3){
switch (resultArr[1]){
if (resultArr.length > 3) {
switch (resultArr[1]) {
case "thousands":
result.resultCount = "1,000+";
break;
case "about":
result.resultCount = resultArr[2]+"+";
result.resultCount = resultArr[2] + "+";
break;
default:
StringBuilder buffer = new StringBuilder();
for (int i=1;i<resultArr.length-1;i++){
for (int i = 1; i < resultArr.length - 1; i++) {
buffer.append(resultArr[i]);
}
result.resultCount = buffer.toString();
break;
}
}else if(resultArr.length == 3){
} else if (resultArr.length == 3) {
result.resultCount = resultArr[1];
}else{
} else {
result.resultCount = "";
}
}
}else {
} else {
result.resultCount = "";
}

Expand Down Expand Up @@ -402,7 +405,7 @@ private static GalleryInfo parseGalleryInfo(Element e) {
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
}

parserTag(gi,e);
parserTag(gi, e);

// Rating
Element ir = JsoupUtils.getElementByClass(e, "ir");
Expand Down Expand Up @@ -454,14 +457,14 @@ private static GalleryInfo parseGalleryInfo(Element e) {
return gi;
}

private static void parserTag(final GalleryInfo gi,final Element e) {
private static void parserTag(final GalleryInfo gi, final Element e) {
Elements gts = JsoupUtils.getElementsByClass(e, "gt");
if (gts != null) {
gi.tgList = (ArrayList<String>) gts.eachAttr("title");
}
Elements gtl = JsoupUtils.getElementsByClass(e, "gtl");
if (gtl!=null){
if (gi.tgList==null){
if (gtl != null) {
if (gi.tgList == null) {
gi.tgList = new ArrayList<>();
}
gi.tgList.addAll(gtl.eachAttr("title"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.hippo.ehviewer.ui.dialog;

import static com.hippo.ehviewer.client.EhConfig.ORDER_BY_FAV_TIME;
import static com.hippo.ehviewer.client.EhConfig.ORDER_BY_PUB_TIME;

import android.app.AlertDialog;

import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.parser.FavoritesParser;
import com.hippo.ehviewer.ui.scene.FavoritesScene;

public class FavoriteListSortDialog {
private final FavoritesScene scene;

public FavoriteListSortDialog(FavoritesScene scene) {
this.scene = scene;
}

public void showCloudSort(FavoritesParser.Result mResult) {
int checked;
if (null == mResult.favOrder) {
return;
}
if (mResult.favOrder.equals(ORDER_BY_FAV_TIME)) {
checked = 0;
} else if (mResult.favOrder.equals(ORDER_BY_PUB_TIME)) {
checked = 1;
} else {
return;
}
AlertDialog dialog = new AlertDialog.Builder(scene.getContext())
.setIcon(R.mipmap.ic_launcher)
.setTitle(R.string.order)
.setSingleChoiceItems(R.array.fav_sort, checked, (dialogInterface, i) -> {
if (i == 0) {
scene.updateSort("inline_set=fs_f");
} else {
scene.updateSort("inline_set=fs_p");
}
dialogInterface.dismiss();
})
.create();
dialog.show();
}

public void showLocalSort(FavoritesParser.Result mResult) {

}
}
Loading

0 comments on commit f42d15f

Please sign in to comment.