diff --git a/app/src/debug/res/drawable/downloads.xml b/app/src/debug/res/drawable/downloads.xml index 772735f..37f8230 100644 --- a/app/src/debug/res/drawable/downloads.xml +++ b/app/src/debug/res/drawable/downloads.xml @@ -1,5 +1,5 @@ - - - + + \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt index 8dcf4dd..1cc2059 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/HomeFragment.kt @@ -419,6 +419,7 @@ class HomeFragment : Fragment() { private fun downloadLocalDBData(dialog: DialogInterface) { hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> + try { val downloadList = mutableListOf() 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() } }