From e1e8e4ebb2dc30c672499b84e9d16dc2fda8b508 Mon Sep 17 00:00:00 2001 From: mohamedkaif356 Date: Fri, 7 Jul 2023 16:07:58 +0530 Subject: [PATCH] Login Feature --- .../hpos/presentation/RecyclerViewAdapter.kt | 94 ---------------- .../data/model/patient/UserData.kt | 27 ++--- .../domain/ResultCalculationWithAvgImpl.kt | 94 ---------------- .../domain/ResultCalculationWithFirstImpl.kt | 101 ------------------ .../presentation/adapter/UserListAdapter.kt | 8 +- .../presentation/dashboard/HomeFragment.kt | 20 ++-- .../dashboard/ui/LoginFragment.kt | 29 +++++ .../testRight/TestRightResults.kt | 26 ++--- .../testRight/TestRightViewModel.kt | 18 +++- app/src/main/res/layout/fragment_login.xml | 13 +++ .../res/navigation/dashboard_navigation.xml | 5 + app/src/main/res/values/strings.xml | 2 +- 12 files changed, 97 insertions(+), 340 deletions(-) delete mode 100644 app/src/main/java/com/example/hpos/presentation/RecyclerViewAdapter.kt delete mode 100644 app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithAvgImpl.kt delete mode 100644 app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithFirstImpl.kt create mode 100644 app/src/main/java/com/example/hpostesting/presentation/dashboard/ui/LoginFragment.kt create mode 100644 app/src/main/res/layout/fragment_login.xml diff --git a/app/src/main/java/com/example/hpos/presentation/RecyclerViewAdapter.kt b/app/src/main/java/com/example/hpos/presentation/RecyclerViewAdapter.kt deleted file mode 100644 index 2f85e67..0000000 --- a/app/src/main/java/com/example/hpos/presentation/RecyclerViewAdapter.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.example.hpos.presentation - -import android.util.Log -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.RadioButton -import android.widget.RadioGroup -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.example.hpos.R -import com.example.hpos.data.model.test.Status -import com.example.hpos.data.model.test.TestDetails -import com.example.hpos.presentation.dashboard.ItemClickListener - -class RecyclerViewAdapter : RecyclerView.Adapter() { - - private val dataset = ArrayList() - - var itemClickListener: ItemClickListener? = null - - var selectedPosition = -1 - var prev = -1 - - inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { - val tvId: TextView = view.findViewById(R.id.tv_id) - val tvName: TextView = view.findViewById(R.id.tv_name) - val tvStatus: TextView = view.findViewById(R.id.tv_status) - val radioButton: RadioButton = view.findViewById(R.id.radioButton) - val radioGroup: RadioGroup = view.findViewById(R.id.radio_group) - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context) - .inflate(R.layout.table_item, parent, false) - - return ViewHolder(view) - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - Log.d("RVAdapter", "onBindViewHolder called() : pos = ${position}") - val idString = "ID: " + dataset[position].patientID - holder.tvId.text = idString - holder.tvName.text = dataset[position].patientName - holder.tvStatus.text = dataset[position].testStatus.toString() - - - Log.d("RVAdapter", "For ${dataset[position].patientName}, selected = $selectedPosition") - - holder.radioGroup.clearCheck() - if (dataset[position].testStatus == Status.PENDING) { - holder.radioButton.isEnabled = true - holder.radioButton.isChecked = (position == selectedPosition) - Log.d("RVAdapter", "inside pending if") - } else { - holder.radioButton.isChecked = false - holder.radioButton.isEnabled = false - Log.d("RVAdapter", "inside pending else") - } - - holder.radioButton.setOnClickListener { - setSelectedItem(position) - } - holder.itemView.setOnClickListener { - setSelectedItem(position) - } - } - - private fun setSelectedItem(position: Int) { - Log.d("RVAdapter", "setOnCheckedChangeListener called() -> b true : pos = $position") - - if (position != selectedPosition && dataset[position].testStatus == Status.PENDING) { - prev = selectedPosition - selectedPosition = position - itemClickListener!!.onClick(position) - - if (prev != -1) { - notifyItemChanged(prev) - } - notifyItemChanged(position) - } - } - - override fun getItemCount(): Int { - return dataset.size - } - - fun updateDataSet(newDataSet: ArrayList) { - dataset.clear() - dataset.addAll(newDataSet) - notifyDataSetChanged() - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt b/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt index 6ec7742..b149b9e 100644 --- a/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt +++ b/app/src/main/java/com/example/hpostesting/data/model/patient/UserData.kt @@ -8,38 +8,23 @@ import com.example.hpostesting.data.model.test.TestRightResultType data class UserData( @PrimaryKey var _id: String = "", - var AbhaId: String = "", - var AadharId: String = "", var name: String = "", var birthYear: String = "", - var gender: String = "", - var phoneNumber: String = "", - var careOf: String = "", - var maritalStatus: String = "", - var caste: String = "", - var subCaste: String = "", - var house: String = "", - var city: String = "", - var district: String = "", - var state: String = "", - var pinCode: String = "", - var bloodGroup: String = "", - var isUnderMedication: Boolean? = false, - var isUnderTransfusion: Boolean? = false, - var sickleCellHistory: String? = "", - var userImage: String = "", + var userImageURL: String = "", var location: Location? = null, - var uploadTime: String? = "", + var createdBy: String? = "", + var reportUploadTime: String? = "", var testTime: String? = "", var testStatus: Boolean? = false, var mobileId: String = "", var deviceId: String = "", + var deviceSerialNumber: String = "", var kitSerial: String = "", var csvPath: String = "", var reportPath: String = "", var result: TestRightResultType? = null, - var resultRatio: Double? = null, -){ + var resultRatio: Double? = null +) { enum class Gender { MALE, FEMALE, diff --git a/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithAvgImpl.kt b/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithAvgImpl.kt deleted file mode 100644 index 05c1e8d..0000000 --- a/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithAvgImpl.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.example.hpostesting.domain - -import com.example.hpostesting.data.constant.Constants -import com.example.hpostesting.data.model.test.TestRightCalculationData -import com.example.hpostesting.data.model.test.TestRightResultType - -class ResultCalculationWithAvgImpl : TestRightResultCalculation { - - private val testRightCalculationData = TestRightCalculationData() - - override fun getResults(wavelengthToAbsorbance: ArrayList>): TestRightCalculationData { - - val startWavelengthOne = - Constants.WAVELENGTH_OF_INTEREST_ONE - Constants.RANGE_IN_RESULT_CALCULATIONS - val endWavelengthOne = - Constants.WAVELENGTH_OF_INTEREST_ONE + Constants.RANGE_IN_RESULT_CALCULATIONS + 1 - var sumOfAbsorbanceAtOne = 0.0 - var noOfAbsorbanceRecordedOne = 0 - - val startWavelengthTwo = - Constants.WAVELENGTH_OF_INTEREST_TWO - Constants.RANGE_IN_RESULT_CALCULATIONS - val endWavelengthTwo = - Constants.WAVELENGTH_OF_INTEREST_TWO + Constants.RANGE_IN_RESULT_CALCULATIONS + 1 - var sumOfAbsorbanceAtTwo = 0.0 - var noOfAbsorbanceRecordedTwo = 0 - - for (each in wavelengthToAbsorbance) { - if (each[0] >= startWavelengthOne && each[0] < endWavelengthOne) { - sumOfAbsorbanceAtOne += each[1] - noOfAbsorbanceRecordedOne++ - } - if (each[0] >= startWavelengthTwo && each[0] < endWavelengthTwo) { - sumOfAbsorbanceAtTwo += each[1] - noOfAbsorbanceRecordedTwo++ - } - } - - val avgAbsorbanceOne = (sumOfAbsorbanceAtOne / noOfAbsorbanceRecordedOne) - val avgAbsorbanceTwo = (sumOfAbsorbanceAtTwo / noOfAbsorbanceRecordedTwo) - - testRightCalculationData.absorbanceOne = avgAbsorbanceOne - testRightCalculationData.absorbanceTwo = avgAbsorbanceTwo - - testRightCalculationData.result = calculateResultsAndRatio(avgAbsorbanceOne, avgAbsorbanceTwo) - return testRightCalculationData - } - - private fun calculateResultsAndRatio( - absorbanceAtWaveOne: Double, - absorbanceAtWaveTwo: Double - ): TestRightResultType { - - if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) { - val value = absorbanceAtWaveTwo / absorbanceAtWaveOne - testRightCalculationData.ratioValue = value - - if (value < 0.24 || value == 0.0) { - testRightCalculationData.ratioMinRange = 0.0 - testRightCalculationData.ratioMaxRange = 0.24 - return TestRightResultType.NORMAL - } else if (value >= 0.24 && value < 0.30) { - testRightCalculationData.ratioMinRange = 0.24 - testRightCalculationData.ratioMaxRange = 0.30 - return TestRightResultType.SICKLECELLTRAIT - } else if (value >= 0.30) { - testRightCalculationData.ratioMinRange = 0.30 - testRightCalculationData.ratioMaxRange = 999.0 - return TestRightResultType.SICKLECELLDISEASE - } - } - - return TestRightResultType.UNDEFINED - -// if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) { -// val value = absorbanceAtWaveTwo / absorbanceAtWaveOne -// -// if (value < 0.24 || value == 0.0) { -// return TestRightResultType.NORMAL -// } else if (value >= 0.24 && value < 0.30) { -// return TestRightResultType.SICKLECELLTRAIT -// } else if (value >= 0.30) { -// return TestRightResultType.SICKLECELLDISEASE -// } -// -// } - -// return TestRightResultType.UNDEFINED -// Log.d(TAG, "value = $value") -// println("value = $value") - - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithFirstImpl.kt b/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithFirstImpl.kt deleted file mode 100644 index 8888379..0000000 --- a/app/src/main/java/com/example/hpostesting/domain/ResultCalculationWithFirstImpl.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.example.hpostesting.domain - -import android.util.Log -import com.example.hpostesting.data.constant.Constants -import com.example.hpostesting.data.model.test.TestRightResultType -import kotlin.math.log10 - -class ResultCalculationWithFirstImpl { - - private val TAG = "Testright" - - fun getResults( - wavelengthToPixelArray: ArrayList>, - intensityReferenceArray: ArrayList>, - intensitySampleArray: ArrayList> - ) : TestRightResultType { - var pixelNoWithWave_427 = 0 - var pixelNoWithWave_555 = 0 - - Log.d(TAG, "wavelengthToPixelArray size = ${wavelengthToPixelArray.size}") -// println("wavelengthToPixelArray size = ${wavelengthToPixelArray.size}") - for (each in wavelengthToPixelArray) { - var diff = each[0] - 427 - if (pixelNoWithWave_427 == 0 && diff >= 0 && diff < 1) { - pixelNoWithWave_427 = each[1].toInt() - } - - diff = each[0] - 555 - if (pixelNoWithWave_555 == 0 && diff >= 0 && diff < 1) { - pixelNoWithWave_555 = each[1].toInt() - } - - if (pixelNoWithWave_427 != 0 && pixelNoWithWave_555 != 0) { - break - } - } - - Log.d(TAG, "pixelOfInterest_427 = ${pixelNoWithWave_427}") - Log.d(TAG, "pixelOfInterest_555 = ${pixelNoWithWave_555}") - -// println("pixelOfInterest_427 = ${pixelNoWithWave_427}") -// println("pixelOfInterest_555 = ${pixelNoWithWave_555}") - - val invertedPixel_427 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_427 - val invertedPixel_555 = (Constants.TEST_RIGHT_TOTAL_PIXEL + 1) - pixelNoWithWave_555 - - var io_427 = 0.0 - var io_555 = 0.0 - - for (each in intensityReferenceArray) { - if (each[0].toInt() == invertedPixel_427) { - io_427 = each[1] - } - if (each[0].toInt() == invertedPixel_555) { - io_555 = each[1] - } - } - Log.d(TAG, "I0 values are I0_427 = $io_427 , IO_555 = $io_555") -// println("I0 values are I0_427 = $io_427 , IO_555 = $io_555") - - var i_427 = 0.0 - var i_555 = 0.0 - - for (each in intensitySampleArray) { - if (each[0].toInt() == invertedPixel_427) { - i_427 = each[1] - } - if (each[0].toInt() == invertedPixel_555) { - i_555 = each[1] - } - } - Log.d(TAG, "I values are I_427 = $i_427 , I_555 = $i_555") -// println("I values are I_427 = $i_427 , I_555 = $i_555") - - val absorbanceAtPixelWithWave_427 = log10(io_427 / i_427) - val absorbanceAtPixelWithWave_555 = log10(io_555 / i_555) - Log.d( - TAG, - "absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555" - ) -// println("absorbance values are for 427 = $absorbanceAtPixelWithWave_427 , for 555 = $absorbanceAtPixelWithWave_555") - - var value = 0.0 - if (absorbanceAtPixelWithWave_427 != 0.0 && absorbanceAtPixelWithWave_555 != 0.0) { - value = absorbanceAtPixelWithWave_555 / absorbanceAtPixelWithWave_427 - } - Log.d(TAG, "value = $value") -// println("value = $value") - - - if (value < 0.24 || value == 0.0) { - return TestRightResultType.NORMAL - } else if (value >= 0.24 && value < 0.30) { - return TestRightResultType.SICKLECELLTRAIT - } else if (value >= 0.30) { - return TestRightResultType.SICKLECELLDISEASE - } - return TestRightResultType.UNDEFINED - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/adapter/UserListAdapter.kt b/app/src/main/java/com/example/hpostesting/presentation/adapter/UserListAdapter.kt index 88ac1c4..b6e2bc3 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/adapter/UserListAdapter.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/adapter/UserListAdapter.kt @@ -32,11 +32,9 @@ class UserListAdapter(options: FirestoreRecyclerOptions, private val v holder.binding.apply { userName.text = model.name userId.text = model._id - Glide.with(view).load(model.userImage).into(userImage) - if (model.testStatus != null) { - if (model.testStatus!!) { - userCard.setCardBackgroundColor(view.resources.getColor(R.color.gray)) - } + Glide.with(view).load(model.userImageURL).into(userImage) + if (model.testStatus!!) { + userCard.setCardBackgroundColor(view.resources.getColor(R.color.gray)) } userCard.setOnClickListener { if (model.testStatus != null) { 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 329b937..bf2ca97 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 @@ -91,13 +91,15 @@ class HomeFragment : Fragment() { } private fun getData(search: String?, field: String) { - val capitalizedSearch = - search?.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } - Log.i("Capital", capitalizedSearch.toString()) + val capitalizedSearch = search?.replaceFirstChar { + if (search.lowercase() + .startsWith(it.lowercase()) + ) it.titlecase(Locale.getDefault()) else it.toString() - val query = Firebase.firestore.collection("patientData") - .orderBy(field) - .whereArrayContainsAny(field, listOf(capitalizedSearch)) + } + + val query = Firebase.firestore.collection("patientData").orderBy(field).startAt(search) + .endAt(search + "\uf8ff") val recyclerViewOptions = FirestoreRecyclerOptions.Builder().setQuery(query, UserData::class.java) @@ -179,7 +181,11 @@ class HomeFragment : Fragment() { viewModel.deleteById(userData._id) } dialog.dismiss() - Toast.makeText(requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT).show() + Toast.makeText( + requireContext(), + R.string.upload_success_message, + Toast.LENGTH_SHORT + ).show() } } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/ui/LoginFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/ui/LoginFragment.kt new file mode 100644 index 0000000..75c2d9e --- /dev/null +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/ui/LoginFragment.kt @@ -0,0 +1,29 @@ +package com.example.hpostesting.presentation.dashboard.ui + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding + +class LoginFragment : Fragment() { + + private var _binding: FragmentLoginBinding? = null + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentLoginBinding.inflate(inflater, container, false) + + return binding.root + } + + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt index 37b0dfe..6587257 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt @@ -35,9 +35,7 @@ class TestRightResults : Fragment() { ): View { // Inflate the layout for this fragment binding = FragmentTestRightResultsBinding.inflate(inflater, container, false) - viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable -> - isOnline = isNetworkAvailable - } + return binding.root } @@ -136,16 +134,18 @@ class TestRightResults : Fragment() { } } } - if (isOnline) { - viewModel.uploadResultToDatabase(requireContext(), true) - binding.progressBar.visibility = View.VISIBLE - } else { - viewModel.uploadResultToDatabase(requireContext(), false) - Toast.makeText( - requireContext(), - "Internet not available, Test Data added to Local DB", - Toast.LENGTH_SHORT - ).show() + viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable -> + if (isNetworkAvailable) { + viewModel.uploadResultToDatabase(requireContext(), true) + binding.progressBar.visibility = View.VISIBLE + } else { + viewModel.uploadResultToDatabase(requireContext(), false) + Toast.makeText( + requireContext(), + "Internet not available, Test Data added to Local DB", + Toast.LENGTH_SHORT + ).show() + } } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt index 542dd34..59cf5e4 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt @@ -33,6 +33,7 @@ import java.io.File import java.text.SimpleDateFormat import java.util.Calendar import java.util.Date +import java.util.Locale import javax.inject.Inject import kotlin.math.log10 import kotlin.math.pow @@ -437,9 +438,13 @@ class TestRightViewModel @Inject constructor( private fun addResultTestToDb() { testDetails?.location = DataHolder.location - testDetails?.testTime = Calendar.getInstance().time.toString() + testDetails?.testTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time) viewModelScope.launch { - testDetails!!.uploadTime = Calendar.getInstance().time.toString() + testDetails!!.reportUploadTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time) when (repository.addTestToDatabase(testDetails)) { is Response.Success -> { fireBaseUpload.postValue("Success") @@ -480,7 +485,9 @@ class TestRightViewModel @Inject constructor( // Handle the exception appropriately (e.g., log the error, display an error message) } } else { - testDetails?.testTime = Calendar.getInstance().time.toString() + testDetails?.testTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time) userDao.insertAll(testDetails!!) } } @@ -514,11 +521,14 @@ class TestRightViewModel @Inject constructor( private fun bulkAddResultTestToDb(userData: UserData) { userData.location = DataHolder.location viewModelScope.launch { - userData.uploadTime = Calendar.getInstance().time.toString() + userData.reportUploadTime = SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss", Locale.getDefault() + ).format(Calendar.getInstance().time) when (repository.addTestToDatabase(userData)) { is Response.Success -> { fireBaseUpload.postValue("Success") } + else -> {} } } diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml new file mode 100644 index 0000000..7ceffab --- /dev/null +++ b/app/src/main/res/layout/fragment_login.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/dashboard_navigation.xml b/app/src/main/res/navigation/dashboard_navigation.xml index 91e4adf..325be3d 100644 --- a/app/src/main/res/navigation/dashboard_navigation.xml +++ b/app/src/main/res/navigation/dashboard_navigation.xml @@ -32,4 +32,9 @@ android:id="@+id/mainActivity" android:name="com.example.hpostesting.presentation.MainActivity" android:label="MainActivity" /> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cb5af81..8a91fdd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -62,7 +62,7 @@ Step 2 : Press the button below to start the device reading values. Step 1 : Enter the sample details to start. - + Step 1 : Place the cuvette containing blood sample mixed with kit solution. Step 2 : Press the button below to start the device reading values.