From 3ad189b9ef84b057263f0fc3920c8c3ee3bda54b Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Mon, 31 Mar 2025 17:04:42 -0700 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=8D=A2=E6=BA=90=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=20(#4893)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * change source progress * format,隐藏初始状态 * resolve PR comment * resolve PR comment1 * resolve PR comment2 --- .../changesource/ChangeBookSourceDialog.kt | 21 +++++++++++++++++++ .../changesource/ChangeBookSourceViewModel.kt | 20 ++++++++++++++++-- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 89397a7af..18b773080 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index 499f81b60..85eb5dd27 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt @@ -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() + val totalSourceCount:Int + get() = bookSourceParts.size private var searchBookList = arrayListOf() private val searchBooks = Collections.synchronizedList(arrayListOf()) private val tocMap = ConcurrentHashMap>() + 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) diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 9f21ed9b9..11ee47f7f 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1137,6 +1137,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + 结果 %1$d, 当前进度 %2$d / %3$d: %4$s 点击书名打开详情 等待导出 默认主页 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 34ae5868d..7034b8357 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1140,6 +1140,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + 結果 %1$d、現在の進行状況 %2$d / %3$d: %4$s 点击书名打开详情 等待导出 默认主页 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index c24253951..41e8b0332 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1140,6 +1140,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + " Resultado %1$d, progresso atual %2$d / %3$d: %4$s" 点击书名打开详情 等待导出 默认主页 diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index fe4f4ec65..107051a80 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -1136,6 +1136,7 @@ Còn 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + Kết quả %1$d, tiến trình hiện tại %2$d / %3$d: %4$s 点击书名打开详情 等待导出 " Đồng bộ hóa tiến trình thành công" diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 9c51be61d..fbdaf3635 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1137,6 +1137,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + " 結果 %1$d, 當前進度 %2$d / %3$d: %4$s" 点击书名打开详情 等待导出 進度同步成功 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 626785d4e..9f35179ce 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1139,6 +1139,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + " 結果 %1$d, 當前進度 %2$d / %3$d: %4$s" 点击书名打开详情 等待导出 進度同步成功 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index aeeeb598c..c8fce01b0 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1139,6 +1139,7 @@ 正在导出(%1$s),还有%2$d本待导出 导出(MD) 换源间隔 + 结果 %1$d, 当前进度 %2$d / %3$d: %4$s 点击书名打开详情 等待导出 进度同步成功 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4b1130462..107fd8481 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1142,6 +1142,7 @@ Exporting (%1$s), with %2$d to be exported. Export(MD) Change source delay + Result %1$d, Progress %2$d / %3$d: %4$s Click on the book title to open details Waiting for export Show quick scroll bar