Skip to content

Commit

Permalink
#112: Fix crash on empty file name (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubertm authored Mar 12, 2024
1 parent 55f9025 commit 38e7e24
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import dev.arkbuilders.arkretouch.presentation.theme.Gray
import dev.arkbuilders.arkretouch.presentation.utils.askWritePermissions
import dev.arkbuilders.arkretouch.presentation.utils.getActivity
import dev.arkbuilders.arkretouch.presentation.utils.isWritePermGranted
import dev.arkbuilders.arkretouch.presentation.utils.toast
import java.nio.file.Path

@Composable
Expand Down Expand Up @@ -364,6 +365,9 @@ private fun BoxScope.TopMenu(
SavePathDialog(
initialImagePath = imagePath,
fragmentManager = fragmentManager,
onEmptyFileName = {
context.toast(R.string.ark_retouch_file_name_missing)
},
onDismissClick = { viewModel.showSavePathDialog = false },
onPositiveClick = { savePath ->
viewModel.saveImage(savePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import kotlin.streams.toList
fun SavePathDialog(
initialImagePath: Path?,
fragmentManager: FragmentManager,
onEmptyFileName: () -> Unit,
onDismissClick: () -> Unit,
onPositiveClick: (Path) -> Unit
) {
Expand Down Expand Up @@ -128,6 +129,10 @@ fun SavePathDialog(
value = name,
onValueChange = {
name = it
if (name.isEmpty()) {
onEmptyFileName()
return@OutlinedTextField
}
currentPath?.let { path ->
imagePath = path.resolve(name)
showOverwriteCheckbox.value = Files.list(path).toList()
Expand Down Expand Up @@ -175,7 +180,11 @@ fun SavePathDialog(
Button(
modifier = Modifier.padding(5.dp),
onClick = {
if (currentPath != null && name != null)
if (name.isEmpty()) {
onEmptyFileName()
return@Button
}
if (currentPath != null)
onPositiveClick(currentPath!!.resolve(name))
}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerEvent
Expand Down Expand Up @@ -98,3 +100,7 @@ fun PointerEvent.calculateRotationFromOneFingerGesture(
}
return angleDelta.toFloat()
}

fun Context.toast(@StringRes stringId: Int) {
Toast.makeText(this, getString(stringId), Toast.LENGTH_SHORT).show()
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
<string name="height_empty">Please enter height</string>
<string name="blur_intensity">Intensity</string>
<string name="blur_size">Size</string>
<string name="ark_retouch_file_name_missing">Please provide file name</string>
</resources>

0 comments on commit 38e7e24

Please sign in to comment.