Improve style of PdfGenerationBottomSheet

This commit is contained in:
Pierre-Yves Nicolas
2025-07-05 20:55:35 +02:00
parent b6177700f7
commit 70cb3cfdb4
2 changed files with 139 additions and 66 deletions

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2025 Pierre-Yves Nicolas
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.mydomain.myscan.view
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
@Composable
fun MainActionButton(
onClick: () -> Unit,
text: String,
icon: ImageVector,
modifier: Modifier = Modifier,
iconDescription: String? = null,
enabled: Boolean = true,
) {
Button(onClick = onClick, enabled = enabled, modifier = modifier) {
Icon(icon, contentDescription = iconDescription)
Spacer(Modifier.width(8.dp))
Text(text)
}
}

View File

@@ -16,6 +16,7 @@ package org.mydomain.myscan.view
import android.content.Context import android.content.Context
import android.text.format.Formatter import android.text.format.Formatter
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@@ -25,19 +26,18 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.PictureAsPdf import androidx.compose.material.icons.filled.PictureAsPdf
import androidx.compose.material3.Button import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@@ -108,6 +108,7 @@ fun PdfGenerationBottomSheet(
onSave: () -> Unit, onSave: () -> Unit,
onOpen: () -> Unit, onOpen: () -> Unit,
) { ) {
Column() {
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -116,10 +117,12 @@ fun PdfGenerationBottomSheet(
CloseButton(onDismiss) CloseButton(onDismiss)
Row { Row {
Icon(Icons.Default.PictureAsPdf, contentDescription = "PDF", Icon(
Icons.Default.PictureAsPdf, contentDescription = "PDF",
modifier = Modifier modifier = Modifier
.size(34.dp) .size(34.dp)
.padding(end = 8.dp)) .padding(end = 8.dp)
)
Text("Generate PDF", style = MaterialTheme.typography.headlineSmall) Text("Generate PDF", style = MaterialTheme.typography.headlineSmall)
} }
@@ -145,36 +148,65 @@ fun PdfGenerationBottomSheet(
Spacer(Modifier.height(24.dp)) Spacer(Modifier.height(24.dp))
MainActions(pdf, onShare, onSave)
}
if (uiState.savedFileUri != null) {
SavePdfBar(onOpen)
}
}
}
@Composable
private fun MainActions(
pdf: GeneratedPdf?,
onShare: () -> Unit,
onSave: () -> Unit,
) {
Row( Row(
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
OutlinedButton( MainActionButton(
onClick = onShare, onClick = onShare,
enabled = pdf != null, enabled = pdf != null,
icon = Icons.Default.Share,
iconDescription = "Share",
text = "Share",
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
) { Text("Share") } )
MainActionButton(
OutlinedButton(
onClick = onSave, onClick = onSave,
enabled = pdf != null, enabled = pdf != null,
icon = Icons.Default.Download,
iconDescription = "Save",
text = "Save",
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
) { Text("Save") } )
} }
if (uiState.savedFileUri != null) { }
@Composable
private fun SavePdfBar(onOpen: () -> Unit) {
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Absolute.SpaceBetween,
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.surfaceVariant)
.padding(vertical = 8.dp, horizontal = 16.dp),
) {
Text( Text(
text = "PDF saved to Downloads", text = "PDF saved to Downloads",
style = MaterialTheme.typography.bodyMedium style = MaterialTheme.typography.bodyMedium
) )
Spacer(modifier = Modifier.height(8.dp)) MainActionButton(
Button(onClick = onOpen) { onClick = onOpen,
Icon(Icons.AutoMirrored.Filled.OpenInNew, contentDescription = null) text = "Open",
Spacer(Modifier.width(8.dp)) icon = Icons.AutoMirrored.Filled.OpenInNew,
Text("Open") )
}
}
} }
} }