From dce96b599acd613ecef9cab270c396cb33fb5f01 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Mon, 6 Dec 2021 21:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=BB=98=E5=88=B6=E8=83=8C=E6=99=AF=E9=94=99=E4=BD=8D?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/activity/SearchWordActivity.kt | 1 + .../fycz/myreader/widget/page/PageLoader.java | 51 +++++++++++-------- 2 files changed, 32 insertions(+), 20 deletions(-) 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 238a1db..c7a41d0 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 @@ -100,6 +100,7 @@ class SearchWordActivity : BaseActivity() { @Synchronized override fun loadMore(item: SearchWord1) { + if (adapter.items.contains(item)) return if (adapter.itemSize == 0) { adapter.addItem(item) } else { 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 72cd831..9802611 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,31 +2128,36 @@ public abstract class PageLoader { public void skipToSearch(int chapterNum, int countInChapter, String keyword) { skipToChapter(chapterNum); - if (mStatus != STATUS_FINISH){ + 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]). - getCharsData().get(position[2])); - switch (position[3]) { - case 0: - mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(position[1]). - getCharsData().get(position[2] + keyword.length() - 1)); - break; - case 1: - mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(position[1] + 1). - getCharsData().get(position[4])); - break; - case -1: - mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(mCurPage.txtLists.size() - 1). - getCharsData().get(mCurPage.txtLists.get(mCurPage.txtLists.size() - 1). - getCharsData().size() - 1)); - break; + + try { + mPageView.setFirstSelectTxtChar(mCurPage.txtLists.get(position[1]). + getCharsData().get(position[2])); + switch (position[3]) { + case 0: + mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(position[1]). + getCharsData().get(position[2] + keyword.length() - 1)); + break; + case 1: + mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(position[1] + 1). + getCharsData().get(position[4])); + break; + case -1: + mPageView.setLastSelectTxtChar(mCurPage.txtLists.get(mCurPage.txtLists.size() - 1). + getCharsData().get(mCurPage.txtLists.get(mCurPage.txtLists.size() - 1). + getCharsData().size() - 1)); + break; + } + mPageView.setSelectMode(PageView.SelectMode.SelectMoveForward); + mPageView.invalidate(); + } catch (Exception e) { + e.printStackTrace(); } - mPageView.setSelectMode(PageView.SelectMode.SelectMoveForward); - mPageView.invalidate(); } private int[] searchWordPositions(int countInChapter, String keyword) { @@ -2195,9 +2200,14 @@ public abstract class PageLoader { // charIndex String currentLine = currentPage.lines.get(lineIndex); - currentLine = StringUtils.trim(currentLine); + if (currentLine.endsWith("\n")){ + currentLine = StringUtils.trim(currentLine) + "\n"; + }else { + currentLine = StringUtils.trim(currentLine); + } length -= currentLine.length(); int charIndex = contentPosition - length; + if (charIndex < 0) charIndex = 0; int addLine = 0; int charIndex2 = 0; // change line @@ -2210,6 +2220,7 @@ public abstract class PageLoader { addLine = -1; charIndex2 = charIndex + keyword.length() - currentLine.length() - 1; } + if (charIndex2 < 0) charIndex = 0; return new int[]{pageIndex, lineIndex, charIndex, addLine, charIndex2}; }