changes related to csv added

This commit is contained in:
Mariya
2023-12-19 15:11:09 +05:30
parent d25a1bb08a
commit 762cbcbe44

View File

@@ -418,22 +418,33 @@ class HomeFragment : Fragment() {
private fun downloadLocalDBData(dialog: DialogInterface) {
var csvDownloaded = false
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
try {
val downloadList = mutableListOf<HemoCubeTestData>()
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<HemoCubeTestData>()
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()