formatting a file style, no real change

This commit is contained in:
tibbi 2021-12-19 20:16:40 +01:00
parent cad5d05cd7
commit d0d4b27746

View file

@ -14,84 +14,84 @@ class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<S
val view = activity.layoutInflater.inflate(R.layout.dialog_rename_items, null)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.rename) {
showKeyboard(view.rename_items_value)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (ignoreClicks) {
return@setOnClickListener
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.rename) {
showKeyboard(view.rename_items_value)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (ignoreClicks) {
return@setOnClickListener
}
val valueToAdd = view.rename_items_value.text.toString()
val append = view.rename_items_radio_group.checkedRadioButtonId == rename_items_radio_append.id
if (valueToAdd.isEmpty()) {
callback()
dismiss()
return@setOnClickListener
}
if (!valueToAdd.isAValidFilename()) {
activity.toast(R.string.invalid_name)
return@setOnClickListener
}
val validPaths = paths.filter { activity.getDoesFilePathExist(it) }
val sdFilePath = validPaths.firstOrNull { activity.isPathOnSD(it) } ?: validPaths.firstOrNull()
if (sdFilePath == null) {
activity.toast(R.string.unknown_error_occurred)
dismiss()
return@setOnClickListener
}
activity.handleSAFDialog(sdFilePath) {
if (!it) {
return@handleSAFDialog
}
val valueToAdd = view.rename_items_value.text.toString()
val append = view.rename_items_radio_group.checkedRadioButtonId == rename_items_radio_append.id
if (valueToAdd.isEmpty()) {
callback()
dismiss()
return@setOnClickListener
}
if (!valueToAdd.isAValidFilename()) {
activity.toast(R.string.invalid_name)
return@setOnClickListener
}
val validPaths = paths.filter { activity.getDoesFilePathExist(it) }
val sdFilePath = validPaths.firstOrNull { activity.isPathOnSD(it) } ?: validPaths.firstOrNull()
if (sdFilePath == null) {
activity.toast(R.string.unknown_error_occurred)
dismiss()
return@setOnClickListener
}
activity.handleSAFDialog(sdFilePath) {
if (!it) {
return@handleSAFDialog
ignoreClicks = true
var pathsCnt = validPaths.size
for (path in validPaths) {
val fullName = path.getFilenameFromPath()
var dotAt = fullName.lastIndexOf(".")
if (dotAt == -1) {
dotAt = fullName.length
}
ignoreClicks = true
var pathsCnt = validPaths.size
for (path in validPaths) {
val fullName = path.getFilenameFromPath()
var dotAt = fullName.lastIndexOf(".")
if (dotAt == -1) {
dotAt = fullName.length
}
val name = fullName.substring(0, dotAt)
val extension = if (fullName.contains(".")) ".${fullName.getFilenameExtension()}" else ""
val name = fullName.substring(0, dotAt)
val extension = if (fullName.contains(".")) ".${fullName.getFilenameExtension()}" else ""
val newName = if (append) {
"$name$valueToAdd$extension"
} else {
"$valueToAdd$fullName"
}
val newName = if (append) {
"$name$valueToAdd$extension"
} else {
"$valueToAdd$fullName"
}
val newPath = "${path.getParentPath()}/$newName"
val newPath = "${path.getParentPath()}/$newName"
if (activity.getDoesFilePathExist(newPath)) {
continue
}
if (activity.getDoesFilePathExist(newPath)) {
continue
}
activity.renameFile(path, newPath, true) { success, useAndroid30Way ->
if (success) {
pathsCnt--
if (pathsCnt == 0) {
callback()
dismiss()
}
} else {
ignoreClicks = false
activity.toast(R.string.unknown_error_occurred)
activity.renameFile(path, newPath, true) { success, useAndroid30Way ->
if (success) {
pathsCnt--
if (pathsCnt == 0) {
callback()
dismiss()
}
} else {
ignoreClicks = false
activity.toast(R.string.unknown_error_occurred)
dismiss()
}
}
}
}
}
}
}
}
}