Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuecanzhu committed Jun 15, 2021
1 parent 55061ac commit 35d7b12
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 40 deletions.
13 changes: 10 additions & 3 deletions app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe

private boolean isPrivate;//是否私密书籍

private boolean isFirstLoad = true;


// 接收电池信息和时间更新的广播
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -391,7 +393,6 @@ public void onLongPress() {
public void onChapterChange(int pos) {
chapterPos = pos;
mBook.setHistoryChapterId(mChapters.get(pos).getTitle());
recordReadTime();
}

@Override
Expand Down Expand Up @@ -420,8 +421,13 @@ public void onPageCountChange(int count) {

@Override
public void onPageChange(int pos, boolean resetRead) {
pagePos = pos;
saveLastChapterReadPosition();
if (isFirstLoad) {
pagePos = mBook.getLastReadPosition();
isFirstLoad = false;
} else {
pagePos = pos;
saveLastChapterReadPosition();
}
screenOffTimerStart();
initMenu();
recordReadTime();
Expand All @@ -443,6 +449,7 @@ public void onPageChange(int pos, boolean resetRead) {
}
}
}

}
);

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/xyz/fycz/myreader/webapi/ThirdSourceApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ protected static Observable<List<Chapter>> getBookChaptersByTC(Book book, ThirdC
headers.putAll(getCookies(rc.getNameSpace()));
BookChapterList bookChapterList = new BookChapterList(source.getSourceUrl(), source, true);
if (!TextUtils.isEmpty(book.getCathe("ChapterListHtml"))) {
return bookChapterList.analyzeChapterList(book.getCathe("ChapterListHtml"), book, headers);
return bookChapterList.analyzeChapterList(book.getCathe("ChapterListHtml"), book, headers)
.flatMap(chapters -> Observable.create(emitter -> {
for (int i = 0; i < chapters.size(); i++) {
Chapter chapter = chapters.get(i);
chapter.setNumber(i);
}
emitter.onNext(chapters);
emitter.onComplete();
}));
}
try {
AnalyzeUrl analyzeUrl = new AnalyzeUrl(book.getChapterUrl(), headers, book.getInfoUrl());
Expand Down
70 changes: 35 additions & 35 deletions app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -917,48 +917,44 @@ private void drawBackground(Canvas canvas) {
: getReadProgress(getChapterPos(), mChapterList.size(), getPagePos(), getAllPagePos());
/****绘制背景****/
if (!mSettingManager.isShowStatusBar()) {
if (!mChapterList.isEmpty()) {
//需要注意的是:绘制text的y的起始点是text的基准线的位置,而不是从text的头部的位置
float tipTop = tipMarginHeight - mTipPaint.getFontMetrics().top;
if (!mChapterList.isEmpty() && mStatus == STATUS_FINISH) {
/*****初始化标题的参数********/
//需要注意的是:绘制text的y的起始点是text的基准线的位置,而不是从text的头部的位置
float tipTop = tipMarginHeight - mTipPaint.getFontMetrics().top;
//根据状态不一样,数据不一样
if (mStatus != STATUS_FINISH) {
if (isChapterListPrepare) {
String title = mChapterList.get(mCurChapterPos).getTitle();
title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), title, true);
canvas.drawText(title, mMarginLeft, tipTop, mTipPaint);
}
} else {
String title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), mCurPage.title, true);
title = TextUtils.ellipsize(title, mTipPaint, mDisplayWidth - mMarginLeft - mMarginRight - mTipPaint.measureText(progress), TextUtils.TruncateAt.END).toString();
canvas.drawText(title, mMarginLeft, tipTop, mTipPaint);
/******绘制页码********/
// 底部的字显示的位置Y
float y = mDisplayHeight - mTipPaint.getFontMetrics().bottom - tipMarginHeight;
String percent = (mCurPage.position + 1) + "/" + mCurChapter.getPageSize();
canvas.drawText(percent, mMarginLeft, y, mTipPaint);
}

/*******绘制进度*******/
float progressTipLeft = mDisplayWidth - mMarginRight - mTipPaint.measureText(progress);
canvas.drawText(progress, progressTipLeft, tipTop, mTipPaint);
String title = getPagePos() == 0 ? mCollBook.getName() : mCurPage.title;
title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), title, true);
title = TextUtils.ellipsize(title, mTipPaint, mDisplayWidth - mMarginLeft - mMarginRight - mTipPaint.measureText(progress), TextUtils.TruncateAt.END).toString();
canvas.drawText(title, mMarginLeft, tipTop, mTipPaint);
/******绘制页码********/
// 底部的字显示的位置Y
float y = mDisplayHeight - mTipPaint.getFontMetrics().bottom - tipMarginHeight;
String percent = (mCurPage.position + 1) + "/" + mCurChapter.getPageSize();
canvas.drawText(percent, mMarginLeft, y, mTipPaint);
} else {
String title = mCollBook.getName();
title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), title, true);
canvas.drawText(title, mMarginLeft, tipTop, mTipPaint);
}
/*******绘制进度*******/
float progressTipLeft = mDisplayWidth - mMarginRight - mTipPaint.measureText(progress);
canvas.drawText(progress, progressTipLeft, tipTop, mTipPaint);
} else {
float tipBottom = mDisplayHeight - mTipPaint.getFontMetrics().bottom - tipMarginHeight;
//根据状态不一样,数据不一样
if (mStatus != STATUS_FINISH) {
if (isChapterListPrepare) {
canvas.drawText(mChapterList.get(mCurChapterPos).getTitle()
, mMarginLeft, tipBottom, mTipPaint);
}
} else {
if (!mChapterList.isEmpty() && mStatus == STATUS_FINISH) {

/******绘制页码********/
String percent = (mCurPage.position + 1) + "/" + mCurChapter.getPageSize();
//页码的x坐标
float tipLeft = mDisplayWidth - 2 * mMarginRight - mTipPaint.measureText(percent + progress);
canvas.drawText(percent, tipLeft, tipBottom, mTipPaint);

String title = TextUtils.ellipsize(mCurPage.title, mTipPaint, tipLeft - 2 * mMarginRight, TextUtils.TruncateAt.END).toString();
String title = getPagePos() == 0 ? mCollBook.getName() : mCurPage.title;
title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), title, true);
title = TextUtils.ellipsize(title, mTipPaint, tipLeft - 2 * mMarginRight, TextUtils.TruncateAt.END).toString();
canvas.drawText(title, mMarginLeft, tipBottom, mTipPaint);
} else {
String title = mCollBook.getName();
title = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), title, true);
canvas.drawText(title, mMarginLeft, tipBottom, mTipPaint);
}
/*******绘制进度*******/
Expand Down Expand Up @@ -1031,7 +1027,10 @@ private void drawContent(Bitmap bitmap) {
String tip = "";
switch (mStatus) {
case STATUS_LOADING:
tip = "正在加载章节内容...";
if (isChapterListPrepare) {
tip = mChapterList.get(mCurChapterPos).getTitle();
}
tip += "\n正在加载章节内容...";
break;
case STATUS_LOADING_CHAPTER:
tip = "正在加载目录列表...";
Expand All @@ -1056,7 +1055,8 @@ private void drawContent(Bitmap bitmap) {
break;
}
if (mStatus == STATUS_ERROR || mStatus == STATUS_CATEGORY_ERROR
|| mStatus == STATUS_PARSE_ERROR) {
|| mStatus == STATUS_PARSE_ERROR
|| (isChapterListPrepare && mStatus == STATUS_LOADING)) {
drawErrorMsg(canvas, tip, 0);
} else {
//将提示语句放到正中间
Expand Down Expand Up @@ -1517,8 +1517,8 @@ private void dealLoadPageList(int chapterPos) {
private void chapterChangeCallback() {
if (mPageChangeListener != null) {
readAloudParagraph = -1;
mPageChangeListener.onPageChange(0, resetReadAloud);
mPageChangeListener.onChapterChange(mCurChapterPos);
mPageChangeListener.onPageChange(mCollBook.getLastReadPosition(), resetReadAloud);
resetReadAloud = true;
mPageChangeListener.onPageCountChange(mCurChapter != null ? mCurChapter.getPageSize() : 0);
}
Expand Down
2 changes: 1 addition & 1 deletion app/version_code.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Jun 14 12:41:11 CST 2021
#Tue Jun 15 19:45:01 CST 2021
VERSION_CODE=212

0 comments on commit 35d7b12

Please sign in to comment.