Improve UX feedback during export preparation
This commit is contained in:
@@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
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
|
||||||
@@ -37,6 +38,7 @@ import androidx.compose.material.icons.filled.Download
|
|||||||
import androidx.compose.material.icons.filled.Share
|
import androidx.compose.material.icons.filled.Share
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
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
|
||||||
@@ -208,7 +210,19 @@ private fun TextFieldAndPdfInfos(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
if (uiState.isGenerating) {
|
if (uiState.isGenerating) {
|
||||||
Text(stringResource(R.string.creating_export), fontStyle = FontStyle.Italic)
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
strokeWidth = 2.dp
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.creating_export),
|
||||||
|
fontStyle = FontStyle.Italic
|
||||||
|
)
|
||||||
|
}
|
||||||
} else if (result != null) {
|
} else if (result != null) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val formattedFileSize = formatFileSize(result.sizeInBytes, context)
|
val formattedFileSize = formatFileSize(result.sizeInBytes, context)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class ExportViewModel(container: AppContainer, val imageRepository: ImageReposit
|
|||||||
preparationJob = viewModelScope.launch {
|
preparationJob = viewModelScope.launch {
|
||||||
val exportQuality = settingsRepository.exportQuality.first()
|
val exportQuality = settingsRepository.exportQuality.first()
|
||||||
exportFormat = settingsRepository.exportFormat.first()
|
exportFormat = settingsRepository.exportFormat.first()
|
||||||
_uiState.update { it.copy(format = exportFormat) }
|
_uiState.update { it.copy(format = exportFormat, isGenerating = true) }
|
||||||
try {
|
try {
|
||||||
val t1 = System.currentTimeMillis()
|
val t1 = System.currentTimeMillis()
|
||||||
val result = if (exportFormat == ExportFormat.JPEG) {
|
val result = if (exportFormat == ExportFormat.JPEG) {
|
||||||
@@ -108,7 +108,8 @@ class ExportViewModel(container: AppContainer, val imageRepository: ImageReposit
|
|||||||
it.copy(isGenerating = false, result = result)
|
it.copy(isGenerating = false, result = result)
|
||||||
}
|
}
|
||||||
val t2 = System.currentTimeMillis()
|
val t2 = System.currentTimeMillis()
|
||||||
Log.i("Export", "Generation time: ${t2-t1} ms")
|
val pageCount = result.pageCount
|
||||||
|
Log.i("Export", "Generation: $pageCount pages, $exportQuality, ${t2-t1} ms")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
val message = "Failed to prepare $exportFormat export"
|
val message = "Failed to prepare $exportFormat export"
|
||||||
logger.e("FairScan", message, e)
|
logger.e("FairScan", message, e)
|
||||||
|
|||||||
Reference in New Issue
Block a user