mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
优化
This commit is contained in:
parent
f0ee3e41ba
commit
6db2f2f390
@ -105,27 +105,19 @@ class FileAssociationActivity :
|
|||||||
val bookDoc = DocumentFile.fromSingleUri(this@FileAssociationActivity, uri)
|
val bookDoc = DocumentFile.fromSingleUri(this@FileAssociationActivity, uri)
|
||||||
withContext(IO) {
|
withContext(IO) {
|
||||||
val name = bookDoc?.name!!
|
val name = bookDoc?.name!!
|
||||||
val doc = treeDoc!!.findFile(name)
|
var doc = treeDoc!!.findFile(name)
|
||||||
if (doc != null) {
|
if (doc == null || bookDoc.lastModified() > doc.lastModified()) {
|
||||||
if (bookDoc.lastModified() > doc.lastModified()) {
|
if (doc == null) {
|
||||||
contentResolver.openOutputStream(doc.uri)!!.use { oStream ->
|
doc = treeDoc.createFile(FileUtils.getMimeType(name), name)!!
|
||||||
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
|
|
||||||
iStream.copyTo(oStream)
|
|
||||||
oStream.flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
viewModel.importBook(doc.uri)
|
contentResolver.openOutputStream(doc.uri)!!.use { oStream ->
|
||||||
} else {
|
|
||||||
val nDoc = treeDoc.createFile(FileUtils.getMimeType(name), name)!!
|
|
||||||
contentResolver.openOutputStream(nDoc.uri)!!.use { oStream ->
|
|
||||||
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
|
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
|
||||||
iStream.copyTo(oStream)
|
iStream.copyTo(oStream)
|
||||||
oStream.flush()
|
oStream.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.importBook(nDoc.uri)
|
|
||||||
}
|
}
|
||||||
|
viewModel.importBook(doc.uri)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val treeFile = File(treeUri.path!!)
|
val treeFile = File(treeUri.path!!)
|
||||||
|
Loading…
Reference in New Issue
Block a user