From 6db2f2f390372831b39f3cde00d784c7768f8c87 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Jan 2022 23:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/association/FileAssociationActivity.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index fafe2b2a9..8ee117e3f 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -105,27 +105,19 @@ class FileAssociationActivity : val bookDoc = DocumentFile.fromSingleUri(this@FileAssociationActivity, uri) withContext(IO) { val name = bookDoc?.name!! - val doc = treeDoc!!.findFile(name) - if (doc != null) { - if (bookDoc.lastModified() > doc.lastModified()) { - contentResolver.openOutputStream(doc.uri)!!.use { oStream -> - contentResolver.openInputStream(bookDoc.uri)!!.use { iStream -> - iStream.copyTo(oStream) - oStream.flush() - } - } + var doc = treeDoc!!.findFile(name) + if (doc == null || bookDoc.lastModified() > doc.lastModified()) { + if (doc == null) { + doc = treeDoc.createFile(FileUtils.getMimeType(name), name)!! } - viewModel.importBook(doc.uri) - } else { - val nDoc = treeDoc.createFile(FileUtils.getMimeType(name), name)!! - contentResolver.openOutputStream(nDoc.uri)!!.use { oStream -> + contentResolver.openOutputStream(doc.uri)!!.use { oStream -> contentResolver.openInputStream(bookDoc.uri)!!.use { iStream -> iStream.copyTo(oStream) oStream.flush() } } - viewModel.importBook(nDoc.uri) } + viewModel.importBook(doc.uri) } } else { val treeFile = File(treeUri.path!!)