Restore behavior when saving PDF for both success and failure
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user