From a96f1507991dc17a8cbb2f7c201501df6cfbac41 Mon Sep 17 00:00:00 2001 From: Paul Woitaschek Date: Tue, 20 Sep 2022 23:02:53 +0200 Subject: [PATCH] Show exactly, which file will be deleted. Fixes #1500 --- .../bookOverview/deleteBook/DeleteBookDialog.kt | 6 ++++++ .../bookOverview/deleteBook/DeleteBookViewModel.kt | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookDialog.kt b/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookDialog.kt index ad80b3eda..cfadfa092 100644 --- a/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookDialog.kt +++ b/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookDialog.kt @@ -3,7 +3,9 @@ package voice.bookOverview.deleteBook 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.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button @@ -53,6 +55,10 @@ internal fun DeleteBookDialog( text = { Column { Text(stringResource(id = R.string.delete_book_dialog_content)) + + Spacer(modifier = Modifier.heightIn(8.dp)) + Text(viewState.fileToDelete, style = MaterialTheme.typography.bodyLarge) + Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier diff --git a/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookViewModel.kt b/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookViewModel.kt index 1b6393f79..de4c39e04 100644 --- a/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookViewModel.kt +++ b/bookOverview/src/main/kotlin/voice/bookOverview/deleteBook/DeleteBookViewModel.kt @@ -37,9 +37,22 @@ constructor( override suspend fun onItemClicked(bookId: BookId, item: BottomSheetItem) { if (item != BottomSheetItem.DeleteBook) return + _state.value = DeleteBookViewState( id = bookId, deleteCheckBoxChecked = false, + fileToDelete = bookId.toUri().pathSegments + .toMutableList() + .also { segments -> + if (segments.firstOrNull() == "document") { + segments.removeFirst() + } + val path = segments.firstOrNull() + if (path != null) { + segments[0] = path.removePrefix("primary:") + } + } + .joinToString(separator = "/"), ) } @@ -71,6 +84,7 @@ constructor( data class DeleteBookViewState( val id: BookId, val deleteCheckBoxChecked: Boolean, + val fileToDelete: String, ) { val confirmButtonEnabled = deleteCheckBoxChecked