master
fengyuecanzhu 3 years ago
parent d3cf7c0014
commit 6055e779c2
  1. 11
      app/src/main/java/xyz/fycz/myreader/model/SearchWordEngine.kt
  2. 14
      app/src/main/java/xyz/fycz/myreader/ui/activity/SearchWordActivity.kt
  3. 1
      app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java
  4. 6
      app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java
  5. 2
      app/version_code.properties

@ -37,8 +37,8 @@ class SearchWordEngine(
private var scheduler: Scheduler private var scheduler: Scheduler
private var compositeDisposable: CompositeDisposable private var compositeDisposable: CompositeDisposable
private lateinit var searchListener: OnSearchListener private lateinit var searchListener: OnSearchListener
private val threadsNum = private val threadsNum = 4
SharedPreUtils.getInstance().getInt(App.getmContext().getString(R.string.threadNum), 8); // SharedPreUtils.getInstance().getInt(App.getmContext().getString(R.string.threadNum), 8)
private var searchSiteIndex = 0 private var searchSiteIndex = 0
private var searchSuccessNum = 0 private var searchSuccessNum = 0
private var searchFinishNum = 0 private var searchFinishNum = 0
@ -120,9 +120,11 @@ class SearchWordEngine(
} }
val allLine: List<String> = content.split("\n") val allLine: List<String> = content.split("\n")
var count = 0 var count = 0
var blockPos = 0
allLine.forEach { allLine.forEach {
var index: Int = -1 var index: Int = -1
while (it.indexOf(keyword, index + 1).also { index = it } != -1) { while (it.indexOf(keyword, index + 1).also { index = it } != -1) {
blockPos++
var leftI = 0 var leftI = 0
var rightI = it.length var rightI = it.length
var leftS = "" var leftS = ""
@ -147,6 +149,11 @@ class SearchWordEngine(
) )
searchWord1.searchWord2List.add(searchWord2) searchWord1.searchWord2List.add(searchWord2)
count++ count++
//当添加的block太多的时候,执行GC
if (blockPos % 15 == 0) {
System.gc()
System.runFinalization()
}
} }
} }
emitter.onNext(searchWord1) emitter.onNext(searchWord1)

@ -25,6 +25,7 @@ import xyz.fycz.myreader.ui.adapter.holder.SearchWord1Holder
import xyz.fycz.myreader.ui.adapter.holder.SearchWord2Holder import xyz.fycz.myreader.ui.adapter.holder.SearchWord2Holder
import xyz.fycz.myreader.util.ToastUtils import xyz.fycz.myreader.util.ToastUtils
import xyz.fycz.myreader.widget.page.PageLoader import xyz.fycz.myreader.widget.page.PageLoader
import xyz.fycz.myreader.widget.page.PageView
/** /**
* @author fengyue * @author fengyue
@ -34,6 +35,8 @@ class SearchWordActivity : BaseActivity() {
private lateinit var binding: ActivitySearchWordBinding private lateinit var binding: ActivitySearchWordBinding
private lateinit var book: Book private lateinit var book: Book
private lateinit var chapters: List<Chapter>
private lateinit var pageLoader: PageLoader
private lateinit var searchWordEngine: SearchWordEngine private lateinit var searchWordEngine: SearchWordEngine
private lateinit var adapter: BaseListAdapter<SearchWord1> private lateinit var adapter: BaseListAdapter<SearchWord1>
@ -48,6 +51,13 @@ class SearchWordActivity : BaseActivity() {
supportActionBar?.title = getString(R.string.search_word) 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) { override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus) super.onWindowFocusChanged(hasFocus)
if (hasFocus) { if (hasFocus) {
@ -66,9 +76,9 @@ class SearchWordActivity : BaseActivity() {
override fun initData(savedInstanceState: Bundle?) { override fun initData(savedInstanceState: Bundle?) {
super.initData(savedInstanceState) super.initData(savedInstanceState)
book = BitIntentDataManager.getInstance().getData(APPCONST.BOOK_KEY) as Book book = BitIntentDataManager.getInstance().getData(APPCONST.BOOK_KEY) as Book
val chapters = chapters =
BitIntentDataManager.getInstance().getData(APPCONST.CHAPTERS_KEY) as List<Chapter> BitIntentDataManager.getInstance().getData(APPCONST.CHAPTERS_KEY) as List<Chapter>
val pageLoader = pageLoader =
BitIntentDataManager.getInstance().getData(APPCONST.PAGE_LOADER_KEY) as PageLoader BitIntentDataManager.getInstance().getData(APPCONST.PAGE_LOADER_KEY) as PageLoader
searchWordEngine = SearchWordEngine(book, chapters, pageLoader) searchWordEngine = SearchWordEngine(book, chapters, pageLoader)
} }

@ -280,7 +280,6 @@ public class EpubPageLoader extends PageLoader {
@Override @Override
public String getChapterReader(Chapter chapter) throws Exception { public String getChapterReader(Chapter chapter) throws Exception {
Log.d("getChapterReader", chapter.getTitle());
/*byte[] content = getChapterContent(chapter).getBytes(); /*byte[] content = getChapterContent(chapter).getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(content); ByteArrayInputStream bais = new ByteArrayInputStream(content);
BufferedReader br = new BufferedReader(new InputStreamReader(bais)); BufferedReader br = new BufferedReader(new InputStreamReader(bais));

@ -2128,6 +2128,10 @@ public abstract class PageLoader {
public void skipToSearch(int chapterNum, int countInChapter, String keyword) { public void skipToSearch(int chapterNum, int countInChapter, String keyword) {
skipToChapter(chapterNum); skipToChapter(chapterNum);
if (mStatus != STATUS_FINISH){
App.getHandler().postDelayed(() -> skipToSearch(chapterNum, countInChapter, keyword), 300);
return;
}
int[] position = searchWordPositions(countInChapter, keyword); int[] position = searchWordPositions(countInChapter, keyword);
skipToPage(position[0]); skipToPage(position[0]);
mPageView.setFirstSelectTxtChar(mCurPage.txtLists.get(position[1]). mPageView.setFirstSelectTxtChar(mCurPage.txtLists.get(position[1]).
@ -2180,7 +2184,7 @@ public abstract class PageLoader {
TxtPage currentPage = pages.get(pageIndex); TxtPage currentPage = pages.get(pageIndex);
int lineIndex = 0; int lineIndex = 0;
length = length - currentPage.getContent().length() + currentPage.lines.get(lineIndex).length(); length = length - currentPage.getContent().length() + currentPage.lines.get(lineIndex).length();
while (length < contentPosition) { while (length <= contentPosition) {
lineIndex += 1; lineIndex += 1;
if (lineIndex > currentPage.lines.size()) { if (lineIndex > currentPage.lines.size()) {
lineIndex = currentPage.lines.size(); lineIndex = currentPage.lines.size();

@ -1,3 +1,3 @@
#Fri Jun 18 21:45:31 CST 2021 #Fri Jun 18 21:45:31 CST 2021
VERSION_CODE=224 VERSION_CODE=224
NEED_CREATE_RELEASE=true NEED_CREATE_RELEASE=false

Loading…
Cancel
Save