From 6ffb08dc4fa99c85d59f1e2008baf97f4cf4d542 Mon Sep 17 00:00:00 2001 From: ocean <503259349@qq.com> Date: Thu, 9 Oct 2025 17:34:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=88=E5=B9=B6=E7=9A=84?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E5=B1=95=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../all/pdfreader/pro/app/util/PdfUtils.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/all/pdfreader/pro/app/util/PdfUtils.kt b/app/src/main/java/com/all/pdfreader/pro/app/util/PdfUtils.kt index 1c37798..688860a 100644 --- a/app/src/main/java/com/all/pdfreader/pro/app/util/PdfUtils.kt +++ b/app/src/main/java/com/all/pdfreader/pro/app/util/PdfUtils.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File import java.io.FileOutputStream @@ -173,16 +174,34 @@ object PdfUtils { try { val merger = PDFMergerUtility() + val total = 100 + + // 加载文件 0~30% inputFiles.forEachIndexed { index, file -> merger.addSource(file) - onProgress?.invoke(index + 1, inputFiles.size) - delay(100) + val progress = ((index + 1).toFloat() / inputFiles.size * 30).toInt() + onProgress?.invoke(progress, total) + delay(50) } merger.destinationFileName = outputFile.absolutePath + // 伪进度(30%~95%) + var fakeProgress = 30 + val fakeJob = launch { + while (fakeProgress < 95) { + fakeProgress += (1..3).random() // 每次前进一点点 + if (fakeProgress > 95) fakeProgress = 95 + onProgress?.invoke(fakeProgress, total) + delay((100L..300L).random()) // 模拟不均匀的进度 + } + } + merger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly()) + fakeJob.cancel() + onProgress?.invoke(100, total) + outputFile } catch (e: Exception) { e.printStackTrace()