优化阅读体验

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

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

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

Loading…
Cancel
Save