Login Feature

This commit is contained in:
mohamedkaif356
2023-07-07 16:07:58 +05:30
parent 0c063583ca
commit e1e8e4ebb2
12 changed files with 97 additions and 340 deletions

View File

@@ -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<RecyclerViewAdapter.ViewHolder>() {
private val dataset = ArrayList<TestDetails>()
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<TestDetails>) {
dataset.clear()
dataset.addAll(newDataSet)
notifyDataSetChanged()
}
}

View File

@@ -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,

View File

@@ -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<ArrayList<Double>>): 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")
}
}

View File

@@ -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<ArrayList<Double>>,
intensityReferenceArray: ArrayList<ArrayList<Double>>,
intensitySampleArray: ArrayList<ArrayList<Double>>
) : 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
}
}

View File

@@ -32,11 +32,9 @@ class UserListAdapter(options: FirestoreRecyclerOptions<UserData>, 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) {

View File

@@ -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<UserData>().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()
}
}
}

View File

@@ -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
}
}

View File

@@ -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()
}
}
}

View File

@@ -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 -> {}
}
}