changed reverted back for csv option for ADMIN

This commit is contained in:
Mariya
2024-03-21 20:53:48 +05:30
parent 614192c04c
commit 29115786fa
2 changed files with 88 additions and 81 deletions

View File

@@ -26,10 +26,10 @@ interface HemoCubeDao {
@Query("SELECT * from hemo_cube_test_table") @Query("SELECT * from hemo_cube_test_table")
fun getAll(): LiveData<List<HemoCubeTestData>> fun getAll(): LiveData<List<HemoCubeTestData>>
@Query("SELECT * from hemo_cube_test_table WHERE molbioFlag=false") @Query("SELECT * from hemo_cube_test_table WHERE molbioFlag=0")
fun getMolbioPending(): List<HemoCubeTestData> fun getMolbioPending(): List<HemoCubeTestData>
@Query("SELECT * from hemo_cube_test_table WHERE localFlag=false") @Query("SELECT * from hemo_cube_test_table WHERE localFlag=0")
fun getFirebasePending():List<HemoCubeTestData> fun getFirebasePending():List<HemoCubeTestData>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)

View File

@@ -148,6 +148,8 @@ class HomeFragment : Fragment() {
userData.forEach { userData.forEach {
if (it.testStatus == false) { if (it.testStatus == false) {
userList.add(it) userList.add(it)
}else if(it.testStatus == true){
userList.removeAll(userData)
} }
} }
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
@@ -272,27 +274,28 @@ class HomeFragment : Fragment() {
binding.uploadData.setOnClickListener { binding.uploadData.setOnClickListener {
// showUploadDialog(requireContext()) // showUploadDialog(requireContext())
} }
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData -> hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
// if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
// val btnSaveLocalVisibility = val btnSaveLocalVisibility =
// if (userData.any { it.testStatus == true }) View.GONE else View.GONE if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE
// binding.downloadCSV.visibility = btnSaveLocalVisibility
// binding.downloadCSV.visibility = btnSaveLocalVisibility binding.downloadCSV.setOnClickListener {
// if (btnSaveLocalVisibility == View.VISIBLE) {
// binding.downloadCSV.setOnClickListener { // Execute the action when the button is visible (testStatus is true for at least one user)
// if (btnSaveLocalVisibility == View.VISIBLE) { showDownloadDialog(requireContext())
// // Execute the action when the button is visible (testStatus is true for at least one user) } else {
// showDownloadDialog(requireContext()) // Handle the case when the button is not visible
// } else { Toast.makeText(
// // Handle the case when the button is not visible requireContext(),
// Toast.makeText( "No test details stored locally",
// requireContext(), Toast.LENGTH_SHORT
// "No test details stored locally", ).show()
// Toast.LENGTH_SHORT }
// ).show() }
// } }else{
// } binding.downloadCSV.visibility = View.GONE
// } }
}
binding.btnNewKit.setOnClickListener { binding.btnNewKit.setOnClickListener {
@@ -949,11 +952,15 @@ class HomeFragment : Fragment() {
} }
private fun checkUnprocessedCSVData() { private fun checkUnprocessedCSVData() {
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
// val downloadDataVisibility = if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
// if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE val downloadDataVisibility =
// binding.downloadCSV.visibility = downloadDataVisibility if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.VISIBLE else View.GONE
// } binding.downloadCSV.visibility = downloadDataVisibility
}else{
binding.downloadCSV.visibility = View.GONE
}
}
} }
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData { private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
@@ -987,22 +994,22 @@ class HomeFragment : Fragment() {
dialog.show() dialog.show()
} }
// private fun showDownloadDialog(context: Context) { private fun showDownloadDialog(context: Context) {
// val builder = AlertDialog.Builder(context) val builder = AlertDialog.Builder(context)
// builder.setTitle(R.string.download_db_registration_title) builder.setTitle(R.string.download_db_registration_title)
// builder.setMessage(R.string.download_db_registration_message) builder.setMessage(R.string.download_db_registration_message)
//
// builder.setPositiveButton(R.string.downloadcsv) { dialog, _ -> builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
// downloadLocalDBData(dialog) downloadLocalDBData(dialog)
// } }
//
// builder.setNegativeButton(R.string.cancel) { dialog, _ -> builder.setNegativeButton(R.string.cancel) { dialog, _ ->
// dialog.dismiss() dialog.dismiss()
// } }
//
// val dialog = builder.create() val dialog = builder.create()
// dialog.show() dialog.show()
// } }
private fun uploadLocalDBData(dialog: DialogInterface) { private fun uploadLocalDBData(dialog: DialogInterface) {
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> // viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
@@ -1064,27 +1071,27 @@ class HomeFragment : Fragment() {
} }
} }
// private fun downloadLocalDBData(dialog: DialogInterface) { private fun downloadLocalDBData(dialog: DialogInterface) {
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList -> hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
// val downloadList = mutableListOf<HemoCubeTestData>() val downloadList = mutableListOf<HemoCubeTestData>()
//
// userDataList.forEach { userData -> userDataList.forEach { userData ->
// 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())
// Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show()
// } else { } else {
// Toast.makeText(requireContext(), "Failed", Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), "", Toast.LENGTH_SHORT).show()
// } }
//
// dialog.dismiss() dialog.dismiss()
// } }
// } }
private fun deleteIncompleteRegistrations(userDataList: List<UserData>) { private fun deleteIncompleteRegistrations(userDataList: List<UserData>) {
userDataList.forEach { userData -> userDataList.forEach { userData ->
@@ -1120,22 +1127,22 @@ class HomeFragment : Fragment() {
} }
} }
private fun showDownloadDialog(context: Context) { // private fun showDownloadDialog(context: Context) {
val builder = AlertDialog.Builder(context) // val builder = AlertDialog.Builder(context)
builder.setTitle(R.string.download_db_registration_title) // builder.setTitle(R.string.download_db_registration_title)
builder.setMessage(R.string.download_db_registration_message) // builder.setMessage(R.string.download_db_registration_message)
//
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ -> // builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
// downloadLocalDBData(dialog) //// downloadLocalDBData(dialog)
} // }
//
builder.setNegativeButton(R.string.cancel) { dialog, _ -> // builder.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss() // dialog.dismiss()
} // }
//
val dialog = builder.create() // val dialog = builder.create()
dialog.show() // dialog.show()
} // }
// private fun downloadLocalDBData(dialog: DialogInterface) { // private fun downloadLocalDBData(dialog: DialogInterface) {
// var csvDownloaded = false // var csvDownloaded = false