Filter is back

This commit is contained in:
seven332 committed 2019-03-25 13:34:24 +08:00
1 parent 3cd4fc7ce9
commit 58ac39cf2c
14 files changed
+476 -147

No files matched your search

@@ -82,7 +82,11 @@ public class EhEngine {
private static final Pattern PATTERN_NEED_HATH_CLIENT = Pattern.compile("(You must have a H@H client assigned to your account to use this feature\\.)");
public static void initialize() { }
public static EhFilter sEhFilter;
public static void initialize() {
sEhFilter = EhFilter.getInstance();
}
private static void doThrowException(Call call, int code, @Nullable Headers headers,
@Nullable String body, Throwable e) throws Throwable {
@@ -170,6 +174,18 @@ public class EhEngine {
}
private static void fillGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String url, boolean filter) throws Throwable {
// Filter title and uploader
if (filter) {
for (int i = 0, n = list.size(); i < n; i++) {
GalleryInfo info = list.get(i);
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
list.remove(i);
i--;
n--;
}
}
}
boolean hasTags = false;
boolean hasPages = false;
boolean hasRated = false;
@@ -185,11 +201,25 @@ public class EhEngine {
}
}
boolean needApi = (Settings.getShowGalleryPages() && !hasPages) || hasRated;
boolean needApi = (filter && sEhFilter.needTags() && !hasTags) ||
(Settings.getShowGalleryPages() && !hasPages) ||
hasRated;
if (needApi) {
fillGalleryListByApi(task, okHttpClient, list, url);
}
// Filter tag
if (filter) {
for (int i = 0, n = list.size(); i < n; i++) {
GalleryInfo info = list.get(i);
if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
list.remove(i);
i--;
n--;
}
}
}
for (GalleryInfo info : list) {
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
}