diff --git a/app/src/main/java/xyz/fycz/myreader/model/SearchWordEngine.kt b/app/src/main/java/xyz/fycz/myreader/model/SearchWordEngine.kt index 6fc9bc0..a647a3d 100644 --- a/app/src/main/java/xyz/fycz/myreader/model/SearchWordEngine.kt +++ b/app/src/main/java/xyz/fycz/myreader/model/SearchWordEngine.kt @@ -37,8 +37,8 @@ class SearchWordEngine( private var scheduler: Scheduler private var compositeDisposable: CompositeDisposable private lateinit var searchListener: OnSearchListener - private val threadsNum = - SharedPreUtils.getInstance().getInt(App.getmContext().getString(R.string.threadNum), 8); + private val threadsNum = 4 +// SharedPreUtils.getInstance().getInt(App.getmContext().getString(R.string.threadNum), 8) private var searchSiteIndex = 0 private var searchSuccessNum = 0 private var searchFinishNum = 0 @@ -120,9 +120,11 @@ class SearchWordEngine( } val allLine: List = content.split("\n") var count = 0 + var blockPos = 0 allLine.forEach { var index: Int = -1 while (it.indexOf(keyword, index + 1).also { index = it } != -1) { + blockPos++ var leftI = 0 var rightI = it.length var leftS = "" @@ -147,6 +149,11 @@ class SearchWordEngine( ) searchWord1.searchWord2List.add(searchWord2) count++ + //当添加的block太多的时候,执行GC + if (blockPos % 15 == 0) { + System.gc() + System.runFinalization() + } } } emitter.onNext(searchWord1) diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchWordActivity.kt b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchWordActivity.kt index 6e2bb80..9ba5c3b 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchWordActivity.kt +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/SearchWordActivity.kt @@ -25,6 +25,7 @@ import xyz.fycz.myreader.ui.adapter.holder.SearchWord1Holder import xyz.fycz.myreader.ui.adapter.holder.SearchWord2Holder import xyz.fycz.myreader.util.ToastUtils import xyz.fycz.myreader.widget.page.PageLoader +import xyz.fycz.myreader.widget.page.PageView /** * @author fengyue @@ -34,6 +35,8 @@ class SearchWordActivity : BaseActivity() { private lateinit var binding: ActivitySearchWordBinding private lateinit var book: Book + private lateinit var chapters: List + private lateinit var pageLoader: PageLoader private lateinit var searchWordEngine: SearchWordEngine private lateinit var adapter: BaseListAdapter @@ -48,6 +51,13 @@ class SearchWordActivity : BaseActivity() { supportActionBar?.title = getString(R.string.search_word) } + override fun onSaveInstanceState(outState: Bundle) { + BitIntentDataManager.getInstance().putData(APPCONST.BOOK_KEY, book) + BitIntentDataManager.getInstance().putData(APPCONST.CHAPTERS_KEY, chapters) + BitIntentDataManager.getInstance().putData(APPCONST.PAGE_LOADER_KEY, pageLoader) + super.onSaveInstanceState(outState) + } + override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) if (hasFocus) { @@ -66,9 +76,9 @@ class SearchWordActivity : BaseActivity() { override fun initData(savedInstanceState: Bundle?) { super.initData(savedInstanceState) book = BitIntentDataManager.getInstance().getData(APPCONST.BOOK_KEY) as Book - val chapters = + chapters = BitIntentDataManager.getInstance().getData(APPCONST.CHAPTERS_KEY) as List - val pageLoader = + pageLoader = BitIntentDataManager.getInstance().getData(APPCONST.PAGE_LOADER_KEY) as PageLoader searchWordEngine = SearchWordEngine(book, chapters, pageLoader) } 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 ba978f4..8471fea 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 @@ -280,7 +280,6 @@ public class EpubPageLoader extends PageLoader { @Override public String getChapterReader(Chapter chapter) throws Exception { - Log.d("getChapterReader", chapter.getTitle()); /*byte[] content = getChapterContent(chapter).getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(content); BufferedReader br = new BufferedReader(new InputStreamReader(bais)); 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 ff91e9d..72cd831 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 @@ -2128,6 +2128,10 @@ public abstract class PageLoader { public void skipToSearch(int chapterNum, int countInChapter, String keyword) { skipToChapter(chapterNum); + if (mStatus != STATUS_FINISH){ + App.getHandler().postDelayed(() -> skipToSearch(chapterNum, countInChapter, keyword), 300); + return; + } int[] position = searchWordPositions(countInChapter, keyword); skipToPage(position[0]); mPageView.setFirstSelectTxtChar(mCurPage.txtLists.get(position[1]). @@ -2180,7 +2184,7 @@ public abstract class PageLoader { TxtPage currentPage = pages.get(pageIndex); int lineIndex = 0; length = length - currentPage.getContent().length() + currentPage.lines.get(lineIndex).length(); - while (length < contentPosition) { + while (length <= contentPosition) { lineIndex += 1; if (lineIndex > currentPage.lines.size()) { lineIndex = currentPage.lines.size(); diff --git a/app/version_code.properties b/app/version_code.properties index 465d718..0f63650 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,3 +1,3 @@ #Fri Jun 18 21:45:31 CST 2021 VERSION_CODE=224 -NEED_CREATE_RELEASE=true +NEED_CREATE_RELEASE=false