@@ -17,18 +17,23 @@ package org.mydomain.myscan.view
1717import android.content.Context
1818import android.text.format.Formatter
1919import androidx.compose.foundation.layout.Arrangement
20+ import androidx.compose.foundation.layout.Box
2021import androidx.compose.foundation.layout.Column
2122import androidx.compose.foundation.layout.Row
2223import androidx.compose.foundation.layout.Spacer
2324import androidx.compose.foundation.layout.fillMaxWidth
2425import androidx.compose.foundation.layout.height
2526import androidx.compose.foundation.layout.padding
27+ import androidx.compose.foundation.layout.size
2628import androidx.compose.foundation.layout.width
2729import androidx.compose.material.icons.Icons
2830import androidx.compose.material.icons.automirrored.filled.OpenInNew
31+ import androidx.compose.material.icons.filled.Close
32+ import androidx.compose.material.icons.filled.PictureAsPdf
2933import androidx.compose.material3.Button
3034import androidx.compose.material3.ExperimentalMaterial3Api
3135import androidx.compose.material3.Icon
36+ import androidx.compose.material3.IconButton
3237import androidx.compose.material3.LinearProgressIndicator
3338import androidx.compose.material3.MaterialTheme
3439import androidx.compose.material3.ModalBottomSheet
@@ -42,6 +47,7 @@ import androidx.compose.runtime.getValue
4247import androidx.compose.runtime.mutableStateOf
4348import androidx.compose.runtime.remember
4449import androidx.compose.runtime.setValue
50+ import androidx.compose.ui.Alignment
4551import androidx.compose.ui.Modifier
4652import androidx.compose.ui.platform.LocalContext
4753import androidx.compose.ui.tooling.preview.Preview
@@ -57,7 +63,7 @@ import java.util.Locale
5763
5864@OptIn(ExperimentalMaterial3Api ::class )
5965@Composable
60- fun PdfGenerationDialogWrapper (
66+ fun PdfGenerationBottomSheetWrapper (
6167 onDismiss : () -> Unit ,
6268 pdfActions : PdfGenerationActions ,
6369 modifier : Modifier = Modifier ,
@@ -105,9 +111,17 @@ fun PdfGenerationBottomSheet(
105111 Column (
106112 modifier = Modifier
107113 .fillMaxWidth()
108- .padding(24 .dp)
114+ .padding(top = 0 .dp, start = 16 .dp, end = 16 .dp, bottom = 16 .dp)
109115 ) {
110- Text (" Generate PDF" , style = MaterialTheme .typography.headlineSmall)
116+ CloseButton (onDismiss)
117+
118+ Row {
119+ Icon (Icons .Default .PictureAsPdf , contentDescription = " PDF" ,
120+ modifier = Modifier
121+ .size(34 .dp)
122+ .padding(end = 8 .dp))
123+ Text (" Generate PDF" , style = MaterialTheme .typography.headlineSmall)
124+ }
111125
112126 Spacer (Modifier .height(16 .dp))
113127
@@ -135,11 +149,6 @@ fun PdfGenerationBottomSheet(
135149 horizontalArrangement = Arrangement .spacedBy(8 .dp),
136150 modifier = Modifier .fillMaxWidth()
137151 ) {
138- OutlinedButton (
139- onClick = onDismiss,
140- modifier = Modifier .weight(1f )
141- ) { Text (" Close" ) }
142-
143152 OutlinedButton (
144153 onClick = onShare,
145154 enabled = pdf != null ,
@@ -169,6 +178,21 @@ fun PdfGenerationBottomSheet(
169178 }
170179}
171180
181+ @Composable
182+ private fun CloseButton (onDismiss : () -> Unit ) {
183+ Box (Modifier .fillMaxWidth()) {
184+ IconButton (
185+ onClick = onDismiss,
186+ modifier = Modifier .align(Alignment .TopEnd )
187+ ) {
188+ Icon (
189+ imageVector = Icons .Default .Close ,
190+ contentDescription = " Close"
191+ )
192+ }
193+ }
194+ }
195+
172196fun defaultFilename (): String {
173197 val timestamp = SimpleDateFormat (" yyyyMMdd_HHmmss" , Locale .getDefault()).format(Date ())
174198 return " scan_$timestamp .pdf"
@@ -182,29 +206,40 @@ fun formatFileSize(sizeInBytes: Long?, context: Context): String {
182206@Preview(showBackground = true )
183207@Composable
184208fun PreviewPdfGenerationDialogDuringGeneration () {
185- MyScanTheme {
186- PdfGenerationBottomSheet (
187- filename = " scan_20250702_174042.pdf" ,
188- uiState = PdfGenerationUiState (isGenerating = true ),
189- onFilenameChange = {},
190- onDismiss = {},
191- onShare = {},
192- onSave = {},
193- onOpen = {},
194- )
195- }
209+ PreviewToCustomize (
210+ uiState = PdfGenerationUiState (isGenerating = true )
211+ )
196212}
197213
198214@Preview(showBackground = true )
199215@Composable
200216fun PreviewPdfGenerationDialogAfterGeneration () {
217+ PreviewToCustomize (
218+ uiState = PdfGenerationUiState (
219+ isGenerating = false ,
220+ generatedPdf = GeneratedPdf (" file://fake.pdf" .toUri(), 442897L , 3 )
221+ )
222+ )
223+ }
224+
225+ @Preview(showBackground = true )
226+ @Composable
227+ fun PreviewPdfGenerationDialogAfterSave () {
228+ PreviewToCustomize (
229+ uiState = PdfGenerationUiState (
230+ isGenerating = false ,
231+ generatedPdf = GeneratedPdf (" file://fake.pdf" .toUri(), 442897L , 3 ),
232+ savedFileUri = " file:///fake" .toUri()
233+ )
234+ )
235+ }
236+
237+ @Composable
238+ fun PreviewToCustomize (uiState : PdfGenerationUiState ) {
201239 MyScanTheme {
202240 PdfGenerationBottomSheet (
203241 filename = " scan_20250702_174042.pdf" ,
204- uiState = PdfGenerationUiState (
205- isGenerating = false ,
206- generatedPdf = GeneratedPdf (" file://fake.pdf" .toUri(), 42897L , 3 )
207- ),
242+ uiState = uiState,
208243 onFilenameChange = {},
209244 onDismiss = {},
210245 onShare = {},
0 commit comments