From 0fe7b599898832e3f4a3d8f8fcfe4c32b1564ccb Mon Sep 17 00:00:00 2001
From: fengyuecanzhu <1021300691@qq.com>
Date: Sun, 13 Jun 2021 22:57:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81epub=E9=98=85=E8=AF=BB(?=
=?UTF-8?q?=E4=BB=85=E6=94=AF=E6=8C=81=E6=96=87=E5=AD=97)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/assetWizardSettings.xml | 4 +-
app/build.gradle | 5 +
app/src/main/AndroidManifest.xml | 1 +
.../xyz/fycz/myreader/common/APPCONST.java | 9 +-
.../xyz/fycz/myreader/common/URLCONST.java | 2 +
.../xyz/fycz/myreader/entity/Quotation.java | 31 ++
.../ui/activity/AdSettingActivity.java | 13 +
.../myreader/ui/activity/DonateActivity.java | 25 +-
.../ui/activity/FileSystemActivity.java | 3 +-
.../myreader/ui/activity/ReadActivity.java | 203 +++--------
.../ui/activity/SearchBookActivity.java | 6 +-
.../ui/fragment/FileCategoryFragment.java | 14 +-
.../myreader/ui/fragment/FindFragment.java | 46 ++-
.../ui/fragment/LocalBookFragment.java | 2 +-
.../myreader/util/media/LocalFileLoader.java | 18 +-
.../xyz/fycz/myreader/util/utils/AdUtils.java | 8 +-
.../fycz/myreader/util/utils/FileUtils.java | 6 +-
.../myreader/widget/page/BookChapterBean.java | 56 ---
.../myreader/widget/page/EpubPageLoader.java | 328 ++++++++++++++++++
.../myreader/widget/page/LocalPageLoader.java | 122 +++----
.../myreader/widget/page/NetPageLoader.java | 76 ++--
.../fycz/myreader/widget/page/PageLoader.java | 16 +-
.../fycz/myreader/widget/page/PageView.java | 7 +-
app/src/main/res/drawable/ic_edit.xml | 4 +-
app/src/main/res/drawable/ic_quotations.xml | 27 ++
...{menu_book_detail.xml => shape_runway.xml} | 0
.../main/res/layout/activity_ad_setting.xml | 10 +
app/src/main/res/layout/activity_read.xml | 8 -
app/src/main/res/layout/activity_splash.xml | 4 +-
app/src/main/res/layout/fragment_find.xml | 328 +++++++++++-------
app/src/main/res/layout/menu_book.xml | 2 +-
app/src/main/res/layout/menu_book_local.xml | 2 +-
32 files changed, 873 insertions(+), 513 deletions(-)
create mode 100644 app/src/main/java/xyz/fycz/myreader/entity/Quotation.java
delete mode 100644 app/src/main/java/xyz/fycz/myreader/widget/page/BookChapterBean.java
create mode 100644 app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java
create mode 100644 app/src/main/res/drawable/ic_quotations.xml
rename app/src/main/res/drawable/{menu_book_detail.xml => shape_runway.xml} (100%)
diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml
index 46bf8ba..ca8bf99 100644
--- a/.idea/assetWizardSettings.xml
+++ b/.idea/assetWizardSettings.xml
@@ -14,8 +14,8 @@
diff --git a/app/build.gradle b/app/build.gradle
index 074096d..d3c6af9 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -213,6 +213,11 @@ dependencies {
//XXPermissions
implementation 'com.github.getActivity:XXPermissions:11.2'
+ //epub
+ implementation('com.positiondev.epublib:epublib-core:3.1') {
+ exclude group: 'org.slf4j'
+ exclude group: 'xmlpull'
+ }
}
greendao {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 28d8283..ad3c638 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -109,6 +109,7 @@
+
diff --git a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
index 0353c42..1df4798 100644
--- a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
+++ b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java
@@ -31,6 +31,7 @@ public class APPCONST {
public static final String FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/";
public static final String SHARE_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/share/";
public static String LOG_DIR = FileUtils.getCachePath() + "/log/";
+ public static String COVER_DIR = FileUtils.getCachePath() + "/covers/";
public static final String BG_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/bg/";
public static String TEM_FILE_DIR = FileUtils.getCachePath() + "/tem/";
public static final String BACKUP_FILE_DIR = Environment.getExternalStorageDirectory() + "/FYReader/backup/";
@@ -124,12 +125,4 @@ public class APPCONST {
public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4168.3 Safari/537.36";
- private static Boolean hasStoragePermission = null;
-
- public static boolean hasStoragePermission() {
- if (hasStoragePermission == null) {
- hasStoragePermission = XXPermissions.isGranted(App.getmContext(), STORAGE_PERMISSIONS);
- }
- return hasStoragePermission;
- }
}
diff --git a/app/src/main/java/xyz/fycz/myreader/common/URLCONST.java b/app/src/main/java/xyz/fycz/myreader/common/URLCONST.java
index 732bd49..80c2134 100644
--- a/app/src/main/java/xyz/fycz/myreader/common/URLCONST.java
+++ b/app/src/main/java/xyz/fycz/myreader/common/URLCONST.java
@@ -29,5 +29,7 @@ public class URLCONST {
public static final String WX_ZSM = DONATE + "/wx_zsm.png";
public static final String ZFB_SKM = DONATE + "/zfb_skm.jpg";
public static final String QQ_SKM = DONATE + "/qq_skm.png";
+
+ public static final String QUOTATION = "https://v1.hitokoto.cn/?encode=json&charset=utf-8";
}
diff --git a/app/src/main/java/xyz/fycz/myreader/entity/Quotation.java b/app/src/main/java/xyz/fycz/myreader/entity/Quotation.java
new file mode 100644
index 0000000..381dba1
--- /dev/null
+++ b/app/src/main/java/xyz/fycz/myreader/entity/Quotation.java
@@ -0,0 +1,31 @@
+package xyz.fycz.myreader.entity;
+
+/**
+ * @author fengyue
+ * @date 2021/6/12 20:55
+ */
+public class Quotation {
+ private String hitokoto;
+ private String from;
+
+ public String getHitokoto() {
+ return hitokoto;
+ }
+
+ public void setHitokoto(String hitokoto) {
+ this.hitokoto = hitokoto;
+ }
+
+ public String getFrom() {
+ return from;
+ }
+
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ @Override
+ public String toString() {
+ return hitokoto + " --- " + from;
+ }
+}
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/AdSettingActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/AdSettingActivity.java
index f3c4dbc..3f416d0 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/AdSettingActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/AdSettingActivity.java
@@ -1,5 +1,6 @@
package xyz.fycz.myreader.ui.activity;
+import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
@@ -10,10 +11,12 @@ import com.kongzue.dialogx.dialogs.BottomMenu;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import xyz.fycz.myreader.R;
+import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.databinding.ActivityAdSettingBinding;
import xyz.fycz.myreader.ui.dialog.LoadingDialog;
+import xyz.fycz.myreader.ui.dialog.MyAlertDialog;
import xyz.fycz.myreader.util.help.DateHelper;
import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
@@ -81,6 +84,7 @@ public class AdSettingActivity extends BaseActivity {
binding.scAd.setChecked(aBoolean);
if (aBoolean) {
binding.llAdSetting.setVisibility(View.VISIBLE);
+ binding.rlFlowAdCount.setVisibility(App.isDebug() ? View.VISIBLE : View.GONE);
}
loadingDialog.dismiss();
}
@@ -93,6 +97,15 @@ public class AdSettingActivity extends BaseActivity {
String curAdTimesStr = getAdTimesStr(curAdTimes);
binding.tvSplashCurAdTimes.setText(getString(R.string.splash_cur_ad_times, curAdTimesStr, curAdCount + "次"));
binding.scBookDetailAd.setChecked(bookDetailAd);
+ binding.rlFlowAdCount.setOnClickListener(v -> {
+ int[] n = new int[1];
+ MyAlertDialog.createInputDia(this, "", "", "",
+ true, 1, (MyAlertDialog.onInputChangeListener) text -> {
+ n[0] = Integer.parseInt(text);
+ }, (dialog, which) -> {
+ SharedPreUtils.getInstance().putInt("flowAdCount", n[0]);
+ });
+ });
}
@Override
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
index 3fe4479..b1da373 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/DonateActivity.java
@@ -16,10 +16,12 @@ import java.util.List;
import io.reactivex.annotations.NonNull;
import xyz.fycz.myreader.R;
+import xyz.fycz.myreader.application.App;
import xyz.fycz.myreader.base.BaseActivity;
import xyz.fycz.myreader.base.observer.MySingleObserver;
import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.databinding.ActivityDonateBinding;
+import xyz.fycz.myreader.util.SharedPreUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.utils.AdUtils;
@@ -60,25 +62,30 @@ public class DonateActivity extends BaseActivity {
private void initAd() {
binding.llAdSupport.setVisibility(View.VISIBLE);
- new DdSdkFlowAd().getFlowViews(DonateActivity.this, 6, 1, new DdSdkFlowAd.FlowCallback() {
+ int flowAdCount = SharedPreUtils.getInstance().getInt("flowAdCount", 2);
+ int count = App.isDebug() ? flowAdCount : 1;
+ new DdSdkFlowAd().getFlowViews(DonateActivity.this, 6, count, new DdSdkFlowAd.FlowCallback() {
// 信息流广告拉取完毕后返回的 views
@Override
public void getFlowViews(List views) {
- Log.i(TAG, "信息流广告拉取完毕后返回了" + views.size() + "个view");
- binding.llAdSupport.addView(views.get(0), 2);
+ Log.d(TAG, "信息流广告拉取完毕后返回了" + views.size() + "个view");
+ for (int i = 0; i < views.size(); i++) {
+ View view = views.get(i);
+ binding.llAdSupport.addView(view, i + 2);
+ }
}
// 信息流广告展示后调用
@Override
public void show() {
AdUtils.adRecord("flow","adShow");
- Log.i(TAG, "信息流广告展示成功");
+ Log.d(TAG, "信息流广告展示成功");
}
// 广告拉取失败调用
@Override
public void error(String msg) {
- Log.i(TAG, "广告拉取失败\n" + msg);
+ Log.d(TAG, "广告拉取失败\n" + msg);
}
});
}
@@ -92,13 +99,13 @@ public class DonateActivity extends BaseActivity {
DdSdkRewardAd.show(this, new DdSdkRewardAd.DdSdkRewardCallback() {
@Override
public void show() {
- Log.i(TAG, "激励视频展示成功");
+ Log.d(TAG, "激励视频展示成功");
AdUtils.adRecord("rewardVideo","adShow");
}
@Override
public void click() {
- Log.i(TAG, "激励视频被点击");
+ Log.d(TAG, "激励视频被点击");
AdUtils.adRecord("rewardVideo","adClick");
}
@@ -108,13 +115,13 @@ public class DonateActivity extends BaseActivity {
@Override
public void skip() {
- Log.i(TAG, "激励视频被跳过");
+ Log.d(TAG, "激励视频被跳过");
AdUtils.adRecord("rewardVideo","adSkip");
}
@Override
public void finishCountdown() {
- Log.i(TAG, "激励视频计时完成");
+ Log.d(TAG, "激励视频计时完成");
AdUtils.adRecord("rewardVideo","adFinishCount");
}
});
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java
index 487ed50..a6faa06 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/FileSystemActivity.java
@@ -21,6 +21,7 @@ import xyz.fycz.myreader.ui.fragment.BaseFileFragment;
import xyz.fycz.myreader.ui.fragment.FileCategoryFragment;
import xyz.fycz.myreader.ui.fragment.LocalBookFragment;
import xyz.fycz.myreader.util.ToastUtils;
+import xyz.fycz.myreader.util.utils.FileUtils;
/**
@@ -187,7 +188,7 @@ public class FileSystemActivity extends BaseTabActivity {
if (!file.exists()) continue;
Book book = new Book();
- book.setName(file.getName().replace(".txt", ""));
+ book.setName(file.getName().replace(FileUtils.SUFFIX_EPUB, "").replace(FileUtils.SUFFIX_TXT, ""));
book.setChapterUrl(file.getAbsolutePath());
book.setType("本地书籍");
book.setHistoryChapterId("未开始阅读");
diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
index e91a6f6..2227705 100644
--- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
+++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
@@ -15,7 +15,6 @@ import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
-import android.os.Message;
import android.speech.tts.TextToSpeech;
import android.text.TextUtils;
import android.util.Log;
@@ -50,7 +49,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import xyz.fycz.myreader.ActivityManage;
@@ -64,8 +62,8 @@ import xyz.fycz.myreader.common.APPCONST;
import xyz.fycz.myreader.common.URLCONST;
import xyz.fycz.myreader.databinding.ActivityReadBinding;
import xyz.fycz.myreader.entity.Setting;
-import xyz.fycz.myreader.enums.LocalBookSource;
import xyz.fycz.myreader.enums.Font;
+import xyz.fycz.myreader.enums.LocalBookSource;
import xyz.fycz.myreader.greendao.DbManager;
import xyz.fycz.myreader.greendao.entity.Book;
import xyz.fycz.myreader.greendao.entity.BookMark;
@@ -92,26 +90,23 @@ import xyz.fycz.myreader.ui.popmenu.CustomizeComMenu;
import xyz.fycz.myreader.ui.popmenu.CustomizeLayoutMenu;
import xyz.fycz.myreader.ui.popmenu.ReadSettingMenu;
import xyz.fycz.myreader.util.BrightUtil;
-import xyz.fycz.myreader.util.help.DateHelper;
import xyz.fycz.myreader.util.ShareUtils;
import xyz.fycz.myreader.util.SharedPreUtils;
-import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.SystemUtil;
import xyz.fycz.myreader.util.ToastUtils;
+import xyz.fycz.myreader.util.help.DateHelper;
+import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.notification.NotificationClickReceiver;
import xyz.fycz.myreader.util.notification.NotificationUtil;
import xyz.fycz.myreader.util.utils.ColorUtil;
import xyz.fycz.myreader.util.utils.NetworkUtils;
-import xyz.fycz.myreader.util.utils.RxUtils;
import xyz.fycz.myreader.util.utils.ScreenUtils;
import xyz.fycz.myreader.util.utils.StringUtils;
import xyz.fycz.myreader.util.utils.SystemBarUtils;
import xyz.fycz.myreader.webapi.BookApi;
-import xyz.fycz.myreader.webapi.ResultCallback;
import xyz.fycz.myreader.webapi.crawler.ReadCrawlerUtil;
import xyz.fycz.myreader.webapi.crawler.base.ReadCrawler;
import xyz.fycz.myreader.widget.BubblePopupView;
-import xyz.fycz.myreader.widget.page.LocalPageLoader;
import xyz.fycz.myreader.widget.page.PageLoader;
import xyz.fycz.myreader.widget.page.PageMode;
import xyz.fycz.myreader.widget.page.PageView;
@@ -133,7 +128,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
/***************************variable*****************************/
private Book mBook;
private List aBooks;
- private ArrayList mChapters = new ArrayList<>();
+ private List mChapters = new ArrayList<>();
private ChapterService mChapterService;
private BookService mBookService;
private BookMarkService mBookMarkService;
@@ -212,55 +207,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
}
};
- @SuppressLint("HandlerLeak")
- private Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 1:
- init();
- break;
- case 2:
- try {
- int chapterPos = msg.arg1;
- int pagePos = msg.arg2;
- mPageLoader.skipToChapter(chapterPos);
- mPageLoader.skipToPage(pagePos);
- } catch (Exception e) {
- //ToastUtils.showError("章节跳转失败,请截图联系作者。\n" + e.getMessage());
- e.printStackTrace();
- }
- break;
- case 3:
- break;
- case 4:
- saveLastChapterReadPosition();
- screenOffTimerStart();
- initMenu();
- break;
- case 5:
- if (mPageLoader != null) {
- mPageLoader.refreshUi();
- }
- break;
- case 6:
- mPageLoader.setmStatus(PageLoader.STATUS_LOADING);
- break;
- case 7:
- ToastUtils.showWarring("无网络连接!");
- mPageLoader.chapterError("无网络连接!");
- break;
- case 8:
- binding.pbLoading.setVisibility(View.GONE);
- break;
- case 9:
- ToastUtils.showInfo("正在后台缓存书籍,具体进度可查看通知栏!");
- notificationUtil.requestNotificationPermissionDialog(ReadActivity.this);
- break;
- }
- }
- };
-
+ private Handler mHandler = new Handler();
@Override
protected void bindView() {
@@ -335,6 +282,9 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
if (pagePos != -1 && chapterPos != -1) {
mBook.setHisttoryChapterNum(chapterPos);
mBook.setLastReadPosition(pagePos);
+ } else {
+ pagePos = mBook.getLastReadPosition();
+ chapterPos = mBook.getHisttoryChapterNum();
}
if (SharedPreUtils.getInstance().getBoolean(getString(R.string.isNightFS), false)) {
mSetting.setDayStyle(!ColorUtil.isColorLight(getResources().getColor(R.color.textPrimary)));
@@ -373,7 +323,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
if (!mSetting.isBrightFollowSystem()) {
BrightUtil.setBrightness(this, mSetting.getBrightProgress());
}
- binding.pbLoading.setVisibility(View.VISIBLE);
initEyeView();
initSettingListener();
initTopMenu();
@@ -437,12 +386,26 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
new PageLoader.OnPageChangeListener() {
@Override
public void onChapterChange(int pos) {
+ chapterPos = pos;
mBook.setHistoryChapterId(mChapters.get(pos).getTitle());
recordReadTime();
}
@Override
public void onCategoryFinish(List chapters) {
+ mChapters = chapters;
+ mBook.setNoReadNum(0);
+ mBook.setChapterTotalNum(chapters.size());
+ mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle());
+ if (hasChangeSource) {
+ mBookService.matchHistoryChapterPos(mBook, mChapters);
+ skipToChapterAndPage(mBook.getHisttoryChapterNum(), mBook.getLastReadPosition());
+ hasChangeSource = false;
+ mChapterService.addChapters(chapters);
+ }
+ mBookService.updateEntity(mBook);
+ loadFinish = true;
+ invalidateOptionsMenu();
}
@Override
@@ -452,7 +415,10 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
@Override
public void onPageChange(int pos, boolean resetRead) {
- mHandler.sendMessage(mHandler.obtainMessage(4));
+ pagePos = pos;
+ saveLastChapterReadPosition();
+ screenOffTimerStart();
+ initMenu();
recordReadTime();
if (ReadAloudService.running) {
if (mPageLoader.hasChapterData(mChapters.get(mPageLoader.getChapterPos()))) {
@@ -617,7 +583,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
}
//保存最近阅读时间
mBook.setLastReadTime(DateHelper.getLongDate());
- getData();
+ init();
}
@@ -723,9 +689,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
autoPageStop();
}
ReadAloudService.stop(this);
- for (int i = 0; i < 9; i++) {
- mHandler.removeMessages(i + 1);
- }
if (mPageLoader != null) {
mPageLoader.closeBook();
mPageLoader = null;
@@ -843,7 +806,9 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
boolean needRefresh = data.getBooleanExtra(APPCONST.RESULT_NEED_REFRESH, false);
boolean upMenu = data.getBooleanExtra(APPCONST.RESULT_UP_MENU, false);
if (needRefresh) {
- mHandler.sendEmptyMessage(5);
+ if (mPageLoader != null) {
+ mPageLoader.refreshUi();
+ }
}
if (upMenu) {
initTopMenu();
@@ -904,19 +869,16 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
screenOffTimerStart();
mPageLoader.init();
mPageLoader.refreshChapterList();
- loadFinish = true;
- invalidateOptionsMenu();
- mHandler.sendMessage(mHandler.obtainMessage(8));
}
private void initMenu() {
if (mChapters != null && mChapters.size() != 0) {
- Chapter curChapter = mChapters.get(mPageLoader.getChapterPos());
+ Chapter curChapter = mChapters.get(chapterPos);
String url = curChapter.getUrl();
binding.tvChapterTitleTop.setText(curChapter.getTitle());
binding.tvChapterUrl.setText(StringHelper.isEmpty(url) ? curChapter.getId() :
NetworkUtils.getAbsoluteURL(mReadCrawler.getNameSpace(), url));
- binding.readSbChapterProgress.setProgress(mPageLoader.getPagePos());
+ binding.readSbChapterProgress.setProgress(pagePos);
binding.readSbChapterProgress.setMax(mPageLoader.getAllPagePos() - 1);
binding.readTvPageTip.setText(String.format("%s/%s",
binding.readSbChapterProgress.getProgress() + 1, binding.readSbChapterProgress.getMax() + 1));
@@ -1023,85 +985,6 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
}, (dialog, which) -> dialog.dismiss());
}
/************************章节相关*************************/
- /**
- * 章节数据网络同步
- */
- private void getData() {
- mChapters = (ArrayList) mChapterService.findBookAllChapterByBookId(mBook.getId());
- if (!isCollected || mChapters.size() == 0 || ("本地书籍".equals(mBook.getType()) && !ChapterService.isChapterCached(mBook.getId(), mChapters.get(0).getTitle())
- )) {
- if ("本地书籍".equals(mBook.getType())) {
- if (!new File(mBook.getChapterUrl()).exists()) {
- ToastUtils.showWarring("书籍缓存为空且源文件不存在,书籍加载失败!");
- finish();
- return;
- }
- if (mChapters.size() != 0 && mChapters.get(0).getEnd() > 0) {
- initChapters();
- return;
- }
- ((LocalPageLoader) mPageLoader).loadChapters(new ResultCallback() {
- @Override
- public void onFinish(Object o, int code) {
- ArrayList chapters = (ArrayList) o;
- mBook.setChapterTotalNum(chapters.size());
- mBook.setNewestChapterTitle(chapters.get(chapters.size() - 1).getTitle());
- mBookService.updateEntity(mBook);
- if (mChapters.size() == 0) {
- updateAllOldChapterData(chapters);
- }
- initChapters();
- mHandler.sendMessage(mHandler.obtainMessage(1));
- }
-
- @Override
- public void onError(Exception e) {
- e.printStackTrace();
- mChapters.clear();
- initChapters();
- mHandler.sendMessage(mHandler.obtainMessage(1));
- }
- });
- } else {
- mPageLoader.setmStatus(PageLoader.STATUS_LOADING_CHAPTER);
- BookApi.getBookChapters(mBook, mReadCrawler).flatMap(chapters -> Observable.create(emitter -> {
- updateAllOldChapterData(chapters);
- initChapters();
- emitter.onNext(chapters);
- emitter.onComplete();
- })).compose(RxUtils::toSimpleSingle).subscribe(new MyObserver