Fixed issued related to csv file downloading
This commit is contained in:
@@ -11,7 +11,7 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|||||||
import com.google.android.datatransport.runtime.dagger.Provides
|
import com.google.android.datatransport.runtime.dagger.Provides
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 4, exportSchema = false)
|
@Database(entities = [UserData::class, HemoCubeTestData::class, DeviceData::class], version = 5, exportSchema = false)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class MyDatabase : RoomDatabase() {
|
abstract class MyDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UserDao
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class HomeFragment : Fragment() {
|
|||||||
adapter = OfflineUserListAdapter(binding.root, batLevel)
|
adapter = OfflineUserListAdapter(binding.root, batLevel)
|
||||||
adapter.differ.submitList(userList)
|
adapter.differ.submitList(userList)
|
||||||
binding.rvOrderOffline.adapter = adapter
|
binding.rvOrderOffline.adapter = adapter
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
||||||
@@ -118,12 +119,31 @@ class HomeFragment : Fragment() {
|
|||||||
binding.btnLogout.setOnClickListener {
|
binding.btnLogout.setOnClickListener {
|
||||||
logoutUser(requireContext())
|
logoutUser(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
binding.uploadData.setOnClickListener {
|
binding.uploadData.setOnClickListener {
|
||||||
showUploadDialog(requireContext())
|
showUploadDialog(requireContext())
|
||||||
}
|
}
|
||||||
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||||
|
|
||||||
binding.btnSaveLocal.setOnClickListener {
|
val btnSaveLocalVisibility =
|
||||||
showDownloadDialog(requireContext())
|
if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
binding.btnSaveLocal.visibility = btnSaveLocalVisibility
|
||||||
|
|
||||||
|
binding.btnSaveLocal.setOnClickListener {
|
||||||
|
if (btnSaveLocalVisibility == View.VISIBLE) {
|
||||||
|
// Execute the action when the button is visible (testStatus is true for at least one user)
|
||||||
|
showDownloadDialog(requireContext())
|
||||||
|
} else {
|
||||||
|
// Handle the case when the button is not visible
|
||||||
|
Toast.makeText(
|
||||||
|
requireContext(),
|
||||||
|
"No test details stored locally",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
binding.btnNewKit.setOnClickListener {
|
binding.btnNewKit.setOnClickListener {
|
||||||
with(sharedPreference.edit()) {
|
with(sharedPreference.edit()) {
|
||||||
@@ -311,7 +331,9 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
val uploadDataVisibility =
|
val uploadDataVisibility =
|
||||||
if (userDataList.any { !it.localFlag && it.testStatus == true}) View.VISIBLE else View.GONE
|
if (userDataList.any {
|
||||||
|
!it.localFlag && it.testStatus == true})
|
||||||
|
View.VISIBLE else View.GONE
|
||||||
binding.uploadData.visibility = uploadDataVisibility
|
binding.uploadData.visibility = uploadDataVisibility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -427,25 +449,32 @@ class HomeFragment : Fragment() {
|
|||||||
val downloadList = mutableListOf<HemoCubeTestData>()
|
val downloadList = mutableListOf<HemoCubeTestData>()
|
||||||
|
|
||||||
userDataList.forEach { userData ->
|
userDataList.forEach { userData ->
|
||||||
|
if(userData.testStatus == true) {
|
||||||
// if (!userData.isCSVCreated) {
|
// if (!userData.isCSVCreated) {
|
||||||
downloadList.add(userData) // Add the userData to downloadList
|
downloadList.add(userData) // Add the userData to downloadList
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadList.isNotEmpty()) {
|
if (downloadList.isNotEmpty()) {
|
||||||
// Call ViewModel function to create CSV with filtered data
|
// Call ViewModel function to create CSV with filtered data
|
||||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||||
csvDownloaded = true
|
csvDownloaded = true
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
"CSV file downloaded successfully",
|
"CSV file downloaded successfully",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(requireContext(), "No data to download", Toast.LENGTH_SHORT)
|
Toast.makeText(
|
||||||
.show()
|
requireContext(),
|
||||||
|
"No data to download",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT).show()
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
testDetails?.deviceRatio = DataHolder.hemoCubeTestData?.deviceRatio
|
||||||
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
testDetails?.calculatedRatio = DataHolder.hemoCubeTestData?.calculatedRatio
|
||||||
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
testDetails?.coefficients = DataHolder.hemoCubeTestData?.coefficients
|
||||||
|
testDetails?.incubationTime = DataHolder.hemoCubeTestData?.incubationTime.toString()
|
||||||
testDetails?.name = DataHolder.hemoCubeTestData?.name.toString()
|
testDetails?.name = DataHolder.hemoCubeTestData?.name.toString()
|
||||||
testDetails?.birthYear = DataHolder.hemoCubeTestData?.birthYear.toString()
|
testDetails?.birthYear = DataHolder.hemoCubeTestData?.birthYear.toString()
|
||||||
testDetails?.userImageURL = DataHolder.hemoCubeTestData?.userImageURL.toString()
|
testDetails?.userImageURL = DataHolder.hemoCubeTestData?.userImageURL.toString()
|
||||||
|
|||||||
@@ -107,6 +107,7 @@
|
|||||||
android:layout_height="30dp"
|
android:layout_height="30dp"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="10dp"
|
||||||
android:src="@drawable/downloads"
|
android:src="@drawable/downloads"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/rv_order_offline"
|
app:layout_constraintBottom_toBottomOf="@+id/rv_order_offline"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user