mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-03 11:57:49 +01:00
read handle create file/directory
This commit is contained in:
parent
471d77e19f
commit
644842322b
@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.dialogs
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.isRPlus
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
||||||
@ -15,37 +16,37 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create().apply {
|
||||||
activity.setupDialogStuff(view, this, R.string.create_new) {
|
activity.setupDialogStuff(view, this, R.string.create_new) {
|
||||||
showKeyboard(view.item_name)
|
showKeyboard(view.item_name)
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
||||||
val name = view.item_name.value
|
val name = view.item_name.value
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
activity.toast(R.string.empty_name)
|
activity.toast(R.string.empty_name)
|
||||||
} else if (name.isAValidFilename()) {
|
} else if (name.isAValidFilename()) {
|
||||||
val newPath = "$path/$name"
|
val newPath = "$path/$name"
|
||||||
if (activity.getDoesFilePathExist(newPath)) {
|
if (activity.getDoesFilePathExist(newPath)) {
|
||||||
activity.toast(R.string.name_taken)
|
activity.toast(R.string.name_taken)
|
||||||
return@OnClickListener
|
return@OnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
|
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
|
||||||
createDirectory(newPath, this) {
|
createDirectory(newPath, this) {
|
||||||
callback(it)
|
callback(it)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
createFile(newPath, this) {
|
|
||||||
callback(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
activity.toast(R.string.invalid_name)
|
createFile(newPath, this) {
|
||||||
|
callback(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
}
|
activity.toast(R.string.invalid_name)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
||||||
@ -66,8 +67,18 @@ 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 (File(path).mkdirs()) {
|
if (isRPlus() && activity.isSAFOnlyRoot(path)) {
|
||||||
success(alertDialog)
|
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()) {
|
||||||
|
success(alertDialog)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
@ -103,9 +114,20 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.startsWith(activity.internalStoragePath, true) -> {
|
path.startsWith(activity.internalStoragePath, true) -> {
|
||||||
if (File(path).createNewFile()) {
|
if (isRPlus() && activity.isSAFOnlyRoot(path)) {
|
||||||
success(alertDialog)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
RootHelpers(activity).createFileFolder(path, true) {
|
RootHelpers(activity).createFileFolder(path, true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user