支持epub阅读(仅支持文字)

pull/5/head v2.1.2
fengyuecanzhu 3 years ago
parent 891770ad51
commit 72acb8e74d
  1. 2
      app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java
  2. 2
      app/src/main/java/xyz/fycz/myreader/ui/adapter/ChapterTitleAdapter.java
  3. 18
      app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java
  4. 8
      app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java
  5. 3
      app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java
  6. 13
      app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java

@ -796,7 +796,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe
try {
skipToChapterAndPage(chapterAndPage[0], chapterAndPage[1]);
} catch (Exception e) {
ToastUtils.showError("章节跳转失败,请截图联系作者。\n" +
ToastUtils.showError("章节跳转失败\n" +
e.getMessage());
e.printStackTrace();
}

@ -68,7 +68,7 @@ public class ChapterTitleAdapter extends ArrayAdapter<Chapter> {
final Chapter chapter = getItem(postion);
// viewHolder.tvTitle.setText("【" + chapter.getTitle() + "】");
viewHolder.tvTitle.setText(chapter.getTitle());
if (ChapterService.isChapterCached(chapter.getBookId(), chapter.getTitle()) || chapter.getEnd() > 0 ) {
if (ChapterService.isChapterCached(chapter.getBookId(), chapter.getTitle()) || chapter.getEnd() > 0) {
viewHolder.tvTitle.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(getContext(),R.drawable.selector_category_load), null, null, null);
} else {
viewHolder.tvTitle.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(getContext(),R.drawable.selector_category_unload), null, null, null);

@ -1,12 +1,8 @@
package xyz.fycz.myreader.widget.page;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.text.TextUtils;
import android.util.Log;
import net.sf.jazzlib.ZipFile;
import org.jsoup.Jsoup;
@ -18,6 +14,7 @@ import org.jsoup.select.Elements;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
@ -27,7 +24,6 @@ import java.util.List;
import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
@ -65,6 +61,8 @@ public class EpubPageLoader extends PageLoader {
Observable.create((ObservableOnSubscribe<xyz.fycz.myreader.greendao.entity.Book>) e -> {
File bookFile = new File(mCollBook.getChapterUrl());
if (!bookFile.exists())
e.onError(new FileNotFoundException("书籍源文件不存在\n" + mCollBook.getChapterUrl()));
epubBook = readBook(bookFile);
if (epubBook == null) {
@ -76,7 +74,7 @@ public class EpubPageLoader extends PageLoader {
}
mCharset = Charset.forName(mCollBook.getInfoUrl());
if (TextUtils.isEmpty(mCollBook.getImgUrl())){
if (TextUtils.isEmpty(mCollBook.getImgUrl())) {
saveCover();
}
e.onNext(mCollBook);
@ -99,7 +97,7 @@ public class EpubPageLoader extends PageLoader {
@Override
public void onError(Throwable e) {
chapterError(e.getMessage());
error(STATUS_CATEGORY_ERROR, e.getMessage());
}
});
}
@ -157,7 +155,9 @@ public class EpubPageLoader extends PageLoader {
private List<Chapter> loadChapters() {
Metadata metadata = epubBook.getMetadata();
mCollBook.setName(metadata.getFirstTitle());
if (!TextUtils.isEmpty(metadata.getFirstTitle())) {
mCollBook.setName(metadata.getFirstTitle());
}
if (metadata.getAuthors().size() > 0) {
String author = metadata.getAuthors().get(0).toString().replaceAll("^, |, $", "");
mCollBook.setAuthor(author);
@ -192,12 +192,14 @@ public class EpubPageLoader extends PageLoader {
} else {
bean.setTitle(title);
}
bean.setEnd(1);
mChapterList.add(bean);
}
} else {
parseMenu(refs, 0);
for (int i = 0; i < mChapterList.size(); i++) {
mChapterList.get(i).setNumber(i);
mChapterList.get(i).setEnd(1);
}
}

@ -68,7 +68,10 @@ public class LocalPageLoader extends PageLoader {
public void refreshChapterList() {
// 对于文件是否存在,或者为空的判断,不作处理。 ==> 在文件打开前处理过了。
mBookFile = new File(mCollBook.getChapterUrl());
if (!mBookFile.exists()) {
error(STATUS_CATEGORY_ERROR, "书籍源文件不存在\n" + mCollBook.getChapterUrl());
return;
}
mCharset = mCollBook.getInfoUrl();
// 判断文件是否已经加载过,并具有缓存
@ -113,7 +116,7 @@ public class LocalPageLoader extends PageLoader {
@Override
public void onError(Throwable e) {
chapterError(e.getLocalizedMessage());
error(STATUS_CATEGORY_ERROR, e.getLocalizedMessage());
Log.d(TAG, "file load error:" + e.toString());
}
});
@ -366,7 +369,6 @@ public class LocalPageLoader extends PageLoader {
}
@Override
protected BufferedReader getChapterReader(Chapter chapter) throws Exception {
if (chapter.getEnd() > 0) {

@ -70,6 +70,7 @@ public class NetPageLoader extends PageLoader {
chapter.setId(StringHelper.getStringRandom(25));
chapter.setBookId(mCollBook.getId());
}
mChapterService.addChapters(newChapters);
emitter.onNext(newChapters);
}))
.compose(RxUtils::toSimpleSingle)
@ -94,7 +95,7 @@ public class NetPageLoader extends PageLoader {
@Override
public void onError(Throwable e) {
chapterError(e.getLocalizedMessage());
error(STATUS_CATEGORY_ERROR, e.getLocalizedMessage());
Log.d(TAG, "file load error:" + e.toString());
}
});

@ -32,6 +32,7 @@ import xyz.fycz.myreader.model.audio.ReadAloudService;
import xyz.fycz.myreader.util.IOUtils;
import xyz.fycz.myreader.util.ToastUtils;
import xyz.fycz.myreader.util.help.ChapterContentHelp;
import xyz.fycz.myreader.util.help.StringHelper;
import xyz.fycz.myreader.util.utils.BitmapUtil;
import xyz.fycz.myreader.util.utils.MeUtils;
import xyz.fycz.myreader.util.utils.RxUtils;
@ -62,6 +63,7 @@ public abstract class PageLoader {
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 STATUS_CATEGORY_ERROR = 9; // 获取目录失败
private String errorMsg = "";
// 默认的显示参数配置
@ -780,8 +782,12 @@ public abstract class PageLoader {
}
public void chapterError(String msg) {
error(STATUS_ERROR, msg);
}
public void error(int status, String msg){
//加载错误
mStatus = STATUS_ERROR;
mStatus = status;
errorMsg = msg;
mPageView.drawCurPage(false);
}
@ -1046,8 +1052,11 @@ public abstract class PageLoader {
case STATUS_CATEGORY_EMPTY:
tip = "目录列表为空";
break;
case STATUS_CATEGORY_ERROR:
tip = "目录加载失败\n" + errorMsg;
break;
}
if (mStatus == STATUS_ERROR) {
if (mStatus == STATUS_ERROR || mStatus == STATUS_CATEGORY_ERROR) {
drawErrorMsg(canvas, tip, 0);
} else {
//将提示语句放到正中间

Loading…
Cancel
Save