From d6d4efee07998b93cde3ac83f4afa26eb68e2762 Mon Sep 17 00:00:00 2001 From: GKF Date: Sat, 29 Sep 2018 14:56:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monke/monkeybook/help/BookshelfHelp.java | 6 ++++-- .../monkeybook/model/WebBookModelImpl.java | 18 +++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/monke/monkeybook/help/BookshelfHelp.java b/app/src/main/java/com/monke/monkeybook/help/BookshelfHelp.java index b7924f8235..227bc4ff52 100644 --- a/app/src/main/java/com/monke/monkeybook/help/BookshelfHelp.java +++ b/app/src/main/java/com/monke/monkeybook/help/BookshelfHelp.java @@ -120,18 +120,20 @@ public static void delChapter(String folderName, String fileName) { /** * 存储章节 */ - public static void saveChapterInfo(String folderName, String fileName, String content) { + public static boolean saveChapterInfo(String folderName, String fileName, String content) { if (content == null) { - return; + return false; } File file = getBookFile(formatFileName(folderName), formatFileName(fileName)); //获取流并存储 try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { writer.write(content); writer.flush(); + return true; } catch (IOException e) { MApplication.getInstance().setDownloadPath(FileHelp.getCachePath()); e.printStackTrace(); + return false; } } diff --git a/app/src/main/java/com/monke/monkeybook/model/WebBookModelImpl.java b/app/src/main/java/com/monke/monkeybook/model/WebBookModelImpl.java index 8d9aa24de4..9d856a18f6 100644 --- a/app/src/main/java/com/monke/monkeybook/model/WebBookModelImpl.java +++ b/app/src/main/java/com/monke/monkeybook/model/WebBookModelImpl.java @@ -6,7 +6,6 @@ import com.hwangjr.rxbus.RxBus; import com.monke.monkeybook.bean.BookContentBean; import com.monke.monkeybook.bean.BookShelfBean; -import com.monke.monkeybook.bean.BookSourceBean; import com.monke.monkeybook.bean.ChapterListBean; import com.monke.monkeybook.bean.SearchBookBean; import com.monke.monkeybook.dao.ChapterListBeanDao; @@ -159,15 +158,16 @@ private Observable upChapterList(String bookName, String tag, B .where(ChapterListBeanDao.Properties.DurChapterUrl.eq(bookContentBean.getDurChapterUrl())).unique(); if (chapterListBean != null) { bookContentBean.setNoteUrl(chapterListBean.getNoteUrl()); - BookshelfHelp.saveChapterInfo(bookName + "-" + tag, + if (BookshelfHelp.saveChapterInfo(bookName + "-" + tag, String.format("%d-%s", chapterListBean.getDurChapterIndex(), chapterListBean.getDurChapterName()), - bookContentBean.getDurChapterContent()); - BookshelfHelp.setChapterIsCached(bookName, chapterListBean, true); - DbHelper.getInstance().getmDaoSession().getChapterListBeanDao().update(chapterListBean); - RxBus.get().post(RxBusTag.CHAPTER_CHANGE, chapterListBean); - e.onNext(bookContentBean); - e.onComplete(); - return; + bookContentBean.getDurChapterContent())) { + BookshelfHelp.setChapterIsCached(bookName, chapterListBean, true); + DbHelper.getInstance().getmDaoSession().getChapterListBeanDao().update(chapterListBean); + RxBus.get().post(RxBusTag.CHAPTER_CHANGE, chapterListBean); + e.onNext(bookContentBean); + e.onComplete(); + return; + } } } e.onError(new Throwable("保存章节出错"));