Restore behavior when saving PDF for both success and failure

This commit is contained in:
Pierre-Yves Nicolas
2025-11-26 18:58:55 +01:00
parent 3f10a1cd55
commit 8c9be73022
2 changed files with 5 additions and 11 deletions

View File

@@ -116,11 +116,9 @@ class MainActivity : ComponentActivity() {
exportViewModel.onRequestPdfSave(context, homeViewModel)
}
}
is ExportEvent.ShowToast -> {
Toast.makeText(context, event.message, Toast.LENGTH_SHORT).show()
}
ExportEvent.PdfSaved -> {
Toast.makeText(context, "PDF saved", Toast.LENGTH_SHORT).show()
is ExportEvent.SaveError -> {
val text = getString(R.string.error_save)
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
}
}

View File

@@ -42,8 +42,7 @@ private const val PDF_MIME_TYPE = "application/pdf"
sealed interface ExportEvent {
data object RequestSavePdf : ExportEvent
data class ShowToast(val message: String) : ExportEvent
data object PdfSaved : ExportEvent
data object SaveError : ExportEvent
}
class ExportViewModel(container: AppContainer): ViewModel() {
@@ -153,12 +152,9 @@ class ExportViewModel(container: AppContainer): ViewModel() {
targetFile.absolutePath,
pdf.pageCount
)
_events.emit(ExportEvent.PdfSaved)
} catch (e: Exception) {
logger.e("FairScan", "Failed to save PDF", e)
_events.emit(ExportEvent.ShowToast("Error while saving PDF"))
_events.emit(ExportEvent.SaveError)
}
}