From f589124cc808784cc33e9df30806661c9bf2deb6 Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 14 Jul 2015 16:15:24 +0800 Subject: [PATCH] Fix no hits found --- .../hippo/ehviewer/client/EhException.java | 3 +++ .../ehviewer/client/GalleryListParser.java | 7 ++--- .../ehviewer/client/NotFoundException.java | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/client/NotFoundException.java diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhException.java b/app/src/main/java/com/hippo/ehviewer/client/EhException.java index 5273c3a79..8a60a7127 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhException.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhException.java @@ -16,6 +16,9 @@ package com.hippo.ehviewer.client; +/** + * The exception about EH + */ public class EhException extends Exception { public EhException(String detailMessage) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java b/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java index fbadba634..5de2ddb38 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java @@ -34,14 +34,11 @@ public class GalleryListParser { public static class Result { - public static final int NOT_FOUND = 0; - public static final int CURRENT_PAGE_IS_LAST = -1; public static final int KEEP_LOADING = Integer.MAX_VALUE; /** - * If NOT FOUND, pageNum is 0.
* For lofi, we can not get pages number, * so pageNum is {@link java.lang.Integer#MAX_VALUE} when it is not the last page, * pageNum is {@link #CURRENT_PAGE_IS_LAST} when it is the last page @@ -74,7 +71,7 @@ public class GalleryListParser { if (m.find()) { result.pages = ParserUtils.parseInt(m.group(1)); } else if (body.contains("No hits found

")) { - result.pages = Result.NOT_FOUND; + throw new NotFoundException(); } else { // Can not get page number throw new ParseException("Can't parse gallery list", body); @@ -187,7 +184,7 @@ public class GalleryListParser { if (list.size() == 0) { if (body.contains("No hits found")) { - result.pages = Result.NOT_FOUND; + throw new NotFoundException(); } else if (body.contains("No more hits found")) { throw new EhException("Index is out of range"); } else { diff --git a/app/src/main/java/com/hippo/ehviewer/client/NotFoundException.java b/app/src/main/java/com/hippo/ehviewer/client/NotFoundException.java new file mode 100644 index 000000000..bddbcf244 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/client/NotFoundException.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * Get nothing in search + */ +public class NotFoundException extends EhException { + + public NotFoundException() { + super("Nobody here but us chickens!"); + } +}