Skip to content

Commit

Permalink
[#653]小说组件首次模式切换或者翻页文字空白问题 (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingcan-mc authored Jan 23, 2024
1 parent e66acec commit 38999a4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -151,6 +152,7 @@ public ReaderLayoutView(Context context, int color, String spliteStr, String rea
mPageColor = color;
mSplitStr = spliteStr;
mReaderMoveMode = readerMoveMode;
mLastReaderMoveMode = mReaderMoveMode;
initView();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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 {
Expand All @@ -1628,6 +1644,7 @@ public void run() {
}
}
}
mLastReaderMoveMode = mReaderMoveMode;
}
return isSuccess;

Expand Down Expand Up @@ -1774,13 +1791,15 @@ public void calculateChapter(List<ReaderPageData> 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);
rdPageDatas.add(pageData);
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,4 +11,5 @@ public class ReaderPageData {
String pageData;
int pageIndex;
List<String> pageLineDatas = new ArrayList<>();
float lineWidth = -1;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -339,13 +339,13 @@ public void setMaxPageLineCount(int lineCount) {
}
}

public void setReaderPageData(List<String> pageText) {
public void setReaderPageData(float lineWidth, List<String> pageText) {
if (null == pageText) {
return;
}
mPageText = pageText;
if (null != mPageText) {
mReaderText.setReaderPageData(mPageText);
mReaderText.setReaderPageData(lineWidth, mPageText);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ protected void onDetachedFromWindow() {
mLastDownMotionEvent = null;
}

public void setReaderPageData(List<String> datas) {
public void setReaderPageData(float lineWidth, List<String> datas) {
mPageData.clear();
mPageData.addAll(datas);
mText = getDrawPageString(mPageData);
float viewWidth = lineWidth;
if (viewWidth > 0) {
setMinWidth((int) viewWidth);
}
}

@Override
Expand Down

0 comments on commit 38999a4

Please sign in to comment.