changes related to csv added
This commit is contained in:
@@ -418,22 +418,33 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
|
|
||||||
private fun downloadLocalDBData(dialog: DialogInterface) {
|
private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||||
|
var csvDownloaded = false
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
try {
|
try {
|
||||||
val downloadList = mutableListOf<HemoCubeTestData>()
|
if (!csvDownloaded) {
|
||||||
|
|
||||||
userDataList.forEach { userData ->
|
|
||||||
if (!userData.isCSVCreated) {
|
|
||||||
downloadList.add(userData) // Add the userData to downloadList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (downloadList.isNotEmpty()) {
|
val downloadList = mutableListOf<HemoCubeTestData>()
|
||||||
// Call ViewModel function to create CSV with filtered data
|
|
||||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
userDataList.forEach { userData ->
|
||||||
Toast.makeText(requireContext(), "CSV file downloaded successfully", Toast.LENGTH_SHORT).show()
|
// if (!userData.isCSVCreated) {
|
||||||
} else {
|
downloadList.add(userData) // Add the userData to downloadList
|
||||||
Toast.makeText(requireContext(), "No data to download", Toast.LENGTH_SHORT).show()
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|||||||
Reference in New Issue
Block a user