Merge pull request #2909 from esensar/fix/2901-folder-move-copy-protection
Handle password protection when copying/moving folders
This commit is contained in:
commit
bc85272855
1 changed files with 31 additions and 15 deletions
|
@ -52,6 +52,7 @@ import kotlinx.android.synthetic.main.directory_item_list.view.dir_holder
|
||||||
import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt
|
import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class DirectoryAdapter(
|
class DirectoryAdapter(
|
||||||
activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
|
activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
|
||||||
|
@ -152,7 +153,7 @@ class DirectoryAdapter(
|
||||||
R.id.cab_exclude -> tryExcludeFolder()
|
R.id.cab_exclude -> tryExcludeFolder()
|
||||||
R.id.cab_lock -> tryLockFolder()
|
R.id.cab_lock -> tryLockFolder()
|
||||||
R.id.cab_unlock -> unlockFolder()
|
R.id.cab_unlock -> unlockFolder()
|
||||||
R.id.cab_copy_to -> copyMoveTo(true)
|
R.id.cab_copy_to -> copyFilesTo()
|
||||||
R.id.cab_move_to -> moveFilesTo()
|
R.id.cab_move_to -> moveFilesTo()
|
||||||
R.id.cab_select_all -> selectAll()
|
R.id.cab_select_all -> selectAll()
|
||||||
R.id.cab_create_shortcut -> tryCreateShortcut()
|
R.id.cab_create_shortcut -> tryCreateShortcut()
|
||||||
|
@ -505,16 +506,24 @@ class DirectoryAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveFilesTo() {
|
private fun copyFilesTo() {
|
||||||
activity.handleDeletePasswordProtection {
|
handleLockedFolderOpeningForFolders(getSelectedPaths()) {
|
||||||
copyMoveTo(false)
|
copyMoveTo(it, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun moveFilesTo() {
|
||||||
|
activity.handleDeletePasswordProtection {
|
||||||
|
handleLockedFolderOpeningForFolders(getSelectedPaths()) {
|
||||||
|
copyMoveTo(it, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun copyMoveTo(selectedPaths: Collection<String>, isCopyOperation: Boolean) {
|
||||||
val paths = ArrayList<String>()
|
val paths = ArrayList<String>()
|
||||||
val showHidden = config.shouldShowHidden
|
val showHidden = config.shouldShowHidden
|
||||||
getSelectedPaths().forEach {
|
selectedPaths.forEach {
|
||||||
val filter = config.filterMedia
|
val filter = config.filterMedia
|
||||||
File(it).listFiles()?.filter {
|
File(it).listFiles()?.filter {
|
||||||
!File(it.absolutePath).isDirectory &&
|
!File(it.absolutePath).isDirectory &&
|
||||||
|
@ -583,6 +592,7 @@ class DirectoryAdapter(
|
||||||
config.isDeletePasswordProtectionOn -> activity.handleDeletePasswordProtection {
|
config.isDeletePasswordProtectionOn -> activity.handleDeletePasswordProtection {
|
||||||
deleteFolders()
|
deleteFolders()
|
||||||
}
|
}
|
||||||
|
|
||||||
config.skipDeleteConfirmation -> deleteFolders()
|
config.skipDeleteConfirmation -> deleteFolders()
|
||||||
else -> {
|
else -> {
|
||||||
val itemsCnt = selectedKeys.size
|
val itemsCnt = selectedKeys.size
|
||||||
|
@ -654,20 +664,26 @@ class DirectoryAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foldersToDelete.size == 1) {
|
handleLockedFolderOpeningForFolders(foldersToDelete.map { it.absolutePath }) {
|
||||||
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
|
listener?.deleteFolders(it.map { File(it) }.toMutableList() as ArrayList<File>)
|
||||||
if (success) {
|
|
||||||
listener?.deleteFolders(foldersToDelete)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foldersToDelete = foldersToDelete.filter { !config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File>
|
|
||||||
listener?.deleteFolders(foldersToDelete)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleLockedFolderOpeningForFolders(folders: Collection<String>, callback: (Collection<String>) -> Unit) {
|
||||||
|
if (folders.size == 1) {
|
||||||
|
activity.handleLockedFolderOpening(folders.first()) { success ->
|
||||||
|
if (success) {
|
||||||
|
callback(folders)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val filtered = folders.filter { !config.isFolderProtected(it) }
|
||||||
|
callback(filtered)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun tryChangeAlbumCover(useDefault: Boolean) {
|
private fun tryChangeAlbumCover(useDefault: Boolean) {
|
||||||
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
|
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
Loading…
Reference in a new issue