From f1f1c6ecc8a84559dcb090addb44c737fea39a2d Mon Sep 17 00:00:00 2001 From: mwang <8205347@qq.com> Date: Wed, 6 Mar 2019 22:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E4=B8=80=E4=B8=AA=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=BC=93=E5=AD=98=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhuike/Fragments/BasicFragment.java | 2 +- .../deiniu/zhuike/adapter/ShelfAdapter.java | 13 +- .../main/java/com/deiniu/zhuike/db/Book.java | 23 +- .../com/deiniu/zhuike/db/BookChapter.java | 30 ++- .../com/deiniu/zhuike/utils/BookUtil.java | 232 ++++++++++++++++-- .../com/deiniu/zhuike/utils/PageFactory.java | 153 +++++++++--- .../java/com/deiniu/zhuike/utils/TRPage.java | 13 +- 7 files changed, 393 insertions(+), 73 deletions(-) diff --git a/zhuike/src/main/java/com/deiniu/zhuike/Fragments/BasicFragment.java b/zhuike/src/main/java/com/deiniu/zhuike/Fragments/BasicFragment.java index ddef06b..56031b7 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/Fragments/BasicFragment.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/Fragments/BasicFragment.java @@ -140,7 +140,7 @@ public abstract class BasicFragment extends Fragment { Book book1 = (Book)LitePal.find(Book.class,book.getId()); book.setBegin(book1.getBegin()); - + book.setBiginChapt(book1.getBiginChapt()); Toast.makeText(activity, book.getBookname() + "加载", Toast.LENGTH_SHORT).show(); final String path = book.getBookpath(); diff --git a/zhuike/src/main/java/com/deiniu/zhuike/adapter/ShelfAdapter.java b/zhuike/src/main/java/com/deiniu/zhuike/adapter/ShelfAdapter.java index 7436425..848d2b3 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/adapter/ShelfAdapter.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/adapter/ShelfAdapter.java @@ -165,16 +165,17 @@ public class ShelfAdapter extends BaseAdapter implements DragGridListener { * @param bookLists */ public void updateBookPosition (int position,int databaseId,List bookLists) { - Book bookList = new Book(); + Book book = new Book(); String bookpath = bookLists.get(position).getBookpath(); String bookname = bookLists.get(position).getBookname(); - bookList.setBookpath(bookpath); - bookList.setBookname(bookname); - bookList.setBegin(bookLists.get(position).getBegin()); - bookList.setCharset(bookLists.get(position).getCharset()); + book.setBookpath(bookpath); + book.setBookname(bookname); + book.setBegin(bookLists.get(position).getBegin()); + book.setBiginChapt(bookLists.get(position).getBiginChapt()); + book.setCharset(bookLists.get(position).getCharset()); //开线程保存改动的数据到数据库 //使用litepal数据库框架update时每次只能update一个id中的一条信息,如果相同则不更新。 - upDateBookToSqlite3(databaseId , bookList); + upDateBookToSqlite3(databaseId , book); } /** diff --git a/zhuike/src/main/java/com/deiniu/zhuike/db/Book.java b/zhuike/src/main/java/com/deiniu/zhuike/db/Book.java index d23e348..004fb77 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/db/Book.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/db/Book.java @@ -8,15 +8,25 @@ import java.io.Serializable; public class Book extends LitePalSupport implements Serializable{ private int id; + private int bookId; private String bookname; private String bookpath; private long begin; + private long biginChapt=1; private String charset; private String cate; private String author; private String lastChapter; private String desc; + private long lastUpdate; + public int getBookId() { + return bookId; + } + + public void setBookId(int bookId) { + this.bookId = bookId; + } public String getCate() { return cate; } @@ -40,9 +50,6 @@ public class Book extends LitePalSupport implements Serializable{ public void setLastUpdate(long lastUpdate) { this.lastUpdate = lastUpdate; } - - private long lastUpdate; - public String getLastChapter() { return lastChapter; } @@ -98,4 +105,14 @@ public class Book extends LitePalSupport implements Serializable{ public void setDesc(String desc) { this.desc = desc; } + + public long getBiginChapt() { + return biginChapt; + } + + public void setBiginChapt(long biginChapt) { + this.biginChapt = biginChapt; + } + + } diff --git a/zhuike/src/main/java/com/deiniu/zhuike/db/BookChapter.java b/zhuike/src/main/java/com/deiniu/zhuike/db/BookChapter.java index 7366dbf..4d7659c 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/db/BookChapter.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/db/BookChapter.java @@ -6,15 +6,41 @@ import org.litepal.crud.LitePalSupport; public class BookChapter extends LitePalSupport { private int id; + private int bookId; private String bookpath; private String chapterName; private long bookChapterStartPos; + private String chapterUrl; + private int length; + private String chapterPath; - + public String getChapterPath() { + return chapterPath; + } + public void setChapterPath(String chapterPath) { + this.chapterPath = chapterPath; + } + public String getChapterUrl() { + return chapterUrl; + } + public void setChapterUrl(String chapterUrl) { + this.chapterUrl = chapterUrl; + } + public int getLength() { + return length; + } + public void setLength(int length) { + this.length = length; + } public int getId() { return id; } - + public int getBookId() { + return bookId; + } + public void setBookId(int bookId) { + this.bookId = bookId; + } public void setId(int id) { this.id = id; } diff --git a/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java b/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java index 290a6a0..918db58 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/utils/BookUtil.java @@ -22,14 +22,18 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class BookUtil { public static final String TAG ="BookUtil"; - private static final String cachedPath = Environment.getExternalStorageDirectory() + "/zhuike/"; + private static final String cachedPath = Environment.getExternalStorageDirectory() + "/zhuike/cache/"; + private static final String chapterPath = Environment.getExternalStorageDirectory() + "/zhuike/chapter/"; + private static final String charachterType = "utf-8";//"UTF-16LE"; //存储的字符数 - public static final int cachedSize = 30000; + public static final int cachedSize = 300000; // protected final ArrayList> myArray = new ArrayList<>(); public static final String lineBreakChar ="\n"; @@ -40,9 +44,25 @@ public class BookUtil { private String m_strCharsetName; private String bookName; private String bookPath; + + public void setBookLen(long bookLen) { + this.bookLen = bookLen; + } + private long bookLen; private long position; - private Book bookList; + private Book book; + + public void setChapterNo(int chapterNo) { + this.chapterNo = chapterNo; + } + + public int getChapterNo() { + return chapterNo; + } + + private int chapterNo;//当前章节 + public String getLineBreakChar(){ return "\n"; @@ -53,24 +73,38 @@ public class BookUtil { if (!file.exists()){ file.mkdir(); } + File file2 = new File(chapterPath); + if (!file2.exists()){ + file2.mkdir(); + } } - public synchronized void openBook(Book bookList) throws IOException { - this.bookList = bookList; + public synchronized void openBook(Book book) throws IOException { + this.book = book; //如果当前缓存不是要打开的书本就缓存书本同时删除缓存 //TODO 构建新的缓存策略,几个选项,1:每本书一个缓存 2:控制缓存总大小,超过限制删除旧缓存 3:网络小说的缓存 - if (bookPath == null || !bookPath.equals(bookList.getBookpath())) { - cleanCacheFile(); - this.bookPath = bookList.getBookpath(); - bookName = FileUtils.getFileName(bookPath); - cacheBook(); + directoryList = LitePal.where("bookId=?",book.getId()+"").find(BookChapter.class); + + for(BookChapter c :directoryList){ + Log.d(TAG, String.format("bookchapter :%s,fileName :%s, chapter Size %s",c.getChapterName(),c.getChapterPath(),c.getLength())); + } + + + if(directoryList.isEmpty()) { + + if (bookPath == null || !bookPath.equals(book.getBookpath())) { + cleanCacheFile(); + this.bookPath = book.getBookpath(); + bookName = FileUtils.getFileName(bookPath); + cacheBook(); + } } } private void cleanCacheFile(){ - File file = new File(cachedPath); + File file = new File(cachedPath ); if (!file.exists()){ file.mkdir(); }else{ @@ -79,6 +113,19 @@ public class BookUtil { files[i].delete(); } } + + file = new File(getChapterPath()); + + if (!file.exists()){ + file.mkdir(); + }else{ + File[] files = file.listFiles(); + for (int i = 0; i < files.length;i++){ + files[i].delete(); + } + } + + } public int next(boolean back){ @@ -87,7 +134,7 @@ public class BookUtil { position = bookLen; return -1; } - char result = current(); + char result = chaptCurrent(); //current(); if (back) { position -= 1; } @@ -135,7 +182,11 @@ public class BookUtil { return line.toCharArray(); } + public char chaptCurrent(){ + char[] charArray = chaptChars(chapterNo); + return charArray[(int)position-1]; + } public char current(){ // int pos = (int) (position % cachedSize); // int cachePos = (int) (position / cachedSize); @@ -179,16 +230,16 @@ public class BookUtil { //缓存书本 private void cacheBook() throws IOException { - if (TextUtils.isEmpty(bookList.getCharset())) { + if (TextUtils.isEmpty(book.getCharset())) { m_strCharsetName = FileUtils.getCharset(bookPath); if (m_strCharsetName == null) { m_strCharsetName = "utf-8"; } ContentValues values = new ContentValues(); values.put("charset",m_strCharsetName); - LitePal.update(Book.class,values,bookList.getId()); + LitePal.update(Book.class,values,book.getId()); }else{ - m_strCharsetName = bookList.getCharset(); + m_strCharsetName = book.getCharset(); } File file = new File(bookPath); @@ -225,8 +276,9 @@ public class BookUtil { myArray.add(cache); // myArray.add(new WeakReference(buf)); // myArray.set(index,); - // Log.e(TAG,String.format("缓存的内容写入文件\n %s",fileName(index))); - // Log.e(TAG,"---------------------------------------------------------------------------------------------------------"); + Log.e(TAG,String.format("缓存的内容写入文件\n %s",fileName(index))); + Log.e(TAG,"---------------------------------------------------------------------------------------------------------"); + try { File cacheBook = new File(fileName(index)); if (!cacheBook.exists()){ @@ -239,35 +291,91 @@ public class BookUtil { throw new RuntimeException("Error during writing " + fileName(index)); } index ++; - } - new Thread(){ + } + getChapter(); + /*new Thread(){ @Override public void run() { - getChapter(); + getChapter(); } }.start(); + */ } //获取章节 public synchronized void getChapter(){ try { long size = 0; + String title =""; + long start =0; + int chaptFileId=0; + int chaptId =0; + BookChapter bookChapter = null; + OutputStreamWriter writer = null; for (int i = 0; i < myArray.size(); i++) { char[] buf = block(i); String bufStr = new String(buf); String[] paragraphs = bufStr.split(lineBreakChar); // String[] paragraphs = bufStr.split("\r\n"); + for (String str : paragraphs) { // if (str.length() <= 30 && (str.matches(".*第.{1,8}章.*") || str.matches(".*第.{1,8}节.*"))) { if(isChapterTitle(str)) { - BookChapter bookCatalogue = new BookChapter(); - bookCatalogue.setBookChapterStartPos(size); - bookCatalogue.setChapterName(str.replaceAll("###","")); - bookCatalogue.setBookpath(bookPath); - directoryList.add(bookCatalogue); + + if(title.length()==0) { + + title = str; + start =0; + + }else { + + + start = size; + title = str; + } + if(bookChapter!=null) { + bookChapter.setLength((int)(size - start)); + bookChapter.setChapterPath(fileChapterName(chaptId) ); + bookChapter.update(bookChapter.getId()); + directoryList.add(bookChapter); + } + + bookChapter = new BookChapter(); + bookChapter.setBookId(book.getId()); + bookChapter.setBookChapterStartPos(start); + bookChapter.setChapterName(str.replaceAll("###","")); + bookChapter.setBookpath(bookPath); + bookChapter.save(); + int id= bookChapter.getId(); + Log.d(TAG,str + " chaptId is " + id); + + + File chapter = new File(fileChapterName(++chaptId)); + if (!chapter.exists()){ + chapter.createNewFile(); + } + if(writer!=null) { + writer.close(); + } + writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(chaptId)), charachterType); + + } + + if(writer==null) { + bookChapter = new BookChapter(); + bookChapter.setBookId(book.getId()); + bookChapter.setBookChapterStartPos(start); + bookChapter.setChapterName(str.replaceAll("###","")); + bookChapter.setBookpath(bookPath); + bookChapter.save(); + writer = new OutputStreamWriter(new FileOutputStream(fileChapterName(++chaptId)), charachterType); //序 + } + str+=lineBreakChar; + writer.write(str); + // Log.e(TAG,String.format("当前行\n %s",str)); if (str.contains("\u3000\u3000")) { size += str.length() + 2; @@ -276,13 +384,40 @@ public class BookUtil { }else { size += str.length(); } + + /* + BookChapter bookChapter = new BookChapter(); + bookChapter.setBookId(book.getId()); + + bookChapter.setBookChapterStartPos(start); + bookChapter.setChapterName(title.replaceAll("###","")); + bookChapter.setBookpath(bookPath); + bookChapter.setLength((int)(size - start)); + bookChapter.save(); + int id= bookChapter.getId(); + Log.d(TAG,str + " chaptId is " + id); + directoryList.add(bookChapter); + */ } } + if(writer!=null) { + writer.close(); + } + if(bookChapter!=null) { + bookChapter.setLength((int)(size - start)); + bookChapter.setChapterPath(fileChapterName(chaptId) ); + bookChapter.update(bookChapter.getId()); + directoryList.add(bookChapter); + } }catch (Exception e){ e.printStackTrace(); } } + void createChapContent(){ + + } + public List getDirectoryList(){ return directoryList; } @@ -294,6 +429,14 @@ public class BookUtil { protected String fileName(int index) { return cachedPath + bookName + index ; } + protected String fileChapterName(int chaptId ) { + + return getChapterPath() + chaptId ; + } + + String getChapterPath(){ + return chapterPath +book.getId()+"/"; + } //获取书本缓存 public char[] block(int index) { @@ -327,6 +470,45 @@ public class BookUtil { } return block; } + + Map chaptCache = new HashMap(); + + //获取chapter 缓存 + public char[] chaptChars(int index) { + char[] block=null; + if(chaptCache.containsKey(Integer.valueOf(index))) { + block = chaptCache .get(index).getData().get(); + } + if (block == null) { + try { + File file = new File(fileChapterName(index)); + int size = (int)file.length(); + if (size < 0) { + throw new RuntimeException("Error during reading " + fileChapterName(index)); + } + block = new char[size / 2]; + InputStreamReader reader = + new InputStreamReader( + new FileInputStream(file), + charachterType + ); + long l = reader.read(block); + if (reader.read(block) != block.length) { + // throw new RuntimeException("Error during reading " + fileChapterName(index)); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Error during reading " + fileChapterName(index)); + } + Cache cache = new Cache(); + cache.setSize(block.length); + cache.setData(new WeakReference(block)); + chaptCache.put(index, cache); +// myArray.set(index, new WeakReference(block)); + } + return block; + } public boolean isChapterTitle(String line){ return (line.length() <= 30 && (line.matches(".*第.{1,8}章.*") || line.matches(".*第.{1,8}节.*"))) ; } diff --git a/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java b/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java index fef06e0..5a1f946 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/utils/PageFactory.java @@ -136,7 +136,7 @@ public class PageFactory { private String bookName = ""; private Book bookList; //书本章节 - private int currentCharter = 0; + private int currentChapter = 0; //当前电量 private int level = 0; private BookUtil mBookUtil; @@ -147,6 +147,43 @@ public class PageFactory { private BookTask bookTask; ContentValues values = new ContentValues(); + + private List currentChaptPages; + private List nextChaptPages; + private List preChaptPages; + + + private List loadCurrentChapt(int chaptId){ + List chaptPages = new ArrayList(); + + char[] chars = mBookUtil.chaptChars(chaptId); + mBookUtil.setBookLen(chars.length); + mBookUtil.setChapterNo(chaptId); + // TRPage page = new TRPage(); + long length =0; + int pageNo =0; + while(length m_lines,Boolean updateCharter) { - if (getDirectoryList().size() > 0 && updateCharter) { - currentCharter = getCurrentCharter(); + public void onDraw(Bitmap bitmap,List m_lines,Boolean updateChapter) { + if (getDirectoryList().size() > 0 && updateChapter) { + currentChapter = getCurrentCharter(); } //更新数据库进度 if (currentPage != null && bookList != null){ @@ -297,6 +334,7 @@ public class PageFactory { public void run() { super.run(); values.put("begin",currentPage.getBegin()); + values.put("biginChapt",currentChapter); int rows = LitePal.update(Book.class,values,bookList.getId()); Log.e(TAG,String.format("update book %s bigin %s, result %s",bookList.getBookname(),currentPage.getBegin(),rows) ); } @@ -366,7 +404,7 @@ public class PageFactory { c.drawText(CommonUtil.subString(bookName,12), marginWidth ,statusMarginBottom + mBatterryFontSize, mBatterryPaint); //画章 if (getDirectoryList().size() > 0) { - String charterName = CommonUtil.subString(getDirectoryList().get(currentCharter).getChapterName(),12); + String charterName = CommonUtil.subString(getDirectoryList().get(currentChapter-1).getChapterName(),12); int nChaterWidth = (int) mBatterryPaint.measureText(charterName) + 1; c.drawText(charterName, mWidth - marginWidth - nChaterWidth, statusMarginBottom + mBatterryFontSize, mBatterryPaint); } @@ -377,14 +415,12 @@ public class PageFactory { //向前翻页 public void prePage(){ if (currentPage.getBegin() <= 0) { - Log.e(TAG,"当前是第一页"); - if (!m_isfirstPage){ + Log.e(TAG,"当前是本章第一页"); + m_isfirstPage =currentChapter ==1; + if ( m_isfirstPage){ Toast.makeText(mContext, "当前是第一页", Toast.LENGTH_SHORT).show(); + return; } - m_isfirstPage = true; - return; - } else { - m_isfirstPage = false; } cancelPage = currentPage; @@ -392,30 +428,27 @@ public class PageFactory { currentPage = getPrePage(); onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true); - - - - - } //向后翻页 public void nextPage(){ if (currentPage.getEnd() >= mBookUtil.getBookLen()) { - Log.e(TAG,"已经是最后一页了"); - if (!m_islastPage){ + Log.e(TAG,"已经是本章最后一页了"); + + m_islastPage =currentChapter == mBookUtil.getDirectoryList().size(); + if ( m_islastPage){ Toast.makeText(mContext, "已经是最后一页了", Toast.LENGTH_SHORT).show(); + return; + } else { + } - m_islastPage = true; - return; - } else { - m_islastPage = false; } cancelPage = currentPage; onDraw(mBookPageWidget.getCurPage(),currentPage.getLines(),true); prePage = currentPage; - currentPage = getNextPage(); + currentPage = getNextPage(); + // currentPage = currentChaptPages.get(currentPage.getPageNo()-1); onDraw(mBookPageWidget.getNextPage(),currentPage.getLines(),true); Log.e("nextPage","nextPagenext"); } @@ -429,13 +462,13 @@ public class PageFactory { * 打开书本 * @throws IOException */ - public void openBook(Book bookList) throws IOException { + public void openBook(Book book ) throws IOException { //清空数据 - currentCharter = 0; + currentChapter = 0; // m_mbBufLen = 0; initBg(config.getDayOrNight()); - this.bookList = bookList; + this.bookList = book ; bookPath = bookList.getBookpath(); bookName = FileUtils.getFileName(bookPath); @@ -446,10 +479,12 @@ public class PageFactory { bookTask.cancel(true); } bookTask = new BookTask(); - bookTask.execute(bookList.getBegin()); + + bookTask.execute(book.getBiginChapt(),book .getBegin()); } private class BookTask extends AsyncTask{ + private long chapter=0; private long begin = 0; @Override protected void onPostExecute(Boolean result) { @@ -461,7 +496,10 @@ public class PageFactory { if (result) { PageFactory.mStatus = PageFactory.Status.FINISH; // m_mbBufLen = mBookUtil.getBookLen(); - currentPage = getPageForBegin(begin); + mBookUtil.setChapterNo((int)chapter); + currentChaptPages = loadCurrentChapt((int)chapter); + currentPage = currentChaptPages.get(0); + // currentPage = getPageForBegin(begin); if (mBookPageWidget != null) { currentPage(true); } @@ -486,7 +524,9 @@ public class PageFactory { @Override protected Boolean doInBackground(Long... params) { - begin = params[0]; + chapter = params[0]; + begin = params[1]; + currentChapter = (int) chapter; try { mBookUtil.openBook(bookList); } catch (Exception e) { @@ -499,6 +539,7 @@ public class PageFactory { } public TRPage getNextPage(){ + /* mBookUtil.setPostition(currentPage.getEnd()); TRPage trPage = new TRPage(); @@ -508,9 +549,20 @@ public class PageFactory { Log.e(TAG,"page postion next end:" +mBookUtil.getPosition() + ""); trPage.setEnd(mBookUtil.getPosition()); return trPage; + */ + int nextPageNo =currentPage.getPageNo(); + if(nextPageNo == currentChaptPages.size()){ + preChaptPages =currentChaptPages; + currentChapter++; + mBookUtil.setChapterNo(currentChapter); + currentChaptPages = loadCurrentChapt(currentChapter ) ; + nextPageNo =0; + } + return currentChaptPages.get(nextPageNo); } public TRPage getPrePage(){ + /* mBookUtil.setPostition(currentPage.getBegin()); TRPage trPage = new TRPage(); @@ -520,9 +572,24 @@ public class PageFactory { Log.e(TAG,"page postion pre begin:" +mBookUtil.getPosition() + ""); trPage.setBegin(mBookUtil.getPosition() ); return trPage; + */ + int prePageNo =currentPage.getPageNo()-1; + if(prePageNo ==0){ + nextChaptPages =currentChaptPages; + currentChapter--; + if(currentChapter ==0) { + return new TRPage(); + } + mBookUtil.setChapterNo(currentChapter); + currentChaptPages = loadCurrentChapt(currentChapter ) ; + prePageNo = currentChaptPages.size(); + } + return currentChaptPages.get(prePageNo-1); + } public TRPage getPageForBegin(long begin){ + /* TRPage trPage = new TRPage(); trPage.setBegin(begin); @@ -530,6 +597,15 @@ public class PageFactory { trPage.setLines(getNextLines()); trPage.setEnd(mBookUtil.getPosition()); return trPage; + */ + + for(TRPage page : currentChaptPages) + { + if(page.getEnd() >begin){ + return page; + } + } + return new TRPage(); } boolean showChapTitleOnTopWhenNextPage =false; @@ -679,7 +755,7 @@ public class PageFactory { //上一章 public void preChapter(){ if (mBookUtil.getDirectoryList().size() > 0){ - int num = currentCharter; + int num = currentChapter; if (num ==0){ num =getCurrentCharter(); } @@ -688,14 +764,14 @@ public class PageFactory { long begin = mBookUtil.getDirectoryList().get(num).getBookChapterStartPos(); currentPage = getPageForBegin(begin); currentPage(true); - currentCharter = num; + currentChapter = num; } } } //下一章 public void nextChapter(){ - int num = currentCharter; + int num = currentChapter; if (num == 0){ num =getCurrentCharter(); } @@ -704,13 +780,13 @@ public class PageFactory { long begin = getDirectoryList().get(num).getBookChapterStartPos(); currentPage = getPageForBegin(begin); currentPage(true); - currentCharter = num; + currentChapter = num; } } //获取现在的章 public int getCurrentCharter(){ - int num = 0; + /*int num = 0; for (int i = 0;getDirectoryList().size() > i;i++){ BookChapter bookCatalogue = getDirectoryList().get(i); if (currentPage.getEnd() >= bookCatalogue.getBookChapterStartPos()){ @@ -720,6 +796,9 @@ public class PageFactory { } } return num; + */ + currentChapter = mBookUtil.getChapterNo(); + return currentChapter ; } //绘制当前页面 @@ -846,7 +925,7 @@ public class PageFactory { } public void clear(){ - currentCharter = 0; + currentChapter = 0; bookPath = ""; bookName = ""; bookList = null; @@ -855,6 +934,10 @@ public class PageFactory { cancelPage = null; prePage = null; currentPage = null; + + currentChaptPages =null; + preChaptPages=null; + nextChaptPages=null; } public static Status getStatus(){ diff --git a/zhuike/src/main/java/com/deiniu/zhuike/utils/TRPage.java b/zhuike/src/main/java/com/deiniu/zhuike/utils/TRPage.java index 586b740..bdffe70 100644 --- a/zhuike/src/main/java/com/deiniu/zhuike/utils/TRPage.java +++ b/zhuike/src/main/java/com/deiniu/zhuike/utils/TRPage.java @@ -1,12 +1,23 @@ package com.deiniu.zhuike.utils; +import java.util.ArrayList; import java.util.List; public class TRPage { private long begin; private long end; - private List lines; + private List lines = new ArrayList<>(); + + public int getPageNo() { + return pageNo; + } + + public void setPageNo(int pageNo) { + this.pageNo = pageNo; + } + + private int pageNo; public long getBegin() { return begin;