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 1cc2059..c8fe39d 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 @@ -418,22 +418,33 @@ class HomeFragment : Fragment() { private fun downloadLocalDBData(dialog: DialogInterface) { + var csvDownloaded = false hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> try { - val downloadList = mutableListOf() + if (!csvDownloaded) { - userDataList.forEach { userData -> - if (!userData.isCSVCreated) { - downloadList.add(userData) // Add the userData to downloadList - } - } - 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() + val downloadList = mutableListOf() + + userDataList.forEach { userData -> +// if (!userData.isCSVCreated) { + downloadList.add(userData) // Add the userData to downloadList +// } + } + + if (downloadList.isNotEmpty()) { + // Call ViewModel function to create CSV with filtered data + hemoCubeViewModel.createCSV(downloadList, requireContext()) + csvDownloaded = true + 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()