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)
|
exportViewModel.onRequestPdfSave(context, homeViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ExportEvent.ShowToast -> {
|
is ExportEvent.SaveError -> {
|
||||||
Toast.makeText(context, event.message, Toast.LENGTH_SHORT).show()
|
val text = getString(R.string.error_save)
|
||||||
}
|
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
|
||||||
ExportEvent.PdfSaved -> {
|
|
||||||
Toast.makeText(context, "PDF saved", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ private const val PDF_MIME_TYPE = "application/pdf"
|
|||||||
|
|
||||||
sealed interface ExportEvent {
|
sealed interface ExportEvent {
|
||||||
data object RequestSavePdf : ExportEvent
|
data object RequestSavePdf : ExportEvent
|
||||||
data class ShowToast(val message: String) : ExportEvent
|
data object SaveError : ExportEvent
|
||||||
data object PdfSaved : ExportEvent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExportViewModel(container: AppContainer): ViewModel() {
|
class ExportViewModel(container: AppContainer): ViewModel() {
|
||||||
@@ -153,12 +152,9 @@ class ExportViewModel(container: AppContainer): ViewModel() {
|
|||||||
targetFile.absolutePath,
|
targetFile.absolutePath,
|
||||||
pdf.pageCount
|
pdf.pageCount
|
||||||
)
|
)
|
||||||
|
|
||||||
_events.emit(ExportEvent.PdfSaved)
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.e("FairScan", "Failed to save PDF", e)
|
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