优化本地书籍阅读

pull/5/head
fengyuecanzhu 4 years ago
parent 4622eef10a
commit 7ee3566024
  1. 18
      app/src/main/java/xyz/fycz/myreader/greendao/service/BookService.java
  2. 14
      app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java

@ -129,10 +129,18 @@ public class BookService extends BaseService {
* @return
*/
public Book findBookByAuthorAndName(String bookName, String author) {
try {
return GreenDaoManager.getInstance().getSession().getBookDao()
.queryBuilder()
.where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author))
.unique();
} catch (Exception e) {
e.printStackTrace();
return GreenDaoManager.getInstance().getSession().getBookDao()
.queryBuilder()
.where(BookDao.Properties.Name.eq(bookName), BookDao.Properties.Author.eq(author))
.list().get(0);
}
}
/**
@ -142,10 +150,18 @@ public class BookService extends BaseService {
* @return
*/
public Book findBookByPath(String path) {
try {
return GreenDaoManager.getInstance().getSession().getBookDao()
.queryBuilder()
.where(BookDao.Properties.ChapterUrl.eq(path))
.unique();
} catch (Exception e) {
e.printStackTrace();
return GreenDaoManager.getInstance().getSession().getBookDao()
.queryBuilder()
.where(BookDao.Properties.ChapterUrl.eq(path))
.list().get(0);
}
}
/**
@ -166,9 +182,11 @@ public class BookService extends BaseService {
* @param book
*/
public void deleteBook(Book book) {
try {
deleteEntity(book);
mChapterService.deleteBookALLChapterById(book.getId());
mBookMarkService.deleteBookALLBookMarkById(book.getId());
}catch (Exception ignored){}
}
/**

@ -316,8 +316,22 @@ public class LocalPageLoader extends PageLoader {
seekPos += chapterContent.length();
if (mChapterList.size() == 0) { //如果当前没有章节,那么就是序章
//创建序章
Chapter preChapter = new Chapter();
preChapter.setTitle("序章");
preChapter.setStart(0);
preChapter.setEnd(chapterContent.getBytes(mCharset).length); //获取String的byte值,作为最终值
//如果序章大小大于30才添加进去
if (preChapter.getEnd() - preChapter.getStart() > 30) {
mChapterList.add(preChapter);
}else {
//加入简介
mCollBook.setDesc(chapterContent);
}
//创建当前章节
Chapter curChapter = new Chapter();
curChapter.setTitle(matcher.group());

Loading…
Cancel
Save