pull/1514/head
gedoor 3 years ago
parent f0ee3e41ba
commit 6db2f2f390
  1. 18
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt

@ -105,9 +105,11 @@ 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()) {
var doc = treeDoc!!.findFile(name)
if (doc == null || bookDoc.lastModified() > doc.lastModified()) {
if (doc == null) {
doc = treeDoc.createFile(FileUtils.getMimeType(name), name)!!
}
contentResolver.openOutputStream(doc.uri)!!.use { oStream ->
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
iStream.copyTo(oStream)
@ -116,16 +118,6 @@ class FileAssociationActivity :
}
}
viewModel.importBook(doc.uri)
} else {
val nDoc = treeDoc.createFile(FileUtils.getMimeType(name), name)!!
contentResolver.openOutputStream(nDoc.uri)!!.use { oStream ->
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
iStream.copyTo(oStream)
oStream.flush()
}
}
viewModel.importBook(nDoc.uri)
}
}
} else {
val treeFile = File(treeUri.path!!)

Loading…
Cancel
Save