diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 1b78fa963..2f67e8f90 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -69,10 +69,14 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity goBackDir() } btn_add_book.onClick { - viewModel.addToBookshelf(adapter.selectedUris) + viewModel.addToBookshelf(adapter.selectedUris) { + upPath() + } } btn_delete.onClick { - viewModel.deleteDoc(adapter.selectedUris) + viewModel.deleteDoc(adapter.selectedUris) { + upPath() + } } cb_selected_all.onClick { adapter.selectAll(cb_selected_all.isChecked) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index 6fdcd8034..a8bd64ea8 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -1,17 +1,25 @@ package io.legado.app.ui.importbook import android.app.Application +import android.net.Uri +import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel class ImportBookViewModel(application: Application) : BaseViewModel(application) { - fun addToBookshelf(uriList: HashSet) { + fun addToBookshelf(uriList: HashSet, finally: () -> Unit) { } - fun deleteDoc(uriList: HashSet) { - + fun deleteDoc(uriList: HashSet, finally: () -> Unit) { + execute { + uriList.forEach { + DocumentFile.fromSingleUri(context, Uri.parse(it))?.delete() + } + }.onFinally { + finally.invoke() + } } } \ No newline at end of file