@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
* 校验失效分组具体到搜索发现目录正文
|
* 校验失效分组具体到搜索发现目录正文
|
||||||
* txt文件初次解析目录不选择禁用的正则
|
* txt文件初次解析目录不选择禁用的正则
|
||||||
* txt单章字数超102400均分txt
|
* txt单章字数超102400均分txt,添加开关
|
||||||
* 修复tts被回收后无法继续朗读的bug,重新初始化tts
|
* 修复tts被回收后无法继续朗读的bug,重新初始化tts
|
||||||
|
|
||||||
**2022/02/03**
|
**2022/02/03**
|
||||||
|
|||||||
@@ -160,6 +160,14 @@ data class Book(
|
|||||||
config().reSegment = reSegment
|
config().reSegment = reSegment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getLimitContentLength(): Boolean {
|
||||||
|
return config().limitContentLength
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setLimitContentLength(limitContentLength: Boolean) {
|
||||||
|
config().limitContentLength = limitContentLength
|
||||||
|
}
|
||||||
|
|
||||||
fun getPageAnim(): Int {
|
fun getPageAnim(): Int {
|
||||||
return config().pageAnim
|
return config().pageAnim
|
||||||
}
|
}
|
||||||
@@ -270,6 +278,7 @@ data class Book(
|
|||||||
var reverseToc: Boolean = false,
|
var reverseToc: Boolean = false,
|
||||||
var pageAnim: Int = -1,
|
var pageAnim: Int = -1,
|
||||||
var reSegment: Boolean = false,
|
var reSegment: Boolean = false,
|
||||||
|
var limitContentLength: Boolean = true, //txt规则解析目录时超过规定的最大字数时均分txt
|
||||||
var imageStyle: String? = null,
|
var imageStyle: String? = null,
|
||||||
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
|
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
|
||||||
var delTag: Long = 0L,//去除标签
|
var delTag: Long = 0L,//去除标签
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
var book: Book? = null
|
var book: Book? = null
|
||||||
var callBack: CallBack? = null
|
var callBack: CallBack? = null
|
||||||
var inBookshelf = false
|
var inBookshelf = false
|
||||||
|
var tocChanged = false
|
||||||
var chapterSize = 0
|
var chapterSize = 0
|
||||||
var durChapterIndex = 0
|
var durChapterIndex = 0
|
||||||
var durChapterPos = 0
|
var durChapterPos = 0
|
||||||
@@ -65,7 +66,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
fun upData(book: Book) {
|
fun upData(book: Book) {
|
||||||
ReadBook.book = book
|
ReadBook.book = book
|
||||||
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||||
if (durChapterIndex != book.durChapterIndex) {
|
if (durChapterIndex != book.durChapterIndex || tocChanged) {
|
||||||
durChapterIndex = book.durChapterIndex
|
durChapterIndex = book.durChapterIndex
|
||||||
durChapterPos = book.durChapterPos
|
durChapterPos = book.durChapterPos
|
||||||
clearTextChapter()
|
clearTextChapter()
|
||||||
|
|||||||
@@ -128,9 +128,9 @@ object LocalBook {
|
|||||||
val m1 = Pattern
|
val m1 = Pattern
|
||||||
.compile("(.*?)《([^《》]+)》(.*)")
|
.compile("(.*?)《([^《》]+)》(.*)")
|
||||||
.matcher(tempFileName)
|
.matcher(tempFileName)
|
||||||
//匹配 书名 by 作者名.txt
|
//匹配 书名 作者:作者名.txt
|
||||||
val m2 = Pattern
|
val m2 = Pattern
|
||||||
.compile("(^)(.+) by (.+)$")
|
.compile("(^)(.+) 作者:(.+)$")
|
||||||
.matcher(tempFileName)
|
.matcher(tempFileName)
|
||||||
|
|
||||||
(m1.takeIf { m1.find() } ?: m2.takeIf { m2.find() }).run {
|
(m1.takeIf { m1.find() } ?: m2.takeIf { m2.find() }).run {
|
||||||
@@ -152,13 +152,13 @@ object LocalBook {
|
|||||||
name = bookMess["name"] ?: tempFileName
|
name = bookMess["name"] ?: tempFileName
|
||||||
author = bookMess["author"]?.takeIf { it.length != tempFileName.length } ?: ""
|
author = bookMess["author"]?.takeIf { it.length != tempFileName.length } ?: ""
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
name = tempFileName.replace(AppPattern.nameRegex, "")
|
name = BookHelp.formatBookName(tempFileName)
|
||||||
author = tempFileName.replace(AppPattern.authorRegex, "")
|
author = BookHelp.formatBookAuthor(tempFileName.replace(name, ""))
|
||||||
.takeIf { it.length != tempFileName.length } ?: ""
|
.takeIf { it.length != tempFileName.length } ?: ""
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = tempFileName.replace(AppPattern.nameRegex, "")
|
name = BookHelp.formatBookName(tempFileName)
|
||||||
author = tempFileName.replace(AppPattern.authorRegex, "")
|
author = BookHelp.formatBookAuthor(tempFileName.replace(name, ""))
|
||||||
.takeIf { it.length != tempFileName.length } ?: ""
|
.takeIf { it.length != tempFileName.length } ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class TextFile(private val book: Book) {
|
|||||||
private val maxLengthWithNoToc = 10 * 1024
|
private val maxLengthWithNoToc = 10 * 1024
|
||||||
//使用正则划分目录,每个章节的最大允许长度
|
//使用正则划分目录,每个章节的最大允许长度
|
||||||
private val maxLengthWithToc = 102400
|
private val maxLengthWithToc = 102400
|
||||||
|
private val limitContentLength = book.getLimitContentLength()
|
||||||
|
|
||||||
private val tocRules = arrayListOf<Pattern>()
|
private val tocRules = arrayListOf<Pattern>()
|
||||||
private var charset: Charset = book.fileCharset()
|
private var charset: Charset = book.fileCharset()
|
||||||
@@ -128,7 +129,7 @@ class TextFile(private val book: Book) {
|
|||||||
val chapterContent = blockContent.substring(seekPos, chapterStart)
|
val chapterContent = blockContent.substring(seekPos, chapterStart)
|
||||||
val chapterLength = chapterContent.toByteArray(charset).size
|
val chapterLength = chapterContent.toByteArray(charset).size
|
||||||
val lastStart = toc.lastOrNull()?.start ?: curOffset
|
val lastStart = toc.lastOrNull()?.start ?: curOffset
|
||||||
if (curOffset + chapterLength - lastStart > maxLengthWithToc) {
|
if (limitContentLength && curOffset + chapterLength - lastStart > maxLengthWithToc) {
|
||||||
bis.close()
|
bis.close()
|
||||||
return analyze()
|
return analyze()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class BookInfoActivity :
|
|||||||
viewModel.upEditBook()
|
viewModel.upEditBook()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private var tocChanged = false
|
||||||
|
|
||||||
override val binding by viewBinding(ActivityBookInfoBinding::inflate)
|
override val binding by viewBinding(ActivityBookInfoBinding::inflate)
|
||||||
override val viewModel by viewModels<BookInfoViewModel>()
|
override val viewModel by viewModels<BookInfoViewModel>()
|
||||||
@@ -118,12 +119,16 @@ class BookInfoActivity :
|
|||||||
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
|
||||||
menu.findItem(R.id.menu_can_update)?.isChecked =
|
menu.findItem(R.id.menu_can_update)?.isChecked =
|
||||||
viewModel.bookData.value?.canUpdate ?: true
|
viewModel.bookData.value?.canUpdate ?: true
|
||||||
|
menu.findItem(R.id.menu_limit_content_length)?.isChecked =
|
||||||
|
viewModel.bookData.value?.getLimitContentLength() ?: false
|
||||||
menu.findItem(R.id.menu_login)?.isVisible =
|
menu.findItem(R.id.menu_login)?.isVisible =
|
||||||
!viewModel.bookSource?.loginUrl.isNullOrBlank()
|
!viewModel.bookSource?.loginUrl.isNullOrBlank()
|
||||||
menu.findItem(R.id.menu_set_source_variable)?.isVisible =
|
menu.findItem(R.id.menu_set_source_variable)?.isVisible =
|
||||||
viewModel.bookSource != null
|
viewModel.bookSource != null
|
||||||
menu.findItem(R.id.menu_set_book_variable)?.isVisible =
|
menu.findItem(R.id.menu_set_book_variable)?.isVisible =
|
||||||
viewModel.bookSource != null
|
viewModel.bookSource != null
|
||||||
|
menu.findItem(R.id.menu_limit_content_length)?.isVisible =
|
||||||
|
viewModel.bookSource == null
|
||||||
return super.onMenuOpened(featureId, menu)
|
return super.onMenuOpened(featureId, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +188,15 @@ class BookInfoActivity :
|
|||||||
}
|
}
|
||||||
R.id.menu_clear_cache -> viewModel.clearCache()
|
R.id.menu_clear_cache -> viewModel.clearCache()
|
||||||
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
R.id.menu_log -> showDialogFragment<AppLogDialog>()
|
||||||
|
R.id.menu_limit_content_length -> {
|
||||||
|
upLoading(true)
|
||||||
|
tocChanged = true
|
||||||
|
viewModel.bookData.value?.let {
|
||||||
|
it.setLimitContentLength(!item.isChecked)
|
||||||
|
viewModel.loadBookInfo(it, false)
|
||||||
|
}
|
||||||
|
if (item.isChecked) longToastOnUi(R.string.need_more_time_load_content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onCompatOptionsItemSelected(item)
|
return super.onCompatOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
@@ -429,8 +443,10 @@ class BookInfoActivity :
|
|||||||
Intent(this, ReadBookActivity::class.java)
|
Intent(this, ReadBookActivity::class.java)
|
||||||
.putExtra("bookUrl", book.bookUrl)
|
.putExtra("bookUrl", book.bookUrl)
|
||||||
.putExtra("inBookshelf", viewModel.inBookshelf)
|
.putExtra("inBookshelf", viewModel.inBookshelf)
|
||||||
|
.putExtra("tocChanged", tocChanged)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
tocChanged = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override val oldBook: Book?
|
override val oldBook: Book?
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
if (book.isLocalBook()) {
|
if (book.isLocalBook()) {
|
||||||
LocalBook.getChapterList(book).let {
|
LocalBook.getChapterList(book).let {
|
||||||
appDb.bookDao.update(book)
|
appDb.bookDao.update(book)
|
||||||
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
||||||
appDb.bookChapterDao.insert(*it.toTypedArray())
|
appDb.bookChapterDao.insert(*it.toTypedArray())
|
||||||
chapterListData.postValue(it)
|
chapterListData.postValue(it)
|
||||||
}
|
}
|
||||||
@@ -127,6 +128,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
.onSuccess(IO) {
|
.onSuccess(IO) {
|
||||||
if (inBookshelf) {
|
if (inBookshelf) {
|
||||||
appDb.bookDao.update(book)
|
appDb.bookDao.update(book)
|
||||||
|
appDb.bookChapterDao.delByBook(book.bookUrl)
|
||||||
appDb.bookChapterDao.insert(*it.toTypedArray())
|
appDb.bookChapterDao.insert(*it.toTypedArray())
|
||||||
}
|
}
|
||||||
if (changeDruChapterIndex == null) {
|
if (changeDruChapterIndex == null) {
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
fun initData(intent: Intent) {
|
fun initData(intent: Intent) {
|
||||||
execute {
|
execute {
|
||||||
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
|
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
|
||||||
|
ReadBook.tocChanged = intent.getBooleanExtra("tocChanged", false)
|
||||||
val bookUrl = intent.getStringExtra("bookUrl")
|
val bookUrl = intent.getStringExtra("bookUrl")
|
||||||
val book = when {
|
val book = when {
|
||||||
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
|
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
|
||||||
|
|||||||
@@ -55,6 +55,12 @@
|
|||||||
android:checkable="true"
|
android:checkable="true"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_limit_content_length"
|
||||||
|
android:title="@string/limit_content_length"
|
||||||
|
android:checkable="true"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_clear_cache"
|
android:id="@+id/menu_clear_cache"
|
||||||
android:title="@string/clear_cache"
|
android:title="@string/clear_cache"
|
||||||
|
|||||||
@@ -332,6 +332,8 @@
|
|||||||
<string name="tip_margin_change">Ajuste de margen</string>
|
<string name="tip_margin_change">Ajuste de margen</string>
|
||||||
<string name="allow_update">Activar actualizaciones</string>
|
<string name="allow_update">Activar actualizaciones</string>
|
||||||
<string name="disable_update">Desactivar actualizaciones</string>
|
<string name="disable_update">Desactivar actualizaciones</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">Invertir</string>
|
<string name="revert_selection">Invertir</string>
|
||||||
<string name="search_book_key">Buscar libro por nombre o autor</string>
|
<string name="search_book_key">Buscar libro por nombre o autor</string>
|
||||||
<string name="debug_hint">Nombre del libro, autor, URL</string>
|
<string name="debug_hint">Nombre del libro, autor, URL</string>
|
||||||
|
|||||||
@@ -336,6 +336,8 @@
|
|||||||
<string name="tip_margin_change">Margin adjustment</string>
|
<string name="tip_margin_change">Margin adjustment</string>
|
||||||
<string name="allow_update">Enable update</string>
|
<string name="allow_update">Enable update</string>
|
||||||
<string name="disable_update">Disable update</string>
|
<string name="disable_update">Disable update</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">Inverse</string>
|
<string name="revert_selection">Inverse</string>
|
||||||
<string name="search_book_key">Search book name/author</string>
|
<string name="search_book_key">Search book name/author</string>
|
||||||
<string name="debug_hint">Book name,Author,URL</string>
|
<string name="debug_hint">Book name,Author,URL</string>
|
||||||
|
|||||||
@@ -333,6 +333,8 @@
|
|||||||
<string name="tip_margin_change">Tip 邊距跟隨邊距調整</string>
|
<string name="tip_margin_change">Tip 邊距跟隨邊距調整</string>
|
||||||
<string name="allow_update">允許更新</string>
|
<string name="allow_update">允許更新</string>
|
||||||
<string name="disable_update">禁止更新</string>
|
<string name="disable_update">禁止更新</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">反選</string>
|
<string name="revert_selection">反選</string>
|
||||||
<string name="search_book_key">搜索書名、作者</string>
|
<string name="search_book_key">搜索書名、作者</string>
|
||||||
<string name="debug_hint">書名、作者、URL</string>
|
<string name="debug_hint">書名、作者、URL</string>
|
||||||
|
|||||||
@@ -335,6 +335,8 @@
|
|||||||
<string name="tip_margin_change">Tip邊距跟隨邊距調整</string>
|
<string name="tip_margin_change">Tip邊距跟隨邊距調整</string>
|
||||||
<string name="allow_update">允許更新</string>
|
<string name="allow_update">允許更新</string>
|
||||||
<string name="disable_update">禁止更新</string>
|
<string name="disable_update">禁止更新</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">反選</string>
|
<string name="revert_selection">反選</string>
|
||||||
<string name="search_book_key">搜尋書名、作者</string>
|
<string name="search_book_key">搜尋書名、作者</string>
|
||||||
<string name="debug_hint">書名、作者、URL</string>
|
<string name="debug_hint">書名、作者、URL</string>
|
||||||
|
|||||||
@@ -335,6 +335,8 @@
|
|||||||
<string name="tip_margin_change">Tip边距跟随边距调整</string>
|
<string name="tip_margin_change">Tip边距跟随边距调整</string>
|
||||||
<string name="allow_update">允许更新</string>
|
<string name="allow_update">允许更新</string>
|
||||||
<string name="disable_update">禁止更新</string>
|
<string name="disable_update">禁止更新</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">反选</string>
|
<string name="revert_selection">反选</string>
|
||||||
<string name="search_book_key">搜索书名、作者</string>
|
<string name="search_book_key">搜索书名、作者</string>
|
||||||
<string name="debug_hint">书名、作者、URL</string>
|
<string name="debug_hint">书名、作者、URL</string>
|
||||||
|
|||||||
@@ -336,6 +336,8 @@
|
|||||||
<string name="tip_margin_change">Margin adjustment</string>
|
<string name="tip_margin_change">Margin adjustment</string>
|
||||||
<string name="allow_update">Enable update</string>
|
<string name="allow_update">Enable update</string>
|
||||||
<string name="disable_update">Disable update</string>
|
<string name="disable_update">Disable update</string>
|
||||||
|
<string name="limit_content_length">限制正文长度</string>
|
||||||
|
<string name="need_more_time_load_content">正文长度过长时,加载正文可能会花费更多时间</string>
|
||||||
<string name="revert_selection">Inverse</string>
|
<string name="revert_selection">Inverse</string>
|
||||||
<string name="search_book_key">Search book name/author</string>
|
<string name="search_book_key">Search book name/author</string>
|
||||||
<string name="debug_hint">Book name,Author,URL</string>
|
<string name="debug_hint">Book name,Author,URL</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user