better ux, how to inform when file already exists
This commit is contained in:
@@ -60,6 +60,7 @@ data class CreateImgProgress(
|
|||||||
@Composable
|
@Composable
|
||||||
fun CreateImgDialog(
|
fun CreateImgDialog(
|
||||||
progress: CreateImgProgress,
|
progress: CreateImgProgress,
|
||||||
|
existingFiles: List<String> = emptyList(),
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onConfirm: (CreateImgOptions) -> Unit,
|
onConfirm: (CreateImgOptions) -> Unit,
|
||||||
onCancel: () -> Unit
|
onCancel: () -> Unit
|
||||||
@@ -68,9 +69,13 @@ fun CreateImgDialog(
|
|||||||
var sizeValue by remember { mutableStateOf("") }
|
var sizeValue by remember { mutableStateOf("") }
|
||||||
var sizeUnit by remember { mutableStateOf(SizeUnit.GB) }
|
var sizeUnit by remember { mutableStateOf(SizeUnit.GB) }
|
||||||
|
|
||||||
|
val fullFileName = if (fileName.isNotBlank()) "$fileName.img" else ""
|
||||||
|
val fileExists = fullFileName.isNotEmpty() && existingFiles.contains(fullFileName)
|
||||||
|
|
||||||
val isValidInput = fileName.isNotBlank() &&
|
val isValidInput = fileName.isNotBlank() &&
|
||||||
!fileName.contains("/") &&
|
!fileName.contains("/") &&
|
||||||
sizeValue.toLongOrNull()?.let { it > 0 } == true
|
sizeValue.toLongOrNull()?.let { it > 0 } == true &&
|
||||||
|
!fileExists
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
@@ -129,9 +134,20 @@ fun CreateImgDialog(
|
|||||||
label = { Text("File Name") },
|
label = { Text("File Name") },
|
||||||
suffix = { Text(".img") },
|
suffix = { Text(".img") },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
|
isError = fileExists,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Show error if file exists
|
||||||
|
if (fileExists) {
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
Text(
|
||||||
|
text = "A file with this name already exists. Please choose a different name.",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
// Size input
|
// Size input
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ fun MainScreen(
|
|||||||
if (showCreateImgDialog || uiState.createImgProgress.isCreating) {
|
if (showCreateImgDialog || uiState.createImgProgress.isCreating) {
|
||||||
CreateImgDialog(
|
CreateImgDialog(
|
||||||
progress = uiState.createImgProgress,
|
progress = uiState.createImgProgress,
|
||||||
|
existingFiles = uiState.isoFiles.map { it.name },
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
showCreateImgDialog = false
|
showCreateImgDialog = false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -417,13 +417,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
val filePath = "${_uiState.value.currentPath}/$fileName"
|
val filePath = "${_uiState.value.currentPath}/$fileName"
|
||||||
val totalBytes = options.totalBytes
|
val totalBytes = options.totalBytes
|
||||||
|
|
||||||
// Check if file already exists
|
|
||||||
val checkResult = RootManager.executeCommand("test -f \"$filePath\" && echo exists")
|
|
||||||
if (checkResult.output.trim() == "exists") {
|
|
||||||
_uiState.update { it.copy(errorMessage = "File already exists: $fileName") }
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start creating
|
// Start creating
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
|||||||
Reference in New Issue
Block a user