color of download button changed, and try catch block added for download function of csv

This commit is contained in:
Mariya
2023-12-15 16:43:27 +05:30
parent 9093caa9df
commit d25a1bb08a
2 changed files with 16 additions and 11 deletions

View File

@@ -419,6 +419,7 @@ class HomeFragment : Fragment() {
private fun downloadLocalDBData(dialog: DialogInterface) {
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
try {
val downloadList = mutableListOf<HemoCubeTestData>()
userDataList.forEach { userData ->
@@ -427,15 +428,19 @@ class HomeFragment : Fragment() {
}
}
if (downloadList.isNotEmpty()) {
// Call ViewModel function to create CSV with filtered data
hemoCubeViewModel.createCSV(downloadList, requireContext())
Toast.makeText(requireContext(), "CSV file downloaded successfully", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(requireContext(), "CSV file downloaing failed", Toast.LENGTH_SHORT).show()
if (downloadList.isNotEmpty()) {
// Call ViewModel function to create CSV with filtered data
hemoCubeViewModel.createCSV(downloadList, requireContext())
Toast.makeText(requireContext(), "CSV file downloaded successfully", Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(requireContext(), "No data to download", Toast.LENGTH_SHORT).show()
}
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT).show()
} finally {
dialog.dismiss()
}
dialog.dismiss()
}
}