显示换源进度 (#4893)
Some checks are pending
Test Build / prepare (push) Waiting to run
Test Build / build (app, release) (push) Blocked by required conditions
Test Build / build (app, releaseA) (push) Blocked by required conditions
Test Build / prerelease (push) Blocked by required conditions
Test Build / lanzou (push) Blocked by required conditions
Test Build / test_Branch (push) Blocked by required conditions
Test Build / telegram (push) Blocked by required conditions

* change source progress

* format,隐藏初始状态

* resolve PR comment

* resolve PR comment1

* resolve PR comment2
This commit is contained in:
Jason Yao
2025-03-31 17:04:42 -07:00
committed by GitHub
parent da859ad181
commit 3ad189b9ef
10 changed files with 47 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
/**
@@ -235,6 +236,26 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
}
}
}
lifecycleScope.launch {
repeatOnLifecycle(STARTED) {
viewModel.finishedChangeSourceResult
.drop(1)
.collect { (count, name) ->
binding.tvDur.text =
getString(
R.string.change_source_progress,
adapter.itemCount,
count,
viewModel.totalSourceCount,
name
)
delay(500)
}
}
}
lifecycleScope.launch {
appDb.bookSourceDao.flowEnabledGroups().conflate().collect {
groups.clear()

View File

@@ -26,6 +26,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.internString
import io.legado.app.utils.mapParallelSafe
import io.legado.app.utils.onEachIndexed
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers.IO
@@ -35,6 +36,8 @@ import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
@@ -43,6 +46,7 @@ import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
import java.util.Collections
@@ -62,9 +66,13 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
private var oldBook: Book? = null
private var screenKey: String = ""
private var bookSourceParts = arrayListOf<BookSourcePart>()
val totalSourceCount:Int
get() = bookSourceParts.size
private var searchBookList = arrayListOf<SearchBook>()
private val searchBooks = Collections.synchronizedList(arrayListOf<SearchBook>())
private val tocMap = ConcurrentHashMap<String, List<BookChapter>>()
private val _finishedChangeSourceResult = MutableStateFlow(0 to "")
val finishedChangeSourceResult= _finishedChangeSourceResult.asStateFlow()
private var tocMapChapterCount = 0
private val contentProcessor by lazy {
ContentProcessor.get(oldBook!!)
@@ -181,6 +189,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
tocMap.clear()
bookMap.clear()
tocMapChapterCount = 0
_finishedChangeSourceResult.value = 0 to ""
val searchGroup = AppConfig.searchGroup
if (searchGroup.isBlank()) {
bookSourceParts.addAll(appDb.bookSourceDao.allEnabledPart)
@@ -223,8 +232,15 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
}.onStart {
searchStateData.postValue(true)
}.mapParallelSafe(threadCount) {
withTimeout(60000L) {
search(it)
runCatching {
withTimeout(60000L) {
search(it)
}
}
it
}.onEachIndexed { index, value ->
_finishedChangeSourceResult.update { _ ->
index + 1 to value.bookSourceName
}
}.onCompletion {
searchStateData.postValue(false)

View File

@@ -1137,6 +1137,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">结果 %1$d, 当前进度 %2$d / %3$d: %4$s</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="default_home_page">默认主页</string>

View File

@@ -1140,6 +1140,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">結果 %1$d、現在の進行状況 %2$d / %3$d: %4$s</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="default_home_page">默认主页</string>

View File

@@ -1140,6 +1140,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">" Resultado %1$d, progresso atual %2$d / %3$d: %4$s"</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="default_home_page">默认主页</string>

View File

@@ -1136,6 +1136,7 @@ Còn </string>
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">Kết quả %1$d, tiến trình hiện tại %2$d / %3$d: %4$s</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="sync_book_progress_success">" Đồng bộ hóa tiến trình thành công"</string>

View File

@@ -1137,6 +1137,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">" 結果 %1$d, 當前進度 %2$d / %3$d: %4$s"</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="sync_book_progress_success">進度同步成功</string>

View File

@@ -1139,6 +1139,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">" 結果 %1$d, 當前進度 %2$d / %3$d: %4$s"</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="sync_book_progress_success">進度同步成功</string>

View File

@@ -1139,6 +1139,7 @@
<string name="export_book_notification_content">正在导出(%1$s),还有%2$d本待导出</string>
<string name="export_md">导出(MD)</string>
<string name="change_source_delay">换源间隔</string>
<string name="change_source_progress">结果 %1$d, 当前进度 %2$d / %3$d: %4$s</string>
<string name="open_book_info_by_click_title">点击书名打开详情</string>
<string name="export_wait">等待导出</string>
<string name="sync_book_progress_success">进度同步成功</string>

View File

@@ -1142,6 +1142,7 @@
<string name="export_book_notification_content">Exporting (%1$s), with %2$d to be exported.</string>
<string name="export_md">Export(MD)</string>
<string name="change_source_delay">Change source delay</string>
<string name="change_source_progress">Result %1$d, Progress %2$d / %3$d: %4$s</string>
<string name="open_book_info_by_click_title">Click on the book title to open details</string>
<string name="export_wait">Waiting for export</string>
<string name="show_bookshelf_fast_scroller">Show quick scroll bar</string>