]*>)?
]*href=\"([^<>\"]+)\"[^<>]*>");
+ Matcher m = p.matcher(pageContent);
+ if (m.find()) {
+ pageSum = Integer.parseInt(m.group(1).replace(",", ""));
+ firstPage = m.group(2);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Get page info, previous page, next page, image url
+ *
+ * @param pageUrlStr
+ * @return True if get
+ */
+ public boolean getPageInfoSumForPage(String pageUrlStr) {
+ String pageContent = getPageContent(pageUrlStr);
+ if (pageContent.length() == 0)
+ return false;
+
+ Pattern p = Pattern.compile("]*id=\"prev\"[^<>]*href=\"([^<>\"]+)\">
]*/>.+
]id=\"next\"[^<>]*href=\"([^<>\"]+)\">
]*/>.+
![]()
]*src=\"([^<>\"]+?)\"[^<>]*style=\"[^<>\"]*\"[^<>]*/>");
+ Matcher m = p.matcher(pageContent);
+ if (m.find()) {
+ prePage = m.group(1);
+ nextPage = m.group(2);
+ imageUrlStr = StringEscapeUtils.unescapeHtml4(m.group(3));
+ return true;
+ }
+ return false;
}
}
diff --git a/src/com/hippo/ehviewer/util/Favourite.java b/src/com/hippo/ehviewer/util/Favourite.java
index 954ce59a8..6b91e497f 100644
--- a/src/com/hippo/ehviewer/util/Favourite.java
+++ b/src/com/hippo/ehviewer/util/Favourite.java
@@ -109,10 +109,6 @@ public class Favourite {
* @return True if remove successfully
*/
public static boolean remove(int index) {
- if (!mInit) {
- throw new IllegalStateException("Please init Favourite first.");
- }
-
mFavouriteLmd.remove(index);
String key = mListOrder.remove(index);
Util.putStrings(mFavouritePre, LIST_ORDER, mListOrder);
@@ -126,9 +122,6 @@ public class Favourite {
* @return
*/
public static ArrayList
getFavouriteList() {
- if (!mInit) {
- throw new IllegalStateException("Please init Favourite first.");
- }
return mFavouriteLmd;
}
diff --git a/src/com/hippo/ehviewer/util/Tag.java b/src/com/hippo/ehviewer/util/Tag.java
index 18b4053e7..0e7963705 100644
--- a/src/com/hippo/ehviewer/util/Tag.java
+++ b/src/com/hippo/ehviewer/util/Tag.java
@@ -25,9 +25,8 @@ public class Tag {
private static ArrayList mTags = new ArrayList();
private static boolean mInit = false;
- private static final String NOT_INIT_ERROR_INFO = "Please init Tag first.";
/**
- * Init Favourite
+ * Init Tag
*
* @param context Application context
*/
@@ -51,9 +50,6 @@ public class Tag {
}
private static void getTag() {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
-
String[] allOrder = Util.getStrings(mTagPre, LIST_ORDER);
if (allOrder == null)
@@ -82,9 +78,6 @@ public class Tag {
* @return
*/
public static boolean add(String key, ListUrls tag) {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
-
// Check contain this item or not
if (mListOrder.indexOf(key) == -1) {
mListOrder.add(key);
@@ -133,9 +126,6 @@ public class Tag {
* @return True if remove successfully
*/
public static boolean remove(String key) {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
-
int index = mListOrder.indexOf(key);
if (index != -1) {
mListOrder.remove(index);
@@ -154,9 +144,6 @@ public class Tag {
* @return True if remove successfully
*/
public static boolean remove(int index) {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
-
mTags.remove(index);
String key = mListOrder.remove(index);
mTagPre.edit().remove(key).apply();
@@ -198,8 +185,6 @@ public class Tag {
* @return
*/
public static ArrayList getTagList() {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
return mTags;
}
@@ -209,8 +194,6 @@ public class Tag {
* @return
*/
public static ArrayList getKeyList() {
- if (!mInit)
- throw new IllegalStateException(NOT_INIT_ERROR_INFO);
return mListOrder;
}
diff --git a/src/com/hippo/ehviewer/util/Ui.java b/src/com/hippo/ehviewer/util/Ui.java
index ccd825c4a..cc4d31b44 100644
--- a/src/com/hippo/ehviewer/util/Ui.java
+++ b/src/com/hippo/ehviewer/util/Ui.java
@@ -150,6 +150,7 @@ public class Ui {
}
if (viewGroup == null || rawRateString == null)
return;
+ viewGroup.removeAllViews();
float num = 0;
try{
num = Float.parseFloat(rawRateString);
diff --git a/src/com/hippo/ehviewer/util/Util.java b/src/com/hippo/ehviewer/util/Util.java
index a05ead698..fb59e1635 100644
--- a/src/com/hippo/ehviewer/util/Util.java
+++ b/src/com/hippo/ehviewer/util/Util.java
@@ -38,7 +38,7 @@ public class Util {
private static String TAG = "Util";
/**
- * Put InputStream to File, default bufferSize is 16 * 1024
+ * Put InputStream to File, default bufferSize is 512 * 1024
*
* @param is
* @param file
@@ -50,7 +50,7 @@ public class Util {
}
public static void copy(InputStream is, OutputStream os) throws IOException {
- byte[] buffer = new byte[16 * 1024];
+ byte[] buffer = new byte[512 * 1024];
int bytesRead;
while((bytesRead = is.read(buffer)) !=-1)
os.write(buffer, 0, bytesRead);
@@ -65,11 +65,36 @@ public class Util {
public static int getResourcesType(String url) {
int type = BITMAP;
int index = url.lastIndexOf('.');
- if (index != -1 && url.substring(index + 1).toLowerCase().equals("gif"))
+ if (index != -1 && getExtension(url).equals("gif"))
type = MOVIE;
return type;
}
+ public static String getExtension(String url) {
+ int index = url.lastIndexOf('.');
+ if (index != -1)
+ return url.substring(index + 1).toLowerCase();
+ else
+ return "png";
+ }
+
+ public static String getName(String fileName) {
+ int index = fileName.lastIndexOf('.');
+ if (index != -1)
+ return fileName.substring(0, index).toLowerCase();
+ else
+ return "png";
+ }
+
+ public static boolean isNumber(String str) {
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ if (ch < '0' || ch > '9')
+ return false;
+ }
+ return true;
+ }
+
public static String byteArrayToHexString(byte[] b) {
StringBuilder sb = new StringBuilder(b.length * 2);
for (byte element : b) {
@@ -130,4 +155,20 @@ public class Util {
sb.delete(length - 1, length);
shaper.edit().putString(key, byteArrayToHexString(sb.toString().getBytes())).apply();
}
+
+ public static void closeStreamQuietly (InputStream is) {
+ try {
+ if (is != null)
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+
+ public static void closeStreamQuietly (OutputStream os) {
+ try {
+ if (os != null)
+ os.close();
+ } catch (IOException e) {
+ }
+ }
}