From 7b421cc68aee381bc20bd0ae6273863cd2b550f8 Mon Sep 17 00:00:00 2001 From: cmc Date: Wed, 17 Jan 2024 16:22:30 +0800 Subject: [PATCH] =?UTF-8?q?[#653]=E5=B0=8F=E8=AF=B4=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=A8=A1=E5=BC=8F=E5=88=87=E6=8D=A2=E6=88=96?= =?UTF-8?q?=E8=80=85=E7=BF=BB=E9=A1=B5=E6=96=87=E5=AD=97=E7=A9=BA=E7=99=BD?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/readerdiv/ReaderLayoutView.java | 27 ++++++++++++++++--- .../view/readerdiv/ReaderPageData.java | 3 ++- .../view/readerdiv/ReaderPageView.java | 6 ++--- .../widgets/view/readerdiv/ReaderText.java | 6 ++++- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderLayoutView.java b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderLayoutView.java index 068ed17f..6213fab6 100644 --- a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderLayoutView.java +++ b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderLayoutView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, the hapjs-platform Project Contributors + * Copyright (c) 2023-present, the hapjs-platform Project Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.hapjs.widgets.view.readerdiv; @@ -116,6 +116,7 @@ public int getTotalCurrentIndex() { private IGesture mGesture; private boolean mIsAttachToWindow; private String mReaderMoveMode = ReaderDiv.READER_PAGE_MODE_HORIZON; + private String mLastReaderMoveMode = null; private boolean mNoNeedPreloadPage; private static final int GO_NEXT_SUCCESS = 1; @@ -151,6 +152,7 @@ public ReaderLayoutView(Context context, int color, String spliteStr, String rea mPageColor = color; mSplitStr = spliteStr; mReaderMoveMode = readerMoveMode; + mLastReaderMoveMode = mReaderMoveMode; initView(); } @@ -642,7 +644,7 @@ private void initCurrentPage(boolean isHorizonMode, boolean isPreChapter, int cu readerPageView.setBgColor(mPageColor); readerPageView.setLineHeight(mLineHeight); readerPageView.setMaxPageLineCount(mPageLineCount); - readerPageView.setReaderPageData(mCurReaderPageData.pageLineDatas); + readerPageView.setReaderPageData(mCurReaderPageData.lineWidth, mCurReaderPageData.pageLineDatas); } else { readerPageView.setPageIndex(pageIndex); readerPageView.setLineHeight(mLineHeight); @@ -743,7 +745,7 @@ private void prepareNextPage(boolean isHorizonMode, boolean isPreAd, boolean isC nextPageView.setBgColor(mPageColor); nextPageView.setLineHeight(mLineHeight); nextPageView.setMaxPageLineCount(mPageLineCount); - nextPageView.setReaderPageData(readerPageData.pageLineDatas); + nextPageView.setReaderPageData(readerPageData.lineWidth, readerPageData.pageLineDatas); } else { Log.w(TAG, READER_LOG_TAG + " prepareNextPage readerPageData is null."); } @@ -1608,7 +1610,21 @@ public boolean refreshReaderMoveMode(String readerMoveMode) { post(new Runnable() { @Override public void run() { - goNextPage(false); + if (mTotalCurrentIndex == 0 && READER_PAGE_MODE_VERTICAL.equals(mLastReaderMoveMode)) { + mCurReaderPageData = null; + mCurrentIndex = -1; + Log.w(TAG, READER_LOG_TAG + "refreshReaderMoveMode " + + " mCurrentIndex : " + mCurrentIndex + + " mReaderMoveMode : " + mReaderMoveMode); + mTotalCurrentIndex = -1; + mCurMaxIndex = -1; + mCurMinIndex = -1; + mReaderPageTypes.clear(); + goNextPage(true); + } else { + goNextPage(false); + } + mLastReaderMoveMode = mReaderMoveMode; } }); } else { @@ -1628,6 +1644,7 @@ public void run() { } } } + mLastReaderMoveMode = mReaderMoveMode; } return isSuccess; @@ -1774,6 +1791,7 @@ public void calculateChapter(List rdPageDatas, String title, Str } if (beginLine + pageLineCount <= lineSize) { pageData = new ReaderPageData(); + pageData.lineWidth = realWidth; pageData.pageIndex = i; pageData.pageLineDatas.addAll(lines.subList(beginLine, beginLine + pageLineCount)); pageData.pageData = getDrawPageString(pageData.pageLineDatas); @@ -1781,6 +1799,7 @@ public void calculateChapter(List rdPageDatas, String title, Str beginLine = beginLine + pageLineCount; } else { pageData = new ReaderPageData(); + pageData.lineWidth = realWidth; pageData.pageIndex = i; pageData.pageLineDatas.addAll(lines.subList(beginLine, lineSize)); pageData.pageData = getDrawPageString(pageData.pageLineDatas); diff --git a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageData.java b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageData.java index fd68ca68..598e9741 100644 --- a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageData.java +++ b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, the hapjs-platform Project Contributors + * Copyright (c) 2023-present, the hapjs-platform Project Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.hapjs.widgets.view.readerdiv; @@ -11,4 +11,5 @@ public class ReaderPageData { String pageData; int pageIndex; List pageLineDatas = new ArrayList<>(); + float lineWidth = -1; } diff --git a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageView.java b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageView.java index 0adda90b..b9189551 100644 --- a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageView.java +++ b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderPageView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, the hapjs-platform Project Contributors + * Copyright (c) 2023-present, the hapjs-platform Project Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.hapjs.widgets.view.readerdiv; @@ -339,13 +339,13 @@ public void setMaxPageLineCount(int lineCount) { } } - public void setReaderPageData(List pageText) { + public void setReaderPageData(float lineWidth, List pageText) { if (null == pageText) { return; } mPageText = pageText; if (null != mPageText) { - mReaderText.setReaderPageData(mPageText); + mReaderText.setReaderPageData(lineWidth, mPageText); } } diff --git a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderText.java b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderText.java index d76062a9..6580f6fa 100644 --- a/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderText.java +++ b/core/runtime/android/widgets/src/main/java/org/hapjs/widgets/view/readerdiv/ReaderText.java @@ -76,10 +76,14 @@ protected void onDetachedFromWindow() { mLastDownMotionEvent = null; } - public void setReaderPageData(List datas) { + public void setReaderPageData(float lineWidth, List datas) { mPageData.clear(); mPageData.addAll(datas); mText = getDrawPageString(mPageData); + float viewWidth = lineWidth; + if (viewWidth > 0) { + setMinWidth((int) viewWidth); + } } @Override