mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
handle copy/move, share, create new directory
This commit is contained in:
@ -304,7 +304,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
try {
|
try {
|
||||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||||
intent.addCategory("android.intent.category.DEFAULT")
|
intent.addCategory("android.intent.category.DEFAULT")
|
||||||
intent.data = Uri.parse(String.format("package:%s", applicationContext.packageName))
|
intent.data = Uri.parse("package:$packageName")
|
||||||
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
startActivityForResult(intent, MANAGE_STORAGE_RC)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
@ -325,7 +325,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
isAskingPermissions = false
|
isAskingPermissions = false
|
||||||
if(requestCode == MANAGE_STORAGE_RC && isRPlus()){
|
if (requestCode == MANAGE_STORAGE_RC && isRPlus()) {
|
||||||
actionOnPermission?.invoke(Environment.isExternalStorageManager())
|
actionOnPermission?.invoke(Environment.isExternalStorageManager())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,13 +327,25 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||||||
private fun addFileUris(path: String, paths: ArrayList<String>) {
|
private fun addFileUris(path: String, paths: ArrayList<String>) {
|
||||||
if (activity.getIsPathDirectory(path)) {
|
if (activity.getIsPathDirectory(path)) {
|
||||||
val shouldShowHidden = activity.config.shouldShowHidden
|
val shouldShowHidden = activity.config.shouldShowHidden
|
||||||
if (activity.isPathOnOTG(path)) {
|
when {
|
||||||
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
|
activity.isRestrictedAndroidDir(path) -> {
|
||||||
addFileUris(it.uri.toString(), paths)
|
activity.getStorageItemsWithTreeUri(path, shouldShowHidden, false){ files->
|
||||||
|
files.forEach {
|
||||||
|
addFileUris(activity.getPrimaryAndroidSAFUri(it.path).toString(), paths)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
File(path).listFiles()?.filter { if (shouldShowHidden) true else !it.name.startsWith('.') }?.forEach {
|
activity.isPathOnOTG(path) -> {
|
||||||
addFileUris(it.absolutePath, paths)
|
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
|
||||||
|
addFileUris(it.uri.toString(), paths)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
File(path).listFiles()?.filter { if (shouldShowHidden) true else !it.name.startsWith('.') }?.forEach {
|
||||||
|
addFileUris(it.absolutePath, paths)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -363,7 +375,8 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||||||
RadioItem(OPEN_AS_IMAGE, res.getString(R.string.image_file)),
|
RadioItem(OPEN_AS_IMAGE, res.getString(R.string.image_file)),
|
||||||
RadioItem(OPEN_AS_AUDIO, res.getString(R.string.audio_file)),
|
RadioItem(OPEN_AS_AUDIO, res.getString(R.string.audio_file)),
|
||||||
RadioItem(OPEN_AS_VIDEO, res.getString(R.string.video_file)),
|
RadioItem(OPEN_AS_VIDEO, res.getString(R.string.video_file)),
|
||||||
RadioItem(OPEN_AS_OTHER, res.getString(R.string.other_file)))
|
RadioItem(OPEN_AS_OTHER, res.getString(R.string.other_file))
|
||||||
|
)
|
||||||
|
|
||||||
RadioGroupDialog(activity, items) {
|
RadioGroupDialog(activity, items) {
|
||||||
activity.tryOpenPathIntent(getFirstSelectedItemPath(), false, it as Int)
|
activity.tryOpenPathIntent(getFirstSelectedItemPath(), false, it as Int)
|
||||||
@ -387,19 +400,30 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||||||
activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) {
|
activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) {
|
||||||
if (!isCopyOperation) {
|
if (!isCopyOperation) {
|
||||||
files.forEach { sourceFileDir ->
|
files.forEach { sourceFileDir ->
|
||||||
val sourceFile = File(sourceFileDir.path)
|
val sourcePath = sourceFileDir.path
|
||||||
if (activity.getDoesFilePathExist(source) && activity.getIsPathDirectory(source) &&
|
if (activity.isRestrictedAndroidDir(sourcePath) && activity.getDoesFilePathExist(sourcePath)) {
|
||||||
sourceFile.list()?.isEmpty() == true && sourceFile.getProperSize(true) == 0L && sourceFile.getFileCount(true) == 0) {
|
activity.deleteFile(sourceFileDir, true) {
|
||||||
val sourceFolder = sourceFile.toFileDirItem(activity)
|
|
||||||
activity.deleteFile(sourceFolder, true) {
|
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
finishActMode()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
listener?.refreshItems()
|
val sourceFile = File(sourcePath)
|
||||||
finishActMode()
|
if (activity.getDoesFilePathExist(source) && activity.getIsPathDirectory(source) &&
|
||||||
|
sourceFile.list()?.isEmpty() == true && sourceFile.getProperSize(true) == 0L && sourceFile.getFileCount(true) == 0
|
||||||
|
) {
|
||||||
|
val sourceFolder = sourceFile.toFileDirItem(activity)
|
||||||
|
activity.deleteFile(sourceFolder, true) {
|
||||||
|
listener?.refreshItems()
|
||||||
|
activity.runOnUiThread {
|
||||||
|
finishActMode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
listener?.refreshItems()
|
||||||
|
finishActMode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -828,10 +852,13 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasOTGConnected && itemToLoad is String && activity.isPathOnOTG(itemToLoad) && baseConfig.OTGTreeUri.isNotEmpty() && baseConfig.OTGPartition.isNotEmpty()) {
|
if (activity.isRestrictedAndroidDir(path)) {
|
||||||
|
itemToLoad = activity.getPrimaryAndroidSAFUri(path)
|
||||||
|
} else if (hasOTGConnected && itemToLoad is String && activity.isPathOnOTG(itemToLoad) && baseConfig.OTGTreeUri.isNotEmpty() && baseConfig.OTGPartition.isNotEmpty()) {
|
||||||
itemToLoad = getOTGPublicPath(itemToLoad)
|
itemToLoad = getOTGPublicPath(itemToLoad)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return itemToLoad
|
return itemToLoad
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,13 +67,19 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||||||
success(alertDialog)
|
success(alertDialog)
|
||||||
}
|
}
|
||||||
path.startsWith(activity.internalStoragePath, true) -> {
|
path.startsWith(activity.internalStoragePath, true) -> {
|
||||||
if (isRPlus() && activity.isSAFOnlyRoot(path)) {
|
if (activity.isRestrictedAndroidDir(path)) {
|
||||||
if (activity.createSAFOnlyDirectory(path)) {
|
activity.handlePrimarySAFDialog(path) {
|
||||||
success(alertDialog)
|
if (!it) {
|
||||||
} else {
|
callback(false)
|
||||||
val error = String.format(activity.getString(R.string.could_not_create_folder), path)
|
return@handlePrimarySAFDialog
|
||||||
activity.showErrorToast(error)
|
}
|
||||||
callback(false)
|
if (activity.createSAFOnlyDirectory(path)) {
|
||||||
|
success(alertDialog)
|
||||||
|
} else {
|
||||||
|
val error = String.format(activity.getString(R.string.could_not_create_folder), path)
|
||||||
|
activity.showErrorToast(error)
|
||||||
|
callback(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (File(path).mkdirs()) {
|
if (File(path).mkdirs()) {
|
||||||
@ -96,6 +102,22 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||||||
private fun createFile(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
private fun createFile(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
||||||
try {
|
try {
|
||||||
when {
|
when {
|
||||||
|
activity.isRestrictedAndroidDir(path) -> {
|
||||||
|
activity.handlePrimarySAFDialog(path) {
|
||||||
|
if (!it) {
|
||||||
|
callback(false)
|
||||||
|
return@handlePrimarySAFDialog
|
||||||
|
}
|
||||||
|
if (activity.createSAFOnlyFile(path)) {
|
||||||
|
success(alertDialog)
|
||||||
|
} else {
|
||||||
|
val error = String.format(activity.getString(R.string.could_not_create_file), path)
|
||||||
|
activity.showErrorToast(error)
|
||||||
|
callback(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activity.needsStupidWritePermissions(path) -> {
|
activity.needsStupidWritePermissions(path) -> {
|
||||||
activity.handleSAFDialog(path) {
|
activity.handleSAFDialog(path) {
|
||||||
if (!it) {
|
if (!it) {
|
||||||
@ -113,22 +135,13 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||||||
success(alertDialog)
|
success(alertDialog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.startsWith(activity.internalStoragePath, true) -> {
|
|
||||||
if (isRPlus() && activity.isSAFOnlyRoot(path)) {
|
|
||||||
if (activity.createSAFOnlyFile(path)) {
|
|
||||||
success(alertDialog)
|
|
||||||
} else {
|
|
||||||
val error = String.format(activity.getString(R.string.could_not_create_file), path)
|
|
||||||
activity.showErrorToast(error)
|
|
||||||
callback(false)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (File(path).createNewFile()) {
|
|
||||||
success(alertDialog)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
path.startsWith(activity.internalStoragePath, true) -> {
|
||||||
|
if (File(path).createNewFile()) {
|
||||||
|
success(alertDialog)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
RootHelpers(activity).createFileFolder(path, true) {
|
RootHelpers(activity).createFileFolder(path, true) {
|
||||||
if (it) {
|
if (it) {
|
||||||
|
@ -187,7 +187,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
|
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
|
||||||
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
|
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
|
||||||
|
|
||||||
if (isRPlus() && context.isSAFOnlyRoot(path)) {
|
if (context.isRestrictedAndroidDir(path)) {
|
||||||
activity?.handlePrimarySAFDialog(path) {
|
activity?.handlePrimarySAFDialog(path) {
|
||||||
context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) {
|
context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) {
|
||||||
callback(path, getListItemsFromFileDirItems(it))
|
callback(path, getListItemsFromFileDirItems(it))
|
||||||
@ -214,7 +214,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
if (getProperChildCount) {
|
if (getProperChildCount) {
|
||||||
items.filter { it.mIsDirectory }.forEach {
|
items.filter { it.mIsDirectory }.forEach {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
val childrenCount = it.getDirectChildrenCount(context!!, showHidden)
|
val childrenCount = it.getDirectChildrenCount(activity as BaseSimpleActivity, showHidden)
|
||||||
if (childrenCount != 0) {
|
if (childrenCount != 0) {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
|
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
|
||||||
@ -235,7 +235,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
|
|
||||||
var lastModified = lastModifieds.remove(curPath)
|
var lastModified = lastModifieds.remove(curPath)
|
||||||
val isDirectory = if (lastModified != null) false else file.isDirectory
|
val isDirectory = if (lastModified != null) false else file.isDirectory
|
||||||
val children = if (isDirectory && getProperChildCount) file.getDirectChildrenCount(showHidden) else 0
|
val children = if (isDirectory && getProperChildCount) file.getDirectChildrenCount(context, showHidden) else 0
|
||||||
val size = if (isDirectory) {
|
val size = if (isDirectory) {
|
||||||
if (isSortingBySize) {
|
if (isSortingBySize) {
|
||||||
file.getProperSize(showHidden)
|
file.getProperSize(showHidden)
|
||||||
|
Reference in New Issue
Block a user