Skip to content

Commit

Permalink
Fixed automatic cut picture missing one page of the question
Browse files Browse the repository at this point in the history
  • Loading branch information
Haleydu committed Sep 11, 2020
1 parent c1cd49c commit 4e4511c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/hiroshi/cimoc/core/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public int compare(DocumentFile lhs, DocumentFile rhs) {
}
});

List<ImageUrl> list = Storage.buildImageUrlFromDocumentFile(files, chapter.getPath(), chapter.getCount());
List<ImageUrl> list = Storage.buildImageUrlFromDocumentFile(files, chapter.getPath(), chapter.getCount(),chapter);
if (list.size() != 0) {
subscriber.onNext(list);
subscriber.onCompleted();
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/hiroshi/cimoc/core/Local.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public int compare(DocumentFile lhs, DocumentFile rhs) {
return lhs.getName().compareTo(rhs.getName());
}
});
List<ImageUrl> list = Storage.buildImageUrlFromDocumentFile(files, chapter.getTitle(), chapter.getCount());

List<ImageUrl> list = Storage.buildImageUrlFromDocumentFile(files, chapter.getTitle(), chapter.getCount(), chapter);
if (list.size() != 0) {
subscriber.onNext(list);
subscriber.onCompleted();
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/hiroshi/cimoc/core/Manga.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void call(Subscriber<? super List<ImageUrl>> subscriber) {
}).subscribeOn(Schedulers.io());
}

public static List<ImageUrl> getImageUrls(Parser parser, int source, String cid, String path, String title,ChapterManager mChapterManager) throws InterruptedIOException {
public static List<ImageUrl> getImageUrls(Parser parser, int source, String cid, String path, String title, ChapterManager mChapterManager) throws InterruptedIOException {
List<ImageUrl> list = new ArrayList<>();
// Mongo mongo = new Mongo();
Response response = null;
Expand All @@ -183,9 +183,9 @@ public static List<ImageUrl> getImageUrls(Parser parser, int source, String cid,
Request request = parser.getImagesRequest(cid, path);
response = App.getHttpClient().newCall(request).execute();
if (response.isSuccessful()) {
Chapter chapter = mChapterManager.getChapter(path,title);
if (chapter!=null){
list.addAll(parser.parseImages(response.body().string(),chapter));
List<Chapter> chapter = mChapterManager.getChapter(path, title);
if (chapter != null && chapter.size() >= 1) {
list.addAll(parser.parseImages(response.body().string(), chapter.get(0)));
}
if (list.size() == 0) {
list.addAll(parser.parseImages(response.body().string()));
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/hiroshi/cimoc/core/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.Uri;
import android.os.Environment;

import com.hiroshi.cimoc.model.Chapter;
import com.hiroshi.cimoc.model.ImageUrl;
import com.hiroshi.cimoc.saf.DocumentFile;
import com.hiroshi.cimoc.utils.DecryptionUtils;
Expand Down Expand Up @@ -144,7 +145,7 @@ public void call(Subscriber<? super Uri> subscriber) {
}).subscribeOn(Schedulers.io());
}

public static List<ImageUrl> buildImageUrlFromDocumentFile(List<DocumentFile> list, String chapter, int max) {
public static List<ImageUrl> buildImageUrlFromDocumentFile(List<DocumentFile> list, String chapterStr, int max, Chapter chapter) {
int count = 0;
List<ImageUrl> result = new ArrayList<>(list.size());
for (DocumentFile file : list) {
Expand All @@ -156,10 +157,12 @@ public static List<ImageUrl> buildImageUrlFromDocumentFile(List<DocumentFile> li
if (uri.startsWith("file")) { // content:// 解码会出错 file:// 中文路径如果不解码 Fresco 读取不了
uri = DecryptionUtils.urlDecrypt(uri);
}
ImageUrl image = new ImageUrl(++count, uri, false);
Long comicChapter = chapter.getId();
Long id = Long.parseLong(comicChapter + "300" + count);
ImageUrl image = new ImageUrl(id, chapter.getSourceComic(),++count, uri, false);
image.setHeight(opts.outHeight);
image.setWidth(opts.outWidth);
image.setChapter(chapter);
image.setChapter(chapterStr);
result.add(image);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public Observable<List<Chapter>> getListChapter(Long sourceComic) {
.list();
}

public Chapter getChapter(String path,String title) {
public List<Chapter> getChapter(String path,String title) {
return mChapterDao.queryBuilder()
.where(ChapterDao.Properties.Path.eq(path),ChapterDao.Properties.Title.eq(title))
.unique();
.list();
}


Expand Down
30 changes: 6 additions & 24 deletions app/src/main/java/com/hiroshi/cimoc/model/ImageUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.greenrobot.greendao.annotation.Generated;

/**
Expand All @@ -18,9 +20,8 @@ public class ImageUrl {
public static final int STATE_NULL = 0;
public static final int STATE_PAGE_1 = 1;
public static final int STATE_PAGE_2 = 2;
private static AtomicInteger count = new AtomicInteger(0);

@Id
@Id(autoincrement = true)
private Long id; // 唯一标识
@NotNull
private Long comicChapter;
Expand All @@ -36,28 +37,9 @@ public class ImageUrl {
private boolean success; // 图片显示成功
private boolean download; // 下载的图片

public ImageUrl(int num, String url, boolean lazy) {
this(num, new String[]{url}, lazy);
}

public ImageUrl(int num, String[] urls, boolean lazy) {
this(num, urls, STATE_NULL, lazy);
}

public ImageUrl(int num, String[] urls, int state, boolean lazy) {
this(num, urls, null, state, lazy);
}

public ImageUrl(int num, String[] urls, String chapter, int state, boolean lazy) {
this.num = num;
this.urls = urls;
this.chapter = chapter;
this.state = state;
this.height = 0;
this.width = 0;
this.lazy = lazy;
this.loading = false;
this.success = false;
public ImageUrl(Long id, Long comicChapter, int num, String[] urls, String chapter, int state, boolean lazy) {
this(id, comicChapter, num, urls, chapter, state, 0, 0, lazy,
false, false,false);
}

public ImageUrl(Long id,Long comicChapter,int num, String url, boolean lazy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected void updateProgress() {
@Override
public void onPicturePaging(ImageUrl image) {
int pos = mReaderAdapter.getPositionById(image.getId());
mReaderAdapter.add(pos + 1, new ImageUrl(image.getNum(), image.getUrls(),
mReaderAdapter.add(pos + 1, new ImageUrl(image.getId()+900,image.getComicChapter(),image.getNum(), image.getUrls(),
image.getChapter(), ImageUrl.STATE_PAGE_2, false));
}

Expand Down

0 comments on commit 4e4511c

Please sign in to comment.