delete and rename files
This commit is contained in:
50
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
50
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package sh.sar.isodroid.ui.components
|
package sh.sar.isodroid.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@@ -26,6 +27,8 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import sh.sar.isodroid.data.IsoFile
|
import sh.sar.isodroid.data.IsoFile
|
||||||
@@ -35,10 +38,13 @@ fun FileBrowser(
|
|||||||
files: List<IsoFile>,
|
files: List<IsoFile>,
|
||||||
currentPath: String,
|
currentPath: String,
|
||||||
onFileClick: (IsoFile) -> Unit,
|
onFileClick: (IsoFile) -> Unit,
|
||||||
|
onFileLongClick: (IsoFile) -> Unit,
|
||||||
onNavigateUp: () -> Unit,
|
onNavigateUp: () -> Unit,
|
||||||
canNavigateUp: Boolean,
|
canNavigateUp: Boolean,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
|
val hapticFeedback = LocalHapticFeedback.current
|
||||||
|
|
||||||
Column(modifier = modifier.fillMaxSize()) {
|
Column(modifier = modifier.fillMaxSize()) {
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
Column(
|
Column(
|
||||||
@@ -78,7 +84,8 @@ fun FileBrowser(
|
|||||||
name = "..",
|
name = "..",
|
||||||
size = "",
|
size = "",
|
||||||
isDirectory = true,
|
isDirectory = true,
|
||||||
onClick = onNavigateUp
|
onClick = onNavigateUp,
|
||||||
|
onLongClick = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +95,11 @@ fun FileBrowser(
|
|||||||
name = file.name,
|
name = file.name,
|
||||||
size = file.formattedSize,
|
size = file.formattedSize,
|
||||||
isIso = file.name.lowercase().endsWith(".iso"),
|
isIso = file.name.lowercase().endsWith(".iso"),
|
||||||
onClick = { onFileClick(file) }
|
onClick = { onFileClick(file) },
|
||||||
|
onLongClick = {
|
||||||
|
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
|
onFileLongClick(file)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,18 +107,23 @@ fun FileBrowser(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun FileItem(
|
private fun FileItem(
|
||||||
name: String,
|
name: String,
|
||||||
size: String,
|
size: String,
|
||||||
isDirectory: Boolean = false,
|
isDirectory: Boolean = false,
|
||||||
isIso: Boolean = true,
|
isIso: Boolean = true,
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit,
|
||||||
|
onLongClick: (() -> Unit)?
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable(onClick = onClick),
|
.combinedClickable(
|
||||||
|
onClick = onClick,
|
||||||
|
onLongClick = onLongClick
|
||||||
|
),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
containerColor = MaterialTheme.colorScheme.surface
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
package sh.sar.isodroid.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Edit
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import sh.sar.isodroid.data.IsoFile
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FileContextMenu(
|
||||||
|
file: IsoFile,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onRename: (String) -> Unit,
|
||||||
|
onDelete: () -> Unit
|
||||||
|
) {
|
||||||
|
var showRenameDialog by remember { mutableStateOf(false) }
|
||||||
|
var showDeleteConfirm by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
if (showRenameDialog) {
|
||||||
|
RenameDialog(
|
||||||
|
currentName = file.name,
|
||||||
|
onDismiss = { showRenameDialog = false },
|
||||||
|
onConfirm = { newName ->
|
||||||
|
showRenameDialog = false
|
||||||
|
onRename(newName)
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else if (showDeleteConfirm) {
|
||||||
|
DeleteConfirmDialog(
|
||||||
|
fileName = file.name,
|
||||||
|
onDismiss = { showDeleteConfirm = false },
|
||||||
|
onConfirm = {
|
||||||
|
showDeleteConfirm = false
|
||||||
|
onDelete()
|
||||||
|
onDismiss()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = file.name,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
maxLines = 2,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
MenuItem(
|
||||||
|
icon = { Icon(Icons.Default.Edit, contentDescription = null) },
|
||||||
|
text = "Rename",
|
||||||
|
onClick = { showRenameDialog = true }
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
MenuItem(
|
||||||
|
icon = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Delete,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = "Delete",
|
||||||
|
textColor = MaterialTheme.colorScheme.error,
|
||||||
|
onClick = { showDeleteConfirm = true }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MenuItem(
|
||||||
|
icon: @Composable () -> Unit,
|
||||||
|
text: String,
|
||||||
|
textColor: androidx.compose.ui.graphics.Color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
onClick: () -> Unit
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(onClick = onClick)
|
||||||
|
.padding(vertical = 12.dp, horizontal = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
icon()
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Text(
|
||||||
|
text = text,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = textColor
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RenameDialog(
|
||||||
|
currentName: String,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onConfirm: (String) -> Unit
|
||||||
|
) {
|
||||||
|
// Extract name without extension
|
||||||
|
val extension = if (currentName.contains(".")) {
|
||||||
|
"." + currentName.substringAfterLast(".")
|
||||||
|
} else ""
|
||||||
|
val nameWithoutExtension = currentName.removeSuffix(extension)
|
||||||
|
|
||||||
|
var newName by remember { mutableStateOf(nameWithoutExtension) }
|
||||||
|
val isValid = newName.isNotBlank() && !newName.contains("/")
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text("Rename") },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = newName,
|
||||||
|
onValueChange = { newName = it.replace("/", "") },
|
||||||
|
label = { Text("File Name") },
|
||||||
|
suffix = { Text(extension) },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = { onConfirm(newName + extension) },
|
||||||
|
enabled = isValid && newName != nameWithoutExtension
|
||||||
|
) {
|
||||||
|
Text("Rename")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun DeleteConfirmDialog(
|
||||||
|
fileName: String,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onConfirm: () -> Unit
|
||||||
|
) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text("Delete File") },
|
||||||
|
text = {
|
||||||
|
Text("Are you sure you want to delete \"$fileName\"? This action cannot be undone.")
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onConfirm) {
|
||||||
|
Text("Delete", color = MaterialTheme.colorScheme.error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -39,6 +39,7 @@ import kotlinx.coroutines.launch
|
|||||||
import sh.sar.isodroid.data.IsoFile
|
import sh.sar.isodroid.data.IsoFile
|
||||||
import sh.sar.isodroid.data.MountOptions
|
import sh.sar.isodroid.data.MountOptions
|
||||||
import sh.sar.isodroid.ui.components.CreateImgDialog
|
import sh.sar.isodroid.ui.components.CreateImgDialog
|
||||||
|
import sh.sar.isodroid.ui.components.FileContextMenu
|
||||||
import sh.sar.isodroid.ui.components.FileBrowser
|
import sh.sar.isodroid.ui.components.FileBrowser
|
||||||
import sh.sar.isodroid.ui.components.MountDialog
|
import sh.sar.isodroid.ui.components.MountDialog
|
||||||
import sh.sar.isodroid.ui.components.StatusCard
|
import sh.sar.isodroid.ui.components.StatusCard
|
||||||
@@ -58,6 +59,7 @@ fun MainScreen(
|
|||||||
var selectedFile by remember { mutableStateOf<IsoFile?>(null) }
|
var selectedFile by remember { mutableStateOf<IsoFile?>(null) }
|
||||||
var showMountDialog by remember { mutableStateOf(false) }
|
var showMountDialog by remember { mutableStateOf(false) }
|
||||||
var showCreateImgDialog by remember { mutableStateOf(false) }
|
var showCreateImgDialog by remember { mutableStateOf(false) }
|
||||||
|
var contextMenuFile by remember { mutableStateOf<IsoFile?>(null) }
|
||||||
|
|
||||||
// Show error messages
|
// Show error messages
|
||||||
LaunchedEffect(uiState.errorMessage) {
|
LaunchedEffect(uiState.errorMessage) {
|
||||||
@@ -169,6 +171,9 @@ fun MainScreen(
|
|||||||
selectedFile = file
|
selectedFile = file
|
||||||
showMountDialog = true
|
showMountDialog = true
|
||||||
},
|
},
|
||||||
|
onFileLongClick = { file ->
|
||||||
|
contextMenuFile = file
|
||||||
|
},
|
||||||
onNavigateUp = { viewModel.navigateUp() },
|
onNavigateUp = { viewModel.navigateUp() },
|
||||||
canNavigateUp = viewModel.canNavigateUp(),
|
canNavigateUp = viewModel.canNavigateUp(),
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
@@ -214,4 +219,18 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File context menu (long press)
|
||||||
|
contextMenuFile?.let { file ->
|
||||||
|
FileContextMenu(
|
||||||
|
file = file,
|
||||||
|
onDismiss = { contextMenuFile = null },
|
||||||
|
onRename = { newName ->
|
||||||
|
viewModel.renameFile(file, newName)
|
||||||
|
},
|
||||||
|
onDelete = {
|
||||||
|
viewModel.deleteFile(file)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -501,6 +501,40 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun renameFile(file: IsoFile, newName: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
val oldPath = file.path
|
||||||
|
val newPath = "${oldPath.substringBeforeLast("/")}/$newName"
|
||||||
|
|
||||||
|
// Check if new file already exists
|
||||||
|
val checkResult = RootManager.executeCommand("test -f \"$newPath\" && echo exists")
|
||||||
|
if (checkResult.output.trim() == "exists") {
|
||||||
|
_uiState.update { it.copy(errorMessage = "File already exists: $newName") }
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = RootManager.executeCommand("mv \"$oldPath\" \"$newPath\"")
|
||||||
|
if (result.success) {
|
||||||
|
_uiState.update { it.copy(successMessage = "Renamed to $newName") }
|
||||||
|
loadFiles()
|
||||||
|
} else {
|
||||||
|
_uiState.update { it.copy(errorMessage = "Failed to rename file") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deleteFile(file: IsoFile) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
val result = RootManager.executeCommand("rm -f \"${file.path}\"")
|
||||||
|
if (result.success) {
|
||||||
|
_uiState.update { it.copy(successMessage = "Deleted ${file.name}") }
|
||||||
|
loadFiles()
|
||||||
|
} else {
|
||||||
|
_uiState.update { it.copy(errorMessage = "Failed to delete file") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun clearError() {
|
fun clearError() {
|
||||||
_uiState.update { it.copy(errorMessage = null) }
|
_uiState.update { it.copy(errorMessage = null) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user