优化
This commit is contained in:
@@ -346,7 +346,7 @@ fun Book.getExportFileName(
|
|||||||
fun Book.simulatedTotalChapterNum(): Int {
|
fun Book.simulatedTotalChapterNum(): Int {
|
||||||
return if (readSimulating()) {
|
return if (readSimulating()) {
|
||||||
val currentDate = LocalDate.now()
|
val currentDate = LocalDate.now()
|
||||||
val daysPassed = between(this.config.startDate, currentDate).days + 1
|
val daysPassed = between(config.startDate, currentDate).days + 1
|
||||||
// 计算当前应该解锁到哪一章
|
// 计算当前应该解锁到哪一章
|
||||||
val chaptersToUnlock =
|
val chaptersToUnlock =
|
||||||
max(0, (config.startChapter ?: 0) + (daysPassed * config.dailyChapters))
|
max(0, (config.startChapter ?: 0) + (daysPassed * config.dailyChapters))
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import io.legado.app.utils.postEvent
|
|||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
@@ -149,7 +150,7 @@ object BookHelp {
|
|||||||
book.getFolderName(),
|
book.getFolderName(),
|
||||||
cacheImageFolderName
|
cacheImageFolderName
|
||||||
).listFiles()?.forEach { imgFile ->
|
).listFiles()?.forEach { imgFile ->
|
||||||
if (!imgNames.contains(imgFile.name)){
|
if (!imgNames.contains(imgFile.name)) {
|
||||||
imgFile.delete()
|
imgFile.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,6 +192,17 @@ object BookHelp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun flowImages(bookChapter: BookChapter, content: String): Flow<String> {
|
||||||
|
return flow {
|
||||||
|
val matcher = AppPattern.imgPattern.matcher(content)
|
||||||
|
while (matcher.find()) {
|
||||||
|
val src = matcher.group(1) ?: continue
|
||||||
|
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
|
||||||
|
emit(mSrc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun saveImages(
|
suspend fun saveImages(
|
||||||
bookSource: BookSource,
|
bookSource: BookSource,
|
||||||
book: Book,
|
book: Book,
|
||||||
@@ -198,14 +210,7 @@ object BookHelp {
|
|||||||
content: String,
|
content: String,
|
||||||
concurrency: Int = AppConfig.threadCount
|
concurrency: Int = AppConfig.threadCount
|
||||||
) = coroutineScope {
|
) = coroutineScope {
|
||||||
flow {
|
flowImages(bookChapter, content).onEachParallel(concurrency) { mSrc ->
|
||||||
val matcher = AppPattern.imgPattern.matcher(content)
|
|
||||||
while (matcher.find()) {
|
|
||||||
val src = matcher.group(1) ?: continue
|
|
||||||
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
|
|
||||||
emit(mSrc)
|
|
||||||
}
|
|
||||||
}.onEachParallel(concurrency) { mSrc ->
|
|
||||||
saveImage(bookSource, book, mSrc, bookChapter)
|
saveImage(bookSource, book, mSrc, bookChapter)
|
||||||
}.collect()
|
}.collect()
|
||||||
}
|
}
|
||||||
@@ -329,8 +334,8 @@ object BookHelp {
|
|||||||
* 检测该章节是否下载
|
* 检测该章节是否下载
|
||||||
*/
|
*/
|
||||||
fun hasContent(book: Book, bookChapter: BookChapter): Boolean {
|
fun hasContent(book: Book, bookChapter: BookChapter): Boolean {
|
||||||
return if (book.isLocalTxt
|
return if (book.isLocalTxt ||
|
||||||
|| (bookChapter.isVolume && bookChapter.url.startsWith(bookChapter.title))
|
(bookChapter.isVolume && bookChapter.url.startsWith(bookChapter.title))
|
||||||
) {
|
) {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package io.legado.app.model
|
package io.legado.app.model
|
||||||
|
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.constant.AppPattern
|
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.data.entities.BookChapter
|
import io.legado.app.data.entities.BookChapter
|
||||||
@@ -26,7 +25,6 @@ import io.legado.app.ui.book.manga.entities.MangaChapter
|
|||||||
import io.legado.app.ui.book.manga.entities.MangaContent
|
import io.legado.app.ui.book.manga.entities.MangaContent
|
||||||
import io.legado.app.ui.book.manga.entities.MangaContentData
|
import io.legado.app.ui.book.manga.entities.MangaContentData
|
||||||
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
import io.legado.app.ui.book.manga.entities.ReaderLoading
|
||||||
import io.legado.app.utils.NetworkUtils
|
|
||||||
import io.legado.app.utils.mapIndexed
|
import io.legado.app.utils.mapIndexed
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.CoroutineStart
|
import kotlinx.coroutines.CoroutineStart
|
||||||
@@ -38,7 +36,6 @@ import kotlinx.coroutines.cancelChildren
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
import kotlinx.coroutines.flow.toList
|
import kotlinx.coroutines.flow.toList
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Semaphore
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
@@ -431,7 +428,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
(downloadFailChapters[chapter.index] ?: 0) + 1
|
(downloadFailChapters[chapter.index] ?: 0) + 1
|
||||||
contentLoadFinish(chapter, null)
|
contentLoadFinish(chapter, null)
|
||||||
}, cancel = {
|
}, cancel = {
|
||||||
contentLoadFinish(chapter, null, canceled = true)
|
contentLoadFinish(chapter, null, canceled = true)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
contentLoadFinish(chapter, null, "加载内容失败 没有书源")
|
contentLoadFinish(chapter, null, "加载内容失败 没有书源")
|
||||||
@@ -562,22 +559,16 @@ object ReadManga : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun getManageChapter(chapter: BookChapter, content: String): MangaChapter {
|
private suspend fun getManageChapter(chapter: BookChapter, content: String): MangaChapter {
|
||||||
val list = flow {
|
val list = BookHelp.flowImages(chapter, content)
|
||||||
val matcher = AppPattern.imgPattern.matcher(content)
|
.distinctUntilChanged().mapIndexed { index, src ->
|
||||||
while (matcher.find()) {
|
MangaContent(
|
||||||
val src = matcher.group(1) ?: continue
|
mChapterIndex = chapter.index,
|
||||||
val mSrc = NetworkUtils.getAbsoluteURL(chapter.url, src)
|
chapterSize = chapterSize,
|
||||||
emit(mSrc)
|
mImageUrl = src,
|
||||||
}
|
index = index,
|
||||||
}.distinctUntilChanged().mapIndexed { index, src ->
|
mChapterName = chapter.title
|
||||||
MangaContent(
|
)
|
||||||
mChapterIndex = chapter.index,
|
}.toList()
|
||||||
chapterSize = chapterSize,
|
|
||||||
mImageUrl = src,
|
|
||||||
index = index,
|
|
||||||
mChapterName = chapter.title
|
|
||||||
)
|
|
||||||
}.toList()
|
|
||||||
|
|
||||||
val imageCount = list.size
|
val imageCount = list.size
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package io.legado.app.ui.book.manga.entities
|
package io.legado.app.ui.book.manga.entities
|
||||||
|
|
||||||
data class MangaContent(
|
data class MangaContent(
|
||||||
var mChapterIndex: Int = 0,//总章节位置
|
val mChapterIndex: Int = 0,//总章节位置
|
||||||
var chapterSize: Int,//总章节数量
|
val chapterSize: Int,//总章节数量
|
||||||
val mImageUrl: String = "",//当前URL
|
val mImageUrl: String = "",//当前URL
|
||||||
var index: Int = 0,//当前章节位置
|
val index: Int = 0,//当前章节位置
|
||||||
var imageCount: Int = 0,//当前章节内容总数
|
var imageCount: Int = 0,//当前章节内容总数
|
||||||
var mChapterName: String = "",//章节名称
|
val mChapterName: String = "",//章节名称
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user