Fix file export when no file can open this type and export is chosen

Before the `FileInputStream` got closed before started reading because of the async UseCase
This commit is contained in:
Julian Raufelder 2022-05-05 17:44:36 +02:00
parent 0f05400353
commit 47131abd50
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D

View File

@ -284,16 +284,18 @@ class BrowseFilesPresenter @Inject constructor( //
private fun copyFile(downloadFiles: List<DownloadFile>) {
downloadFiles.forEach { downloadFile ->
try {
FileInputStream(fileUtil.fileFor(cloudFileModelMapper.toModel(downloadFile.downloadFile))).use {
copyDataUseCase //
.withSource(it) //
.andTarget(downloadFile.dataSink) //
.run(object : DefaultResultHandler<Void>() {
override fun onFinished() {
view?.showMessage(R.string.screen_file_browser_msg_file_exported)
}
})
}
val source = FileInputStream(fileUtil.fileFor(cloudFileModelMapper.toModel(downloadFile.downloadFile)))
copyDataUseCase //
.withSource(source) //
.andTarget(downloadFile.dataSink) //
.run(object : DefaultResultHandler<Void>() {
override fun onSuccess(t: Void?) {
view?.showMessage(R.string.screen_file_browser_msg_file_exported)
}
override fun onFinished() {
source.close()
}
})
} catch (e: FileNotFoundException) {
showError(e)
}