handle copy/move, share, create new directory
This commit is contained in:
parent
26d79d5f4a
commit
6dbfdb0c24
|
@ -304,7 +304,7 @@ class MainActivity : SimpleActivity() {
|
|||
try {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
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)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
@ -325,7 +325,7 @@ class MainActivity : SimpleActivity() {
|
|||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
isAskingPermissions = false
|
||||
if(requestCode == MANAGE_STORAGE_RC && isRPlus()){
|
||||
if (requestCode == MANAGE_STORAGE_RC && isRPlus()) {
|
||||
actionOnPermission?.invoke(Environment.isExternalStorageManager())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -327,13 +327,25 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||
private fun addFileUris(path: String, paths: ArrayList<String>) {
|
||||
if (activity.getIsPathDirectory(path)) {
|
||||
val shouldShowHidden = activity.config.shouldShowHidden
|
||||
if (activity.isPathOnOTG(path)) {
|
||||
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
|
||||
addFileUris(it.uri.toString(), paths)
|
||||
when {
|
||||
activity.isRestrictedAndroidDir(path) -> {
|
||||
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 {
|
||||
addFileUris(it.absolutePath, paths)
|
||||
|
||||
activity.isPathOnOTG(path) -> {
|
||||
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 {
|
||||
|
@ -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_AUDIO, res.getString(R.string.audio_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) {
|
||||
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) {
|
||||
if (!isCopyOperation) {
|
||||
files.forEach { sourceFileDir ->
|
||||
val sourceFile = File(sourceFileDir.path)
|
||||
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) {
|
||||
val sourcePath = sourceFileDir.path
|
||||
if (activity.isRestrictedAndroidDir(sourcePath) && activity.getDoesFilePathExist(sourcePath)) {
|
||||
activity.deleteFile(sourceFileDir, true) {
|
||||
listener?.refreshItems()
|
||||
activity.runOnUiThread {
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
listener?.refreshItems()
|
||||
finishActMode()
|
||||
val sourceFile = File(sourcePath)
|
||||
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 {
|
||||
|
@ -828,10 +852,13 @@ class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem
|
|||
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)
|
||||
}
|
||||
|
||||
|
||||
return itemToLoad
|
||||
}
|
||||
|
||||
|
|
|
@ -67,13 +67,19 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||
success(alertDialog)
|
||||
}
|
||||
path.startsWith(activity.internalStoragePath, true) -> {
|
||||
if (isRPlus() && activity.isSAFOnlyRoot(path)) {
|
||||
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)
|
||||
if (activity.isRestrictedAndroidDir(path)) {
|
||||
activity.handlePrimarySAFDialog(path) {
|
||||
if (!it) {
|
||||
callback(false)
|
||||
return@handlePrimarySAFDialog
|
||||
}
|
||||
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 {
|
||||
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) {
|
||||
try {
|
||||
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.handleSAFDialog(path) {
|
||||
if (!it) {
|
||||
|
@ -113,22 +135,13 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||
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 -> {
|
||||
RootHelpers(activity).createFileFolder(path, true) {
|
||||
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 getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
|
||||
|
||||
if (isRPlus() && context.isSAFOnlyRoot(path)) {
|
||||
if (context.isRestrictedAndroidDir(path)) {
|
||||
activity?.handlePrimarySAFDialog(path) {
|
||||
context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) {
|
||||
callback(path, getListItemsFromFileDirItems(it))
|
||||
|
@ -214,7 +214,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||
if (getProperChildCount) {
|
||||
items.filter { it.mIsDirectory }.forEach {
|
||||
if (context != null) {
|
||||
val childrenCount = it.getDirectChildrenCount(context!!, showHidden)
|
||||
val childrenCount = it.getDirectChildrenCount(activity as BaseSimpleActivity, showHidden)
|
||||
if (childrenCount != 0) {
|
||||
activity?.runOnUiThread {
|
||||
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
|
||||
|
@ -235,7 +235,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||
|
||||
var lastModified = lastModifieds.remove(curPath)
|
||||
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) {
|
||||
if (isSortingBySize) {
|
||||
file.getProperSize(showHidden)
|
||||
|
|
Loading…
Reference in New Issue