reuse some file operations from the shared lib
This commit is contained in:
parent
6854890b8e
commit
56cd0bb14f
|
@ -32,7 +32,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.9.9'
|
||||
compile 'com.simplemobiletools:commons:2.11.5'
|
||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.simplemobiletools.filemanager.SCROLL_STATE
|
|||
import com.simplemobiletools.filemanager.extensions.config
|
||||
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
||||
|
@ -128,7 +127,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
initRootFileManager()
|
||||
} else {
|
||||
toast(R.string.no_permissions)
|
||||
toast(R.string.no_storage_permissions)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
@ -150,9 +149,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
}
|
||||
|
||||
fun changePath(pickedPath: String) {
|
||||
if (!isShowingPermDialog(File(pickedPath))) {
|
||||
mBasePath = pickedPath
|
||||
openPath(pickedPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,16 +166,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
val files = ArrayList<File>(selections.size)
|
||||
val removeFiles = ArrayList<FileDirItem>(selections.size)
|
||||
|
||||
var isShowingPermDialog = false
|
||||
activity.runOnUiThread {
|
||||
if (activity.isShowingPermDialog(File(mItems[selections[0]].path))) {
|
||||
isShowingPermDialog = true
|
||||
}
|
||||
}
|
||||
|
||||
if (isShowingPermDialog)
|
||||
return
|
||||
|
||||
activity.handleSAFDialog(File(mItems[selections[0]].path)) {
|
||||
selections.reverse()
|
||||
selections.forEach {
|
||||
val file = mItems[it]
|
||||
|
@ -188,6 +179,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
markedItems.clear()
|
||||
listener?.deleteFiles(files)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSelectedMedia(): List<FileDirItem> {
|
||||
val positions = multiSelector.selectedPositions
|
||||
|
|
|
@ -57,10 +57,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val c
|
|||
}
|
||||
}
|
||||
|
||||
if (activity.isShowingPermDialog(destinationDir)) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
activity.handleSAFDialog(destinationDir) {
|
||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
||||
context.toast(R.string.copying)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
|
||||
|
@ -68,20 +65,18 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val c
|
|||
dismiss()
|
||||
} else {
|
||||
if (context.isPathOnSD(sourcePath) || context.isPathOnSD(destinationPath)) {
|
||||
if (activity.isShowingPermDialog(files[0])) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
activity.handleSAFDialog(files[0]) {
|
||||
context.toast(R.string.moving)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
|
||||
CopyMoveTask(context, true, config.treeUri, false, copyMoveListener).execute(pair)
|
||||
dismiss()
|
||||
}
|
||||
} else {
|
||||
val updatedFiles = ArrayList<File>(files.size * 2)
|
||||
updatedFiles.addAll(files)
|
||||
for (file in files) {
|
||||
val destination = File(destinationDir, file.name)
|
||||
if (file.renameTo(destination))
|
||||
if (!destination.exists() && file.renameTo(destination))
|
||||
updatedFiles.add(destination)
|
||||
}
|
||||
|
||||
|
@ -93,6 +88,7 @@ class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val c
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -189,42 +189,14 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat
|
|||
}
|
||||
|
||||
override fun deleteFiles(files: ArrayList<File>) {
|
||||
val act = activity as SimpleActivity
|
||||
if (act.isShowingPermDialog(files[0])) {
|
||||
return
|
||||
}
|
||||
|
||||
Thread({
|
||||
var hadSuccess = false
|
||||
files.forEach {
|
||||
if (it.isDirectory) {
|
||||
for (child in it.listFiles()) {
|
||||
deleteFile(child, act)
|
||||
(activity as SimpleActivity).deleteFiles(files) {
|
||||
if (!it) {
|
||||
activity.runOnUiThread {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}
|
||||
if (deleteFile(it, act)) {
|
||||
hadSuccess = true
|
||||
context.deleteFromMediaStore(it)
|
||||
}
|
||||
}
|
||||
if (!hadSuccess)
|
||||
act.runOnUiThread {
|
||||
act.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
||||
private fun deleteFile(file: File, act: SimpleActivity): Boolean {
|
||||
if (file.delete() || act.tryFastDocumentDelete(file)) {
|
||||
return true
|
||||
} else {
|
||||
val document = act.getFileDocument(file.absolutePath, context.config.treeUri) ?: return false
|
||||
if (document.isFile && document.delete()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun refreshItems() {
|
||||
fillItems()
|
||||
|
|
Loading…
Reference in New Issue