Skip to content

Commit ff7c6c1

Browse files
committed
Apply Dar9586/NClientV2 !762
Dar9586#762
1 parent 8862712 commit ff7c6c1

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

app/src/main/java/com/dar/nclientv2/api/SimpleGallery.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public SimpleGallery(Context context, Element e) {
8080
a = e.getElementsByTag("img").first();
8181
temp = a.hasAttr("data-src") ? a.attr("data-src") : a.attr("src");
8282
mediaId = Integer.parseInt(temp.substring(temp.indexOf("galleries") + 10, temp.lastIndexOf('/')));
83-
thumbnail = Page.charToExt(temp.charAt(temp.length() - 3));
83+
String extension = temp.substring(temp.lastIndexOf('.') + 1);
84+
thumbnail = Page.charToExt(extension.charAt(0));
8485
title = e.getElementsByTag("div").first().text();
8586
if (context != null && id > Global.getMaxId()) Global.updateMaxId(context, id);
8687
}
@@ -93,13 +94,18 @@ public SimpleGallery(Gallery gallery) {
9394
}
9495

9596
private static String extToString(ImageExt ext) {
97+
if (ext == null) {
98+
return null;
99+
}
96100
switch (ext) {
97101
case GIF:
98102
return "gif";
99103
case PNG:
100104
return "png";
101105
case JPG:
102106
return "jpg";
107+
case WEBP:
108+
return "webp";
103109
}
104110
return null;
105111
}

app/src/main/java/com/dar/nclientv2/api/components/GalleryData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ private void readPagePath(String path) throws IOException {
315315
case 'p':
316316
case 'j':
317317
case 'g':
318+
case 'w':
318319
if (specialImages) {
319320
cover = new Page(ImageType.COVER, Page.charToExt(actualChar));
320321
thumbnail = new Page(ImageType.THUMBNAIL, Page.charToExt(actualChar));

app/src/main/java/com/dar/nclientv2/api/components/Page.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static String extToString(ImageExt ext) {
9090
return "png";
9191
case JPG:
9292
return "jpg";
93+
case WEBP:
94+
return "webp";
9395
}
9496
return null;
9597
}
@@ -102,6 +104,8 @@ public static char extToChar(ImageExt imageExt) {
102104
return 'p';
103105
case JPG:
104106
return 'j';
107+
case WEBP:
108+
return 'w';
105109
}
106110
return '\0';
107111
}
@@ -114,6 +118,8 @@ public static ImageExt charToExt(int ext) {
114118
return ImageExt.PNG;
115119
case 'j':
116120
return ImageExt.JPG;
121+
case 'w':
122+
return ImageExt.WEBP;
117123
}
118124
return null;
119125
}

app/src/main/java/com/dar/nclientv2/api/enums/ImageExt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.dar.nclientv2.api.enums;
22

33
public enum ImageExt {
4-
JPG("jpg"), PNG("png"), GIF("gif");
4+
JPG("jpg"), PNG("png"), GIF("gif"), WEBP("webp");
55

66
private final char firstLetter;
77
private final String name;

app/src/main/java/com/dar/nclientv2/api/local/LocalGallery.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public LocalGallery[] newArray(int size) {
3434
return new LocalGallery[size];
3535
}
3636
};
37-
private static final Pattern FILE_PATTERN = Pattern.compile("^(\\d{1,9})\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
37+
private static final Pattern FILE_PATTERN = Pattern.compile("^(\\d{1,9})\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
3838
private static final Pattern DUP_PATTERN = Pattern.compile("^(.*)\\.DUP\\d+$");
3939
private static final Pattern IDFILE_PATTERN = Pattern.compile("^\\.\\d{1,6}$");
4040
private final GalleryFolder folder;
@@ -106,6 +106,8 @@ public static File getPage(File dir, int page) {
106106
if (dir == null || !dir.exists()) return null;
107107
String pag = String.format(Locale.US, "%03d.", page);
108108
File x;
109+
x = new File(dir, pag + "webp");
110+
if (x.exists()) return x;
109111
x = new File(dir, pag + "jpg");
110112
if (x.exists()) return x;
111113
x = new File(dir, pag + "png");

app/src/main/java/com/dar/nclientv2/files/GalleryFolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public GalleryFolder[] newArray(int size) {
3232
return new GalleryFolder[size];
3333
}
3434
};
35-
private static final Pattern FILE_PATTERN = Pattern.compile("^0*(\\d{1,9})\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
35+
private static final Pattern FILE_PATTERN = Pattern.compile("^0*(\\d{1,9})\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
3636
private static final Pattern IDFILE_PATTERN = Pattern.compile("^\\.(\\d{1,6})$");
3737
private static final String NOMEDIA_FILE = ".nomedia";
3838
private final SparseArrayCompat<PageFile> pageArray = new SparseArrayCompat<>();

app/src/main/java/com/dar/nclientv2/files/PageFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public PageFile[] newArray(int size) {
2828
return new PageFile[size];
2929
}
3030
};
31-
private static final Pattern DEFAULT_THUMBNAIL = Pattern.compile("^0*1\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
32-
private static final Pattern VALID_PAGE = Pattern.compile("^0*(\\d+)\\.(gif|png|jpg)$", Pattern.CASE_INSENSITIVE);
31+
private static final Pattern DEFAULT_THUMBNAIL = Pattern.compile("^0*1\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
32+
private static final Pattern VALID_PAGE = Pattern.compile("^0*(\\d+)\\.(gif|png|jpg|webp)$", Pattern.CASE_INSENSITIVE);
3333
private final ImageExt ext;
3434
private final int page;
3535

0 commit comments

Comments
 (0)