|
@@ -74,6 +74,9 @@ open class FolderPickerActivity :
|
|
|
private var mChooseBtn: MaterialButton? = null
|
|
|
private var caption: String? = null
|
|
|
|
|
|
+ private var mAction: String? = null
|
|
|
+ private var mTargetFilePaths: ArrayList<String>? = null
|
|
|
+
|
|
|
@Inject
|
|
|
lateinit var localBroadcastManager: LocalBroadcastManager
|
|
|
|
|
@@ -95,8 +98,9 @@ open class FolderPickerActivity :
|
|
|
View.VISIBLE
|
|
|
findViewById<View>(R.id.switch_grid_view_button).visibility =
|
|
|
View.GONE
|
|
|
- if (intent.getStringExtra(EXTRA_ACTION) != null) {
|
|
|
- when (intent.getStringExtra(EXTRA_ACTION)) {
|
|
|
+ mAction = intent.getStringExtra(EXTRA_ACTION)
|
|
|
+ if (mAction != null) {
|
|
|
+ when (mAction) {
|
|
|
MOVE -> {
|
|
|
caption = resources.getText(R.string.move_to).toString()
|
|
|
mSearchOnlyFolders = true
|
|
@@ -118,6 +122,7 @@ open class FolderPickerActivity :
|
|
|
} else {
|
|
|
caption = themeUtils.getDefaultDisplayNameForRootFolder(this)
|
|
|
}
|
|
|
+ mTargetFilePaths = intent.getStringArrayListExtra(EXTRA_FILE_PATHS)
|
|
|
if (intent.getParcelableExtra<Parcelable?>(EXTRA_CURRENT_FOLDER) != null) {
|
|
|
file = intent.getParcelableExtra(EXTRA_CURRENT_FOLDER)
|
|
|
}
|
|
@@ -146,7 +151,7 @@ open class FolderPickerActivity :
|
|
|
val listOfFolders = listOfFilesFragment
|
|
|
listOfFolders!!.listDirectory(folder, false, false)
|
|
|
startSyncFolderOperation(folder, false)
|
|
|
- updateNavigationElementsInActionBar()
|
|
|
+ updateUiElements()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -205,7 +210,7 @@ open class FolderPickerActivity :
|
|
|
*/
|
|
|
override fun onBrowsedDownTo(directory: OCFile) {
|
|
|
file = directory
|
|
|
- updateNavigationElementsInActionBar()
|
|
|
+ updateUiElements()
|
|
|
// Sync Folder
|
|
|
startSyncFolderOperation(directory, false)
|
|
|
}
|
|
@@ -241,6 +246,8 @@ open class FolderPickerActivity :
|
|
|
// refresh list of files
|
|
|
refreshListOfFilesFragment(false)
|
|
|
|
|
|
+ updateUiElements()
|
|
|
+
|
|
|
// Listen for sync messages
|
|
|
val syncIntentFilter = IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START)
|
|
|
syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END)
|
|
@@ -317,7 +324,7 @@ open class FolderPickerActivity :
|
|
|
val root = storageManager.getFileByPath(OCFile.ROOT_PATH)
|
|
|
listOfFiles.listDirectory(root, false, false)
|
|
|
file = listOfFiles.currentFile
|
|
|
- updateNavigationElementsInActionBar()
|
|
|
+ updateUiElements()
|
|
|
startSyncFolderOperation(root, false)
|
|
|
}
|
|
|
}
|
|
@@ -331,10 +338,34 @@ open class FolderPickerActivity :
|
|
|
return
|
|
|
}
|
|
|
file = listOfFiles.currentFile
|
|
|
- updateNavigationElementsInActionBar()
|
|
|
+ updateUiElements()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun updateUiElements() {
|
|
|
+ toggleChooseEnabled()
|
|
|
+ updateNavigationElementsInActionBar()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun toggleChooseEnabled() {
|
|
|
+ mChooseBtn?.isEnabled = checkFolderSelectable()
|
|
|
+ }
|
|
|
+
|
|
|
+ // for copy and move, disable selecting parent folder of target files
|
|
|
+ private fun checkFolderSelectable(): Boolean {
|
|
|
+ return when {
|
|
|
+ mAction != COPY && mAction != MOVE -> true
|
|
|
+ mTargetFilePaths.isNullOrEmpty() -> true
|
|
|
+ file?.isFolder != true -> true
|
|
|
+ // only disable if ALL target files are in selected folder
|
|
|
+ else -> mTargetFilePaths!!.any { !isParentFolder(file.remotePath, it) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun isParentFolder(folderPath: String, filePath: String): Boolean {
|
|
|
+ return folderPath == File(filePath).parent
|
|
|
+ }
|
|
|
+
|
|
|
private fun updateNavigationElementsInActionBar() {
|
|
|
val currentDir = currentFolder
|
|
|
val actionBar = supportActionBar
|
|
@@ -378,9 +409,8 @@ open class FolderPickerActivity :
|
|
|
if (targetFiles != null) {
|
|
|
resultData.putParcelableArrayListExtra(EXTRA_FILES, targetFiles)
|
|
|
}
|
|
|
- val targetFilePaths = i.getStringArrayListExtra(EXTRA_FILE_PATHS)
|
|
|
- if (targetFilePaths != null) {
|
|
|
- resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, targetFilePaths)
|
|
|
+ mTargetFilePaths.let {
|
|
|
+ resultData.putStringArrayListExtra(EXTRA_FILE_PATHS, it)
|
|
|
}
|
|
|
setResult(RESULT_OK, resultData)
|
|
|
finish()
|