diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml deleted file mode 100644 index ca8bf99..0000000 --- a/.idea/assetWizardSettings.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 731bba8..61a9130 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,8 +1,6 @@ - - - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index bf2bb41..eb20a8e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,7 +4,7 @@ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6560a98..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator-enh.xml b/.idea/markdown-navigator-enh.xml deleted file mode 100644 index a8fcc84..0000000 --- a/.idea/markdown-navigator-enh.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml deleted file mode 100644 index a2fc086..0000000 --- a/.idea/markdown-navigator.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 58918f5..52c80b4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,17 @@ - + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/src/main/assets/updatelog.fy b/app/src/main/assets/updatelog.fy index f108f6b..255be57 100644 --- a/app/src/main/assets/updatelog.fy +++ b/app/src/main/assets/updatelog.fy @@ -1,3 +1,9 @@ +2021.08.10 +风月读书v2.1.7 +更新内容: +1、修复发现分类bug +2、新增章节内容智能分段 + 2021.07.24 风月读书v2.1.6 更新内容: diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java index 27802a5..d60583d 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MoreSettingActivity.java @@ -70,6 +70,7 @@ public class MoreSettingActivity extends BaseActivity { private boolean noMenuTitle; private boolean readAloudVolumeTurnPage; private boolean enType; + private boolean reSeg; private ArrayList mBooks; int booksCount; @@ -114,6 +115,7 @@ public class MoreSettingActivity extends BaseActivity { noMenuTitle = mSetting.isNoMenuChTitle(); readAloudVolumeTurnPage = mSetting.isReadAloudVolumeTurnPage(); enType = mSetting.isEnType(); + reSeg = mSetting.isLightNovelParagraph(); threadNum = SharedPreUtils.getInstance().getInt(getString(R.string.threadNum), 8); isWebDav = getIntent().getBooleanExtra(APPCONST.WEB_DAV, false); } @@ -198,6 +200,7 @@ public class MoreSettingActivity extends BaseActivity { binding.scLongPress.setChecked(isLongPress); binding.scNoMenuTitle.setChecked(noMenuTitle); binding.scAdaptEnType.setChecked(enType); + binding.scReSeg.setChecked(reSeg); binding.scReadAloudVolumeTurnPage.setChecked(readAloudVolumeTurnPage); } @@ -281,6 +284,14 @@ public class MoreSettingActivity extends BaseActivity { } ); + binding.rlReSeg.setOnClickListener(v -> { + needRefresh = true; + reSeg = !reSeg; + binding.scReSeg.setChecked(reSeg); + mSetting.setLightNovelParagraph(reSeg); + SysManager.saveSetting(mSetting); + }); + binding.llBookSort.setOnClickListener(v -> { /*MyAlertDialog.build(this) .setTitle(getString(R.string.book_sort)) 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 5b854d8..fcbdcff 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 @@ -1937,7 +1937,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe ReplaceRuleBean oldRuleBean = new ReplaceRuleBean(); oldRuleBean.setReplaceSummary(""); oldRuleBean.setEnable(true); - oldRuleBean.setRegex(binding.readPvContent.getSelectStr().trim()); + oldRuleBean.setRegex(binding.readPvContent.getSelectStr()); oldRuleBean.setIsRegex(false); oldRuleBean.setReplacement(""); oldRuleBean.setSerialNumber(0); diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java index e191663..f560519 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/EpubPageLoader.java @@ -279,12 +279,13 @@ public class EpubPageLoader extends PageLoader { } @Override - protected BufferedReader getChapterReader(Chapter chapter) throws Exception { + protected String getChapterReader(Chapter chapter) throws Exception { Log.d("getChapterReader", chapter.getTitle()); - byte[] content = getChapterContent(chapter).getBytes(); + /*byte[] content = getChapterContent(chapter).getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(content); BufferedReader br = new BufferedReader(new InputStreamReader(bais)); - return br; + return br;*/ + return getChapterContent(chapter); } @Override diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java index 2279cf4..c45bf7d 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/LocalPageLoader.java @@ -370,20 +370,23 @@ public class LocalPageLoader extends PageLoader { @Override - protected BufferedReader getChapterReader(Chapter chapter) throws Exception { + protected String getChapterReader(Chapter chapter) throws Exception { if (chapter.getEnd() > 0) { Log.d("getChapterReader", chapter.getTitle()); //从文件中获取数据 - byte[] content = getContent(chapter); + /*byte[] content = getContent(chapter); ByteArrayInputStream bais = new ByteArrayInputStream(content); BufferedReader br = new BufferedReader(new InputStreamReader(bais, mCharset)); - return br; + return br;*/ + byte[] content = getContent(chapter); + return new String(content, mCharset); } - File file = new File(APPCONST.BOOK_CACHE_PATH + mCollBook.getId() + /*File file = new File(APPCONST.BOOK_CACHE_PATH + mCollBook.getId() + File.separator + chapter.getTitle() + FileUtils.SUFFIX_FY); - if (!file.exists()) return null; Log.d("getChapterReader", file.getPath()); - return new BufferedReader(new FileReader(file)); + if (!file.exists()) return null; + return new BufferedReader(new FileReader(file));*/ + return mChapterService.getChapterCatheContent(chapter); } diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java index 03f4f47..c7723b4 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/NetPageLoader.java @@ -102,12 +102,13 @@ public class NetPageLoader extends PageLoader { } @Override - protected BufferedReader getChapterReader(Chapter chapter) throws FileNotFoundException { - File file = new File(APPCONST.BOOK_CACHE_PATH + mCollBook.getId() + protected String getChapterReader(Chapter chapter) throws FileNotFoundException { + /*File file = new File(APPCONST.BOOK_CACHE_PATH + mCollBook.getId() + File.separator + chapter.getTitle() + FileUtils.SUFFIX_FY); if (!file.exists()) return null; BufferedReader br = new BufferedReader(new FileReader(file)); - return br; + return br;*/ + return mChapterService.getChapterCatheContent(chapter); } @Override diff --git a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java index fd2f0e9..79e0e05 100644 --- a/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java +++ b/app/src/main/java/xyz/fycz/myreader/widget/page/PageLoader.java @@ -847,7 +847,7 @@ public abstract class PageLoader { return null; } // 获取章节的文本流 - BufferedReader reader = getChapterReader(chapter); + String reader = getChapterReader(chapter); TxtChapter txtChapter = loadPages(chapter, reader); return txtChapter; @@ -862,12 +862,12 @@ public abstract class PageLoader { public abstract void refreshChapterList(); /** - * 获取章节的文本流 + * 获取章节的文本 * * @param chapter * @return */ - protected abstract BufferedReader getChapterReader(Chapter chapter) throws Exception; + protected abstract String getChapterReader(Chapter chapter) throws Exception; /** * 章节数据是否存在 @@ -1665,11 +1665,16 @@ public abstract class PageLoader { * 将章节数据,解析成页面列表 * * @param chapter:章节信息 - * @param br:章节的文本流 + * @param content:章节的文本流 * @return */ - private TxtChapter loadPages(Chapter chapter, BufferedReader br) { + private TxtChapter loadPages(Chapter chapter, String content) { TxtChapter txtChapter = new TxtChapter(chapter.getNumber()); + + content = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), content, true); + content = contentHelper.LightNovelParagraph2(content, chapter.getTitle()); + String[] allLine = content.split("\n"); + //使用流的方式加载 List lines = new ArrayList<>(); List txtLists = new ArrayList<>();//记录每个字的位置 //pzl @@ -1677,147 +1682,144 @@ public abstract class PageLoader { int titleLinesCount = 0; boolean showTitle = true; // 是否展示标题 boolean firstLine = true; - String paragraph = chapter.getTitle();//默认展示标题 + String paragraph = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), chapter.getTitle(), true);//默认展示标题 paragraph = paragraph.trim() + "\n"; - try { - while (showTitle || (paragraph = br.readLine()) != null) { - paragraph = contentHelper.replaceContent(mCollBook.getName() + "-" + mCollBook.getAuthor(), mCollBook.getSource(), paragraph, true); - if (firstLine && !showTitle) { - paragraph = paragraph.replace(chapter.getTitle(), ""); - firstLine = false; + int i = 1; + while (showTitle || i < allLine.length) { + if (firstLine && !showTitle) { + paragraph = paragraph.replace(chapter.getTitle(), ""); + firstLine = false; + } + // 重置段落 + if (!showTitle) { + paragraph = allLine[i]; + if (mSettingManager.isEnType()) { + paragraph = StringUtils.trim(paragraph.replace("\t", "")); + } else { + paragraph = paragraph.replaceAll("\\s", ""); } - // 重置段落 - if (!showTitle) { - if (mSettingManager.isEnType()) { - paragraph = StringUtils.trim(paragraph.replace("\t", "")); - } else { - paragraph = paragraph.replaceAll("\\s", ""); - } - // 如果只有换行符,那么就不执行 - if (paragraph.equals("")) continue; - paragraph = indent + paragraph + "\n"; + i++; + // 如果只有换行符,那么就不执行 + if (paragraph.equals("")) continue; + paragraph = indent + paragraph + "\n"; + } else { + //设置 title 的顶部间距 + rHeight -= mTitlePara; + } + addParagraphLength(txtChapter, paragraph.length()); + int wordCount = 0; + String subStr = null; + while (paragraph.length() > 0) { + //当前空间,是否容得下一行文字 + if (showTitle) { + rHeight -= mTitlePaint.getTextSize(); } else { - //设置 title 的顶部间距 - rHeight -= mTitlePara; + rHeight -= mTextPaint.getTextSize(); } - addParagraphLength(txtChapter, paragraph.length()); - int wordCount = 0; - String subStr = null; - while (paragraph.length() > 0) { - //当前空间,是否容得下一行文字 + // 一页已经填充满了,创建 TextPage + if (rHeight <= 0) { + // 创建Page + TxtPage page = new TxtPage(); + page.position = txtChapter.getTxtPageList().size(); + page.title = chapter.getTitle(); + page.lines = new ArrayList<>(lines); + page.txtLists = new ArrayList<>(txtLists); + page.titleLines = titleLinesCount; + txtChapter.addPage(page); + addTxtPageLength(txtChapter, page.getContent().length()); + // 重置Lines + lines.clear(); + txtLists.clear();//pzl + rHeight = mVisibleHeight; + titleLinesCount = 0; + continue; + } + + //测量一行占用的字节数 + if (mSettingManager.isTightCom()) { if (showTitle) { - rHeight -= mTitlePaint.getTextSize(); + wordCount = mTitlePaint.breakText(paragraph, + true, mVisibleWidth, null); } else { - rHeight -= mTextPaint.getTextSize(); - } - // 一页已经填充满了,创建 TextPage - if (rHeight <= 0) { - // 创建Page - TxtPage page = new TxtPage(); - page.position = txtChapter.getTxtPageList().size(); - page.title = chapter.getTitle(); - page.lines = new ArrayList<>(lines); - page.txtLists = new ArrayList<>(txtLists); - page.titleLines = titleLinesCount; - txtChapter.addPage(page); - addTxtPageLength(txtChapter, page.getContent().length()); - // 重置Lines - lines.clear(); - txtLists.clear();//pzl - rHeight = mVisibleHeight; - titleLinesCount = 0; - continue; + wordCount = mTextPaint.breakText(paragraph, + true, mVisibleWidth, null); } - //测量一行占用的字节数 - if (mSettingManager.isTightCom()) { - if (showTitle) { - wordCount = mTitlePaint.breakText(paragraph, - true, mVisibleWidth, null); - } else { - wordCount = mTextPaint.breakText(paragraph, - true, mVisibleWidth, null); - } - - subStr = paragraph.substring(0, wordCount); - if (paragraph.substring(wordCount).equals("\n")) { - subStr += "\n"; - } + subStr = paragraph.substring(0, wordCount); + if (paragraph.substring(wordCount).equals("\n")) { + subStr += "\n"; + } + } else { + Layout tempLayout; + if (showTitle) { + tempLayout = new StaticLayout(paragraph, mTitlePaint, mVisibleWidth, Layout.Alignment.ALIGN_NORMAL, 0, 0, false); } else { - Layout tempLayout; - if (showTitle) { - tempLayout = new StaticLayout(paragraph, mTitlePaint, mVisibleWidth, Layout.Alignment.ALIGN_NORMAL, 0, 0, false); - } else { - tempLayout = new StaticLayout(paragraph, mTextPaint, mVisibleWidth, Layout.Alignment.ALIGN_NORMAL, 0, 0, false); - } - wordCount = tempLayout.getLineEnd(0); - subStr = paragraph.substring(0, wordCount); + tempLayout = new StaticLayout(paragraph, mTextPaint, mVisibleWidth, Layout.Alignment.ALIGN_NORMAL, 0, 0, false); } + wordCount = tempLayout.getLineEnd(0); + subStr = paragraph.substring(0, wordCount); + } - if (!subStr.equals("\n")) { - //将一行字节,存储到lines中 - lines.add(subStr); - //begin pzl - //记录每个字的位置 - char[] cs = subStr.replace((char) 12288, ' ').trim().toCharArray(); - TxtLine txtList = new TxtLine();//每一行 - txtList.setCharsData(new ArrayList<>()); - for (char c : cs) { - String mesasrustr = String.valueOf(c); - float charwidth = mTextPaint.measureText(mesasrustr); - if (showTitle) { - charwidth = mTitlePaint.measureText(mesasrustr); - } - TxtChar txtChar = new TxtChar(); - txtChar.setChardata(c); - txtChar.setCharWidth(charwidth);//字宽 - txtChar.setIndex(66);//每页每个字的位置 - txtList.getCharsData().add(txtChar); - } - txtLists.add(txtList); - //end pzl - //设置段落间距 + if (!subStr.equals("\n")) { + //将一行字节,存储到lines中 + lines.add(subStr); + //begin pzl + //记录每个字的位置 + char[] cs = subStr.replace((char) 12288, ' ').trim().toCharArray(); + TxtLine txtList = new TxtLine();//每一行 + txtList.setCharsData(new ArrayList<>()); + for (char c : cs) { + String mesasrustr = String.valueOf(c); + float charwidth = mTextPaint.measureText(mesasrustr); if (showTitle) { - titleLinesCount += 1; - rHeight -= mTitleInterval; - } else { - rHeight -= mTextInterval; + charwidth = mTitlePaint.measureText(mesasrustr); } + TxtChar txtChar = new TxtChar(); + txtChar.setChardata(c); + txtChar.setCharWidth(charwidth);//字宽 + txtChar.setIndex(66);//每页每个字的位置 + txtList.getCharsData().add(txtChar); + } + txtLists.add(txtList); + //end pzl + //设置段落间距 + if (showTitle) { + titleLinesCount += 1; + rHeight -= mTitleInterval; + } else { + rHeight -= mTextInterval; } - //裁剪 - paragraph = paragraph.substring(wordCount); - } - - //增加段落的间距 - if (!showTitle && lines.size() != 0) { - rHeight = rHeight - mTextPara + mTextInterval; } + //裁剪 + paragraph = paragraph.substring(wordCount); + } - if (showTitle) { - rHeight = rHeight - mTitlePara + mTitleInterval; - showTitle = false; - } + //增加段落的间距 + if (!showTitle && lines.size() != 0) { + rHeight = rHeight - mTextPara + mTextInterval; } - if (lines.size() != 0) { - //创建Page - TxtPage page = new TxtPage(); - page.position = txtChapter.getTxtPageList().size(); - page.title = chapter.getTitle(); - page.lines = new ArrayList<>(lines); - page.txtLists = new ArrayList<>(txtLists); - page.titleLines = titleLinesCount; - txtChapter.addPage(page); - addTxtPageLength(txtChapter, page.getContent().length()); - //重置Lines - lines.clear(); - txtLists.clear(); + if (showTitle) { + rHeight = rHeight - mTitlePara + mTitleInterval; + showTitle = false; } - } catch (IOException e) { - e.printStackTrace(); - } finally { - IOUtils.close(br); } + + if (lines.size() != 0) { + //创建Page + TxtPage page = new TxtPage(); + page.position = txtChapter.getTxtPageList().size(); + page.title = chapter.getTitle(); + page.lines = new ArrayList<>(lines); + page.txtLists = new ArrayList<>(txtLists); + page.titleLines = titleLinesCount; + txtChapter.addPage(page); + addTxtPageLength(txtChapter, page.getContent().length()); + //重置Lines + lines.clear(); + txtLists.clear(); + } + return txtChapter; } diff --git a/app/src/main/res/layout/activity_more_setting.xml b/app/src/main/res/layout/activity_more_setting.xml index d691866..44d6afd 100644 --- a/app/src/main/res/layout/activity_more_setting.xml +++ b/app/src/main/res/layout/activity_more_setting.xml @@ -296,6 +296,34 @@ android:clickable="false" android:longClickable="false" /> + + + + + + + + 联系作者 浏览器 添加网址 + 章节内容智能分段