From 72acb8e74dbfb541829e76c7db58c423ad4d6cc7 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Mon, 14 Jun 2021 12:28:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81epub=E9=98=85=E8=AF=BB(?= =?UTF-8?q?=E4=BB=85=E6=94=AF=E6=8C=81=E6=96=87=E5=AD=97)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myreader/ui/activity/ReadActivity.java | 2 +- .../ui/adapter/ChapterTitleAdapter.java | 2 +- .../myreader/widget/page/EpubPageLoader.java | 18 ++++++++++-------- .../myreader/widget/page/LocalPageLoader.java | 8 +++++--- .../myreader/widget/page/NetPageLoader.java | 3 ++- .../fycz/myreader/widget/page/PageLoader.java | 13 +++++++++++-- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java index 4e71a5d..2b362e4 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java @@ -796,7 +796,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe try { skipToChapterAndPage(chapterAndPage[0], chapterAndPage[1]); } catch (Exception e) { - ToastUtils.showError("章节跳转失败,请截图联系作者。\n" + + ToastUtils.showError("章节跳转失败\n" + e.getMessage()); e.printStackTrace(); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/ChapterTitleAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/ChapterTitleAdapter.java index 3b22341..a3b5ce8 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/ChapterTitleAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/ChapterTitleAdapter.java @@ -68,7 +68,7 @@ public class ChapterTitleAdapter extends ArrayAdapter { final Chapter chapter = getItem(postion); // viewHolder.tvTitle.setText("【" + chapter.getTitle() + "】"); viewHolder.tvTitle.setText(chapter.getTitle()); - if (ChapterService.isChapterCached(chapter.getBookId(), chapter.getTitle()) || chapter.getEnd() > 0 ) { + if (ChapterService.isChapterCached(chapter.getBookId(), chapter.getTitle()) || chapter.getEnd() > 0) { viewHolder.tvTitle.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(getContext(),R.drawable.selector_category_load), null, null, null); } else { viewHolder.tvTitle.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(getContext(),R.drawable.selector_category_unload), null, null, null); diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java index dc89a16..de01364 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java @@ -1,12 +1,8 @@ package xyz.fycz.myreader.widget.page; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; import android.text.TextUtils; import android.util.Log; - import net.sf.jazzlib.ZipFile; import org.jsoup.Jsoup; @@ -18,6 +14,7 @@ import org.jsoup.select.Elements; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; @@ -27,7 +24,6 @@ import java.util.List; import io.reactivex.Observable; import io.reactivex.ObservableOnSubscribe; -import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; @@ -65,6 +61,8 @@ public class EpubPageLoader extends PageLoader { Observable.create((ObservableOnSubscribe) e -> { File bookFile = new File(mCollBook.getChapterUrl()); + if (!bookFile.exists()) + e.onError(new FileNotFoundException("书籍源文件不存在\n" + mCollBook.getChapterUrl())); epubBook = readBook(bookFile); if (epubBook == null) { @@ -76,7 +74,7 @@ public class EpubPageLoader extends PageLoader { } mCharset = Charset.forName(mCollBook.getInfoUrl()); - if (TextUtils.isEmpty(mCollBook.getImgUrl())){ + if (TextUtils.isEmpty(mCollBook.getImgUrl())) { saveCover(); } e.onNext(mCollBook); @@ -99,7 +97,7 @@ public class EpubPageLoader extends PageLoader { @Override public void onError(Throwable e) { - chapterError(e.getMessage()); + error(STATUS_CATEGORY_ERROR, e.getMessage()); } }); } @@ -157,7 +155,9 @@ public class EpubPageLoader extends PageLoader { private List loadChapters() { Metadata metadata = epubBook.getMetadata(); - mCollBook.setName(metadata.getFirstTitle()); + if (!TextUtils.isEmpty(metadata.getFirstTitle())) { + mCollBook.setName(metadata.getFirstTitle()); + } if (metadata.getAuthors().size() > 0) { String author = metadata.getAuthors().get(0).toString().replaceAll("^, |, $", ""); mCollBook.setAuthor(author); @@ -192,12 +192,14 @@ public class EpubPageLoader extends PageLoader { } else { bean.setTitle(title); } + bean.setEnd(1); mChapterList.add(bean); } } else { parseMenu(refs, 0); for (int i = 0; i < mChapterList.size(); i++) { mChapterList.get(i).setNumber(i); + mChapterList.get(i).setEnd(1); } } diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java index f4c750f..b95b2e2 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java @@ -68,7 +68,10 @@ public class LocalPageLoader extends PageLoader { public void refreshChapterList() { // 对于文件是否存在,或者为空的判断,不作处理。 ==> 在文件打开前处理过了。 mBookFile = new File(mCollBook.getChapterUrl()); - + if (!mBookFile.exists()) { + error(STATUS_CATEGORY_ERROR, "书籍源文件不存在\n" + mCollBook.getChapterUrl()); + return; + } mCharset = mCollBook.getInfoUrl(); // 判断文件是否已经加载过,并具有缓存 @@ -113,7 +116,7 @@ public class LocalPageLoader extends PageLoader { @Override public void onError(Throwable e) { - chapterError(e.getLocalizedMessage()); + error(STATUS_CATEGORY_ERROR, e.getLocalizedMessage()); Log.d(TAG, "file load error:" + e.toString()); } }); @@ -366,7 +369,6 @@ public class LocalPageLoader extends PageLoader { } - @Override protected BufferedReader getChapterReader(Chapter chapter) throws Exception { if (chapter.getEnd() > 0) { diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java index 2ff4916..03f4f47 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java @@ -70,6 +70,7 @@ public class NetPageLoader extends PageLoader { chapter.setId(StringHelper.getStringRandom(25)); chapter.setBookId(mCollBook.getId()); } + mChapterService.addChapters(newChapters); emitter.onNext(newChapters); })) .compose(RxUtils::toSimpleSingle) @@ -94,7 +95,7 @@ public class NetPageLoader extends PageLoader { @Override public void onError(Throwable e) { - chapterError(e.getLocalizedMessage()); + error(STATUS_CATEGORY_ERROR, e.getLocalizedMessage()); Log.d(TAG, "file load error:" + e.toString()); } }); diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java index 256efd1..5611a0d 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java @@ -32,6 +32,7 @@ import xyz.fycz.myreader.model.audio.ReadAloudService; import xyz.fycz.myreader.util.IOUtils; import xyz.fycz.myreader.util.ToastUtils; import xyz.fycz.myreader.util.help.ChapterContentHelp; +import xyz.fycz.myreader.util.help.StringHelper; import xyz.fycz.myreader.util.utils.BitmapUtil; import xyz.fycz.myreader.util.utils.MeUtils; import xyz.fycz.myreader.util.utils.RxUtils; @@ -62,6 +63,7 @@ public abstract class PageLoader { public static final int STATUS_PARING = 6; // 正在解析 (装载本地数据) public static final int STATUS_PARSE_ERROR = 7; // 本地文件解析错误(暂未被使用) public static final int STATUS_CATEGORY_EMPTY = 8; // 获取到的目录为空 + public static final int STATUS_CATEGORY_ERROR = 9; // 获取目录失败 private String errorMsg = ""; // 默认的显示参数配置 @@ -780,8 +782,12 @@ public abstract class PageLoader { } public void chapterError(String msg) { + error(STATUS_ERROR, msg); + } + + public void error(int status, String msg){ //加载错误 - mStatus = STATUS_ERROR; + mStatus = status; errorMsg = msg; mPageView.drawCurPage(false); } @@ -1046,8 +1052,11 @@ public abstract class PageLoader { case STATUS_CATEGORY_EMPTY: tip = "目录列表为空"; break; + case STATUS_CATEGORY_ERROR: + tip = "目录加载失败\n" + errorMsg; + break; } - if (mStatus == STATUS_ERROR) { + if (mStatus == STATUS_ERROR || mStatus == STATUS_CATEGORY_ERROR) { drawErrorMsg(canvas, tip, 0); } else { //将提示语句放到正中间