优化阅读文字选择

pull/5/head
fengyuecanzhu 4 years ago
parent 8c91b9afa4
commit c1401bad93
  1. 1
      app/src/main/assets/updatelog.fy
  2. 33
      app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
  3. 39
      app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java
  4. 6
      app/src/main/java/xyz/fycz/myreader/widget/page/PageView.java

@ -2,6 +2,7 @@
风月读书v2.1.3 风月读书v2.1.3
更新内容: 更新内容:
1、优化阅读文字选择 1、优化阅读文字选择
2、修复已知bug
2021.06.13 2021.06.13
风月读书v2.1.2 风月读书v2.1.2

@ -401,10 +401,12 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
mBook.setChapterTotalNum(chapters.size()); mBook.setChapterTotalNum(chapters.size());
mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle()); mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle());
if (hasChangeSource) { if (hasChangeSource) {
mBookService.matchHistoryChapterPos(mBook, mChapters); boolean flag = mBookService.matchHistoryChapterPos(mBook, mChapters);
skipToChapterAndPage(mBook.getHisttoryChapterNum(), mBook.getLastReadPosition()); Log.d(TAG, "matchHistoryChapterPos=" + flag);
hasChangeSource = false; hasChangeSource = false;
mChapterService.addChapters(chapters); if (flag) {
mPageLoader.skipToChapter(mBook.getHisttoryChapterNum());
}
} }
mBookService.updateEntity(mBook); mBookService.updateEntity(mBook);
loadFinish = true; loadFinish = true;
@ -481,9 +483,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
if (!StringHelper.isEmpty(bean.getDesc())) { if (!StringHelper.isEmpty(bean.getDesc())) {
bookTem.setDesc(bean.getDesc()); bookTem.setDesc(bean.getDesc());
} }
if (isCollected) {
mBookService.updateBook(mBook, bookTem); mBookService.updateBook(mBook, bookTem);
}
mBook = bookTem; mBook = bookTem;
aBooks = mSourceDialog.getaBooks(); aBooks = mSourceDialog.getaBooks();
aBooks.set(pos, mBook); aBooks.set(pos, mBook);
@ -1748,15 +1748,15 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
int dx = (int) event.getRawX() - lastX; int dx = (int) event.getRawX() - lastX;
int dy = (int) event.getRawY() - lastY; int dy = (int) event.getRawY() - lastY;
int l = v.getLeft() + dx; /*int l = v.getLeft() + dx;
int b = v.getBottom() + dy; int b = v.getBottom() + dy;
int r = v.getRight() + dx; int r = v.getRight() + dx;
int t = v.getTop() + dy; int t = v.getTop() + dy;*/
v.layout(l, t, r, b); //v.layout(l, t, r, b);
lastX = (int) event.getRawX(); lastX = (int) event.getRawX();
lastY = (int) event.getRawY(); lastY = (int) event.getRawY();
v.postInvalidate(); //v.postInvalidate();
//移动过程中要画线 //移动过程中要画线
binding.readPvContent.setSelectMode(PageView.SelectMode.SelectMoveForward); binding.readPvContent.setSelectMode(PageView.SelectMode.SelectMoveForward);
@ -1780,7 +1780,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
right.setY(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().y); right.setY(binding.readPvContent.getLastSelectTxtChar().getBottomRightPosition().y);
} }
float leftX = left.getX(); float leftX = left.getX();
float leftY = left.getY(); float leftY = left.getY();
float rightX = right.getX(); float rightX = right.getX();
@ -1831,18 +1830,20 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
* 显示长按菜单 * 显示长按菜单
*/ */
public void showAction() { public void showAction() {
ImageView left = binding.getRoot().findViewWithTag("left");
ImageView right = binding.getRoot().findViewWithTag("right");
float x, y; float x, y;
if (binding.cursorLeft.getX() - binding.cursorRight.getX() > 0) { if (left.getX() - right.getX() > 0) {
x = binding.cursorRight.getX() + (binding.cursorLeft.getX() - binding.cursorRight.getX()) / 2 + ScreenUtils.dpToPx(12); x = right.getX() + (left.getX() - right.getX()) / 2 + ScreenUtils.dpToPx(12);
} else { } else {
x = binding.cursorLeft.getX() + (binding.cursorRight.getX() - binding.cursorLeft.getX()) / 2 + ScreenUtils.dpToPx(12); x = left.getX() + (right.getX() - left.getX()) / 2 + ScreenUtils.dpToPx(12);
} }
if ((binding.cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(60)) < 0) { if ((left.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(60)) < 0) {
longPressMenu.setShowBottom(true); longPressMenu.setShowBottom(true);
y = binding.cursorLeft.getY() + binding.cursorLeft.getHeight() * 3 / 5; y = left.getY() + left.getHeight() * 3 / 5;
} else { } else {
longPressMenu.setShowBottom(false); longPressMenu.setShowBottom(false);
y = binding.cursorLeft.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(5); y = left.getY() - ScreenUtils.spToPx(mSetting.getReadWordSize()) - ScreenUtils.dpToPx(5);
} }
longPressMenu.showPopupListWindow(binding.rlContent, 0, x, y, longPressMenu.showPopupListWindow(binding.rlContent, 0, x, y,
longPressMenuItems, longPressMenuListener); longPressMenuItems, longPressMenuListener);

@ -2079,7 +2079,9 @@ public abstract class PageLoader {
if (txtLines == null) return null; if (txtLines == null) return null;
for (TxtLine l : txtLines) { for (TxtLine l : txtLines) {
List<TxtChar> txtChars = l.getCharsData(); List<TxtChar> txtChars = l.getCharsData();
if (txtChars != null) { if (txtChars != null && txtChars.size() > 0) {
TxtChar first = txtChars.get(0);
TxtChar last = txtChars.get(txtChars.size() - 1);
for (int i = 0; i < txtChars.size(); i++) { for (int i = 0; i < txtChars.size(); i++) {
TxtChar c = txtChars.get(i); TxtChar c = txtChars.get(i);
Point leftPoint = c.getBottomLeftPosition(); Point leftPoint = c.getBottomLeftPosition();
@ -2091,10 +2093,12 @@ public abstract class PageLoader {
boolean flag = down_X2 >= leftPoint.x && down_X2 <= rightPoint.x; boolean flag = down_X2 >= leftPoint.x && down_X2 <= rightPoint.x;
switch (detect) { switch (detect) {
case Left: case Left:
flag = flag || (i == 0 && down_X2 < leftPoint.x); flag = flag || (i == 0 && (down_X2 < leftPoint.x ||
down_X2 > last.getBottomRightPosition().x));
break; break;
case Right: case Right:
flag = flag || (i == txtChars.size() - 1 && down_X2 > rightPoint.x); flag = flag || (i == txtChars.size() - 1 && (down_X2 > rightPoint.x ||
down_X2 < first.getBottomLeftPosition().x));
break; break;
} }
if (flag) return c; if (flag) return c;
@ -2106,41 +2110,22 @@ public abstract class PageLoader {
return null; return null;
} }
TxtChar detectLastTxtChar(TxtChar txtChar) { TxtChar detectTxtCharByIndex(int index) {
TxtChar last = txtChar;
TxtPage txtPage = mCurPage; TxtPage txtPage = mCurPage;
if (txtPage == null) return txtChar; if (txtPage == null) return null;
List<TxtLine> txtLines = txtPage.txtLists; List<TxtLine> txtLines = txtPage.txtLists;
if (txtLines == null) return txtChar; if (txtLines == null) return null;
for (TxtLine l : txtLines) { for (TxtLine l : txtLines) {
List<TxtChar> txtChars = l.getCharsData(); List<TxtChar> txtChars = l.getCharsData();
if (txtChars != null) { if (txtChars != null) {
for (TxtChar c : txtChars) { for (TxtChar c : txtChars) {
if (c != null && c.getIndex() == txtChar.getIndex()) return last; if (c != null && c.getIndex() == index) return c;
last = c;
} }
} }
} }
return txtChar; return null;
} }
TxtChar detectNextTxtChar(TxtChar txtChar) {
TxtPage txtPage = mCurPage;
boolean isNext = false;
if (txtPage == null) return txtChar;
List<TxtLine> txtLines = txtPage.txtLists;
if (txtLines == null) return txtChar;
for (TxtLine l : txtLines) {
List<TxtChar> txtChars = l.getCharsData();
if (txtChars != null) {
for (TxtChar c : txtChars) {
if (isNext) return c;
if (c != null && c.getIndex() == txtChar.getIndex()) isNext = true;
}
}
}
return txtChar;
}
public boolean isPrev() { public boolean isPrev() {
return isPrev; return isPrev;

@ -632,11 +632,13 @@ public class PageView extends View {
} }
public TxtChar getLastTxtChar(TxtChar txtChar){ public TxtChar getLastTxtChar(TxtChar txtChar){
return mPageLoader.detectLastTxtChar(txtChar); TxtChar last = mPageLoader.detectTxtCharByIndex(txtChar.getIndex() - 1);
return last == null ? txtChar : last;
} }
public TxtChar getNextTxtChar(TxtChar txtChar){ public TxtChar getNextTxtChar(TxtChar txtChar){
return mPageLoader.detectNextTxtChar(txtChar); TxtChar next = mPageLoader.detectTxtCharByIndex(txtChar.getIndex() + 1);
return next == null ? txtChar : next;
} }
private void drawOaleSeletLinesBg(Canvas canvas) {// 绘制选中背景 private void drawOaleSeletLinesBg(Canvas canvas) {// 绘制选中背景

Loading…
Cancel
Save