better ux, how to inform when file already exists
This commit is contained in:
@@ -60,6 +60,7 @@ data class CreateImgProgress(
|
||||
@Composable
|
||||
fun CreateImgDialog(
|
||||
progress: CreateImgProgress,
|
||||
existingFiles: List<String> = emptyList(),
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (CreateImgOptions) -> Unit,
|
||||
onCancel: () -> Unit
|
||||
@@ -68,9 +69,13 @@ fun CreateImgDialog(
|
||||
var sizeValue by remember { mutableStateOf("") }
|
||||
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() &&
|
||||
!fileName.contains("/") &&
|
||||
sizeValue.toLongOrNull()?.let { it > 0 } == true
|
||||
sizeValue.toLongOrNull()?.let { it > 0 } == true &&
|
||||
!fileExists
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
@@ -129,9 +134,20 @@ fun CreateImgDialog(
|
||||
label = { Text("File Name") },
|
||||
suffix = { Text(".img") },
|
||||
singleLine = true,
|
||||
isError = fileExists,
|
||||
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))
|
||||
|
||||
// Size input
|
||||
|
||||
@@ -207,6 +207,7 @@ fun MainScreen(
|
||||
if (showCreateImgDialog || uiState.createImgProgress.isCreating) {
|
||||
CreateImgDialog(
|
||||
progress = uiState.createImgProgress,
|
||||
existingFiles = uiState.isoFiles.map { it.name },
|
||||
onDismiss = {
|
||||
showCreateImgDialog = false
|
||||
},
|
||||
|
||||
@@ -417,13 +417,6 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val filePath = "${_uiState.value.currentPath}/$fileName"
|
||||
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
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
|
||||
Reference in New Issue
Block a user