mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
本地书籍无权限则保存到自己选定的文件夹
This commit is contained in:
parent
d118a2551e
commit
44f0a217bc
@ -18,6 +18,8 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
class FileAssociationActivity :
|
class FileAssociationActivity :
|
||||||
VMBaseActivity<ActivityTranslucenceBinding, FileAssociationViewModel>() {
|
VMBaseActivity<ActivityTranslucenceBinding, FileAssociationViewModel>() {
|
||||||
@ -91,10 +93,11 @@ class FileAssociationActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun importBook(treeUri: Uri, uri: Uri) {
|
private fun importBook(treeUri: Uri, uri: Uri) {
|
||||||
val treeDoc = DocumentFile.fromTreeUri(this, treeUri)
|
|
||||||
val bookDoc = DocumentFile.fromSingleUri(this, uri)
|
|
||||||
launch {
|
launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
|
if (treeUri.isContentScheme()) {
|
||||||
|
val treeDoc = DocumentFile.fromTreeUri(this@FileAssociationActivity, treeUri)
|
||||||
|
val bookDoc = DocumentFile.fromSingleUri(this@FileAssociationActivity, uri)
|
||||||
withContext(IO) {
|
withContext(IO) {
|
||||||
val name = bookDoc?.name!!
|
val name = bookDoc?.name!!
|
||||||
val doc = treeDoc!!.findFile(name)
|
val doc = treeDoc!!.findFile(name)
|
||||||
@ -108,6 +111,24 @@ class FileAssociationActivity :
|
|||||||
oStream.flush()
|
oStream.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewModel.importBook(nDoc.uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val treeFile = File(treeUri.path!!)
|
||||||
|
val bookDoc = DocumentFile.fromSingleUri(this@FileAssociationActivity, uri)
|
||||||
|
withContext(IO) {
|
||||||
|
val name = bookDoc?.name!!
|
||||||
|
val file = treeFile.getFile(name)
|
||||||
|
if (!file.exists() || file.lastModified() < bookDoc.lastModified()) {
|
||||||
|
FileOutputStream(file).use { oStream ->
|
||||||
|
contentResolver.openInputStream(bookDoc.uri)!!.use { iStream ->
|
||||||
|
iStream.copyTo(oStream)
|
||||||
|
oStream.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
viewModel.importBook(Uri.fromFile(file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
Loading…
Reference in New Issue
Block a user