优化阅读体验

pull/5/head
fengyuecanzhu 4 years ago
parent 635dd06a54
commit 947a87bf25
  1. 11
      app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
  2. 20
      app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java
  3. 32
      app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java

@ -222,14 +222,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
} }
break; break;
case 6: case 6:
mPageLoader.openChapter(); mPageLoader.setmStatus(PageLoader.STATUS_LOADING);
if (mPageLoader.isPrev()) {//判断是否向前翻页打开章节,如果是则打开自己后跳转到最后一页,否则不跳转
try {//概率性异常(空指针异常)
mPageLoader.skipToPage(mPageLoader.getAllPagePos() - 1);
} catch (Exception e) {
e.printStackTrace();
}
}
break; break;
case 7: case 7:
ToastUtils.showWarring("无网络连接!"); ToastUtils.showWarring("无网络连接!");
@ -1000,9 +993,11 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
} }
}); });
} else { } else {
mPageLoader.setmStatus(PageLoader.STATUS_LOADING_CHAPTER);
CommonApi.getBookChapters(mBook.getChapterUrl(), mReadCrawler, false, new ResultCallback() { CommonApi.getBookChapters(mBook.getChapterUrl(), mReadCrawler, false, new ResultCallback() {
@Override @Override
public void onFinish(Object o, int code) { public void onFinish(Object o, int code) {
mPageLoader.setmStatus(PageLoader.STATUS_LOADING);
ArrayList<Chapter> chapters = (ArrayList<Chapter>) o; ArrayList<Chapter> chapters = (ArrayList<Chapter>) o;
updateAllOldChapterData(chapters); updateAllOldChapterData(chapters);
initChapters(); initChapters();

@ -20,11 +20,6 @@ import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Created by newbiechen on 17-5-29.
* 网络页面加载器
*/
public class NetPageLoader extends PageLoader { public class NetPageLoader extends PageLoader {
private static final String TAG = "PageFactory"; private static final String TAG = "PageFactory";
private ChapterService mChapterService; private ChapterService mChapterService;
@ -220,18 +215,10 @@ public class NetPageLoader extends PageLoader {
* *
* @param chapter * @param chapter
*/ */
public void getChapterContent(final Chapter chapter) { public void getChapterContent(Chapter chapter) {
Chapter cacheChapter = mChapterService.findChapterByBookIdAndTitle(chapter.getBookId(), chapter.getTitle());
if (cacheChapter != null && hasChapterData(chapter)) {
chapter.setContent(APPCONST.BOOK_CACHE_PATH + chapter.getBookId()
+ File.separator + chapter.getTitle() + FileUtils.SUFFIX_FY);
chapter.setId(cacheChapter.getId());
mChapterService.saveOrUpdateChapter(chapter, null);
} else {
CommonApi.getChapterContent(chapter.getUrl(), mReadCrawler, new ResultCallback() { CommonApi.getChapterContent(chapter.getUrl(), mReadCrawler, new ResultCallback() {
@Override @Override
public void onFinish(final Object o, int code) { public void onFinish(final Object o, int code) {
// chapter.setContent((String) o);
mChapterService.saveOrUpdateChapter(chapter, (String) o); mChapterService.saveOrUpdateChapter(chapter, (String) o);
if (getPageStatus() == PageLoader.STATUS_LOADING) { if (getPageStatus() == PageLoader.STATUS_LOADING) {
MyApplication.runOnUiThread(() -> { MyApplication.runOnUiThread(() -> {
@ -246,13 +233,12 @@ public class NetPageLoader extends PageLoader {
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
ToastUtils.showError("章节加载失败\n" + e.getLocalizedMessage()); if (mCurChapterPos == chapter.getNumber())
chapterError();
e.printStackTrace(); e.printStackTrace();
} }
}); });
} }
}
} }

@ -55,12 +55,13 @@ public abstract class PageLoader {
// 当前页面的状态 // 当前页面的状态
public static final int STATUS_LOADING = 1; // 正在加载 public static final int STATUS_LOADING = 1; // 正在加载
public static final int STATUS_FINISH = 2; // 加载完成 public static final int STATUS_LOADING_CHAPTER = 2; // 正在加载目录
public static final int STATUS_ERROR = 3; // 加载错误 (一般是网络加载情况) public static final int STATUS_FINISH = 3; // 加载完成
public static final int STATUS_EMPTY = 4; // 空数据 public static final int STATUS_ERROR = 4; // 加载错误 (一般是网络加载情况)
public static final int STATUS_PARING = 5; // 正在解析 (装载本地数据) public static final int STATUS_EMPTY = 5; // 空数据
public static final int STATUS_PARSE_ERROR = 6; // 本地文件解析错误(暂未被使用) public static final int STATUS_PARING = 6; // 正在解析 (装载本地数据)
public static final int STATUS_CATEGORY_EMPTY = 7; // 获取到的目录为空 public static final int STATUS_PARSE_ERROR = 7; // 本地文件解析错误(暂未被使用)
public static final int STATUS_CATEGORY_EMPTY = 8; // 获取到的目录为空
// 默认的显示参数配置 // 默认的显示参数配置
public static final int DEFAULT_MARGIN_HEIGHT = 28; public static final int DEFAULT_MARGIN_HEIGHT = 28;
public static final int DEFAULT_MARGIN_WIDTH = 15; public static final int DEFAULT_MARGIN_WIDTH = 15;
@ -721,7 +722,7 @@ public abstract class PageLoader {
// 如果章节目录没有准备好 // 如果章节目录没有准备好
if (!isChapterListPrepare) { if (!isChapterListPrepare) {
mStatus = STATUS_LOADING; mStatus = STATUS_LOADING_CHAPTER;
mPageView.drawCurPage(false); mPageView.drawCurPage(false);
return; return;
} }
@ -1007,13 +1008,16 @@ public abstract class PageLoader {
String tip = ""; String tip = "";
switch (mStatus) { switch (mStatus) {
case STATUS_LOADING: case STATUS_LOADING:
tip = "正在拼命加载中..."; tip = "正在加载章节内容...";
break;
case STATUS_LOADING_CHAPTER:
tip = "正在加载目录列表...";
break; break;
case STATUS_ERROR: case STATUS_ERROR:
tip = "加载失败(点击边缘重试)"; tip = "章节内容加载失败";
break; break;
case STATUS_EMPTY: case STATUS_EMPTY:
tip = "章内容为空"; tip = "章内容为空";
break; break;
case STATUS_PARING: case STATUS_PARING:
tip = "正在拆分章节请等待..."; tip = "正在拆分章节请等待...";
@ -1305,6 +1309,8 @@ public abstract class PageLoader {
mCancelPage = mCurPage; mCancelPage = mCurPage;
if (parsePrevChapter()) { if (parsePrevChapter()) {
mCurPage = getPrevLastPage(); mCurPage = getPrevLastPage();
if (mStatus == STATUS_LOADING)
mStatus = STATUS_FINISH;
} else { } else {
mCurPage = new TxtPage(); mCurPage = new TxtPage();
} }
@ -1378,6 +1384,8 @@ public abstract class PageLoader {
// 解析下一章数据 // 解析下一章数据
if (parseNextChapter()) { if (parseNextChapter()) {
mCurPage = mCurChapter.getPage(0); mCurPage = mCurChapter.getPage(0);
if (mStatus == STATUS_LOADING)
mStatus = STATUS_FINISH;
} else { } else {
mCurPage = new TxtPage(); mCurPage = new TxtPage();
} }
@ -2000,6 +2008,10 @@ public abstract class PageLoader {
isPrev = prev; isPrev = prev;
} }
public void setmStatus(int mStatus) {
this.mStatus = mStatus;
}
/*****************************************interface*****************************************/ /*****************************************interface*****************************************/
public interface OnPageChangeListener { public interface OnPageChangeListener {

Loading…
Cancel
Save