Skip to content

Commit

Permalink
fixed minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishksahu committed Aug 29, 2024
1 parent c65b10d commit 8830ebb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class MainActivityViewModel(private val application: Application) : AndroidViewM
ops.deleteFile(item)
}
}
clearSelection()
getItems()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BottomAppBar(private val activity: MainnActivity) {
private val createFolderShowDialog = mutableStateOf(false)
private val createNoteShowDialog = mutableStateOf(false)
private val renameShowDialog = mutableStateOf(false)
private val namePattern = Regex("[~`!@#\$%^&*()+=|\\\\:;\"'>?/<,\\[\\]{}]")
private var name: String = ""

@Composable
Expand Down Expand Up @@ -137,8 +138,8 @@ class BottomAppBar(private val activity: MainnActivity) {
)
if (showDialog.value) {
Prompt(
onConfirmation = {
if (name.isNotEmpty()) {
onConfirmation = { isValid ->
if (name.isNotEmpty() && isValid) {
try {
activity.viewModel.createFolder(name)
} catch (e: Exception) {
Expand Down Expand Up @@ -183,8 +184,8 @@ class BottomAppBar(private val activity: MainnActivity) {
)
if (showDialog.value) {
Prompt(
onConfirmation = {
if (name.isNotEmpty()) {
onConfirmation = { isValid ->
if (name.isNotEmpty() && isValid) {
val noteFile = activity.viewModel.createTextNote(name)
val documentViewIntent = Intent(
activity.application, TextDocumentView::class.java
Expand Down Expand Up @@ -294,8 +295,8 @@ class BottomAppBar(private val activity: MainnActivity) {
)
if (showDialog.value) {
Prompt(
onConfirmation = {
if (name.isNotEmpty()) {
onConfirmation = { isValid ->
if (name.isNotEmpty() && isValid) {

if (!activity.viewModel.renameFile(name)) {
showMessage(activity.getString(R.string.generic_error))
Expand Down Expand Up @@ -525,11 +526,13 @@ class BottomAppBar(private val activity: MainnActivity) {

@Composable
fun Prompt(
onConfirmation: () -> Unit, onDismiss: () -> Unit, dialogTitle: String, okBtnText: String
onConfirmation: (Boolean) -> Unit,
onDismiss: () -> Unit,
dialogTitle: String,
okBtnText: String
) {
val textFieldContent = remember { mutableStateOf(TextFieldValue(name)) }
val isValid = remember { mutableStateOf(true) }
val namePattern = Regex("[~`!@#\$%^&*()+=|\\\\:;\"'>?/<,\\[\\]{}]")

AlertDialog(title = {
Text(text = dialogTitle)
Expand Down Expand Up @@ -573,7 +576,7 @@ class BottomAppBar(private val activity: MainnActivity) {
onDismiss()
textFieldContent.value = TextFieldValue("")
}, confirmButton = {
TextButton(onClick = { onConfirmation() }) {
TextButton(onClick = { onConfirmation(isValid.value) }) {
Text(text = okBtnText)
}
})
Expand Down

0 comments on commit 8830ebb

Please sign in to comment.