Created sample experiment page with form to take user input.

This commit is contained in:
vsuryakumar
2023-01-24 19:53:52 +05:30
parent a7b9ed8cfa
commit ea021d4957
5 changed files with 346 additions and 21 deletions

View File

@@ -1,16 +1,26 @@
package com.example.refactoredapp.presentation.testRight
import android.R.attr.button
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.Color
import android.graphics.LightingColorFilter
import android.graphics.PorterDuff
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.example.refactoredapp.databinding.FragmentTestRightExpReferenceBinding
import com.example.refactoredapp.R
import com.example.refactoredapp.data.model.PatientDetails
import com.example.refactoredapp.databinding.FragmentTestRightExpSampleBinding
class TestRightExpSample : Fragment() {
private lateinit var binding: FragmentTestRightExpReferenceBinding
private lateinit var binding: FragmentTestRightExpSampleBinding
private val viewModel: TestRightViewModel by activityViewModels()
override fun onCreateView(
@@ -18,7 +28,62 @@ class TestRightExpSample : Fragment() {
savedInstanceState: Bundle?
): View {
// Inflate the layout for this fragment
binding = FragmentTestRightExpReferenceBinding.inflate(inflater, container, false)
binding = FragmentTestRightExpSampleBinding.inflate(inflater, container, false)
binding.btnUpdateReference.disable()
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setupListeners()
}
private fun setupListeners() {
binding.btnAcquire.setOnClickListener {
val details = isValidInput()
if (details != null) {
viewModel.patientDetails = details
startAcquiring()
}
}
binding.etNameBlock.setOnClickListener { binding.etName.error = "" }
binding.etAgeBlock.setOnClickListener { binding.etAge.error = "" }
binding.etGenderBlock.setOnClickListener { binding.ddGender.error = "" }
}
private fun startAcquiring() {
}
private fun isValidInput() : PatientDetails? {
val name = binding.etName.editText?.text?.trim()
if (name.isNullOrEmpty()){
binding.etName.error = getString(R.string.name_error)
return null
}
val age = binding.etAge.editText?.text?.trim()
if (age.isNullOrEmpty()){
binding.etAge.error = getString(R.string.age_error)
return null
} else if (age.toString().toInt() < 0 || age.toString().toInt() > 199) {
binding.etAge.error = getString(R.string.age_error_out_of_bound)
return null
}
val gender = binding.ddGender.editText?.text
if (gender.isNullOrEmpty()){
binding.ddGender.error = getString(R.string.gender_error)
return null
}
return PatientDetails(name.toString(), age.toString().toInt(), gender.toString())
}
private fun Button.disable() {
backgroundTintList = ContextCompat.getColorStateList(requireActivity(), R.color.gray)
isClickable = false
}
fun Button.enable() {
backgroundTintList = ContextCompat.getColorStateList(requireActivity(), R.color.purple_500)
// background.setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY)
isClickable = true
}
}

View File

@@ -1,10 +1,13 @@
package com.example.refactoredapp.presentation.testRight
import android.util.Log
import android.util.Patterns
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.refactoredapp.data.Constants
import com.example.refactoredapp.data.model.PatientDetails
import com.example.refactoredapp.data.model.TestRightDeviceConstants
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -12,12 +15,15 @@ import kotlin.math.pow
class TestRightViewModel : ViewModel() {
var isReferenceDone = false
var isServiceConnected = false
private val TAG = "TestRightViewModel"
var isReferenceDone = false
var isServiceConnected = false
val isUsbConnected = MutableLiveData(false)
lateinit var patientDetails: PatientDetails
var deviceConstant: TestRightDeviceConstants? = null
/* Contains wavelength -> pixel no.*/
@@ -92,16 +98,28 @@ class TestRightViewModel : ViewModel() {
// }
}
// val dispatcher = TestCoroutineDispatcher()
//
// @Before
// fun setup() {
// Dispatchers.setMain(dispatcher)
// }
//
// @After
// fun tearDown() {
// Dispatchers.resetMain()
// fun isValidInput() : Boolean{
// name = email.trim()
// return when {
// email.isEmpty() -> {
// Log.d(TAG, "email is empty")
// _emailError.value = context.getString(R.string.malformed_email_empty_error)
// false
// }
// !Patterns.EMAIL_ADDRESS.matcher(email).matches() -> {
// Log.d(TAG, "email pattern mismatched")
// _emailError.value = context.getString(R.string.malformed_email_error)
// false
// }
// password.length < 6 -> {
// Log.d(TAG, "password is empty")
// _passwordError.value = context.getString(R.string.malformed_password_error)
// false
// }
// else -> {
// Log.d(TAG, "isValidInput: returning true")
// true
// }
// }
// }
}

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@@ -1,12 +1,222 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".presentation.testRight.TestRightExpSample">
<!-- TODO: Update blank fragment layout -->
<TextView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
android:layout_height="match_parent">
<Button
android:id="@+id/btn_update_reference"
android:layout_width="216dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="false"
android:textColor="@color/white"
android:text="@string/update_reference"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_title"
style="@style/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/Instructions"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_update_reference" />
<TextView
android:id="@+id/tv_subtitle1"
style="@style/title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/step3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_title" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/cv_sample_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:cardElevation="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_subtitle1">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_title_sample"
style="@style/title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:drawablePadding="8dp"
android:text="@string/enter_sample_details"
app:drawableStartCompat="@drawable/ic_baseline_create_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_name"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="@string/sample_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_title_sample">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_name_block"
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_age"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="@string/age"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_age_block"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<!-- <com.google.android.material.textfield.TextInputLayout-->
<!-- android:id="@+id/et_gender"-->
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="16dp"-->
<!-- android:hint="@string/gender"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/et_age">-->
<!-- <com.google.android.material.textfield.TextInputEditText-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content" />-->
<!-- </com.google.android.material.textfield.TextInputLayout>-->
<!-- style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"-->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/dd_gender"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="@string/gender"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_age">
<AutoCompleteTextView
android:id="@+id/et_gender_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:hint="@string/gender"
android:labelFor="@id/dd_gender"
app:simpleItems="@array/gender" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<TextView
android:id="@+id/tv_subtitle2"
style="@style/title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/step4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cv_sample_details" />
<TextView
android:id="@+id/tv_subtitle3"
style="@style/title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="@string/step5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_subtitle2" />
<Button
android:id="@+id/btn_acquire"
android:layout_width="216dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="false"
android:text="@string/acquire"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_subtitle3" />
<!-- <Button-->
<!-- android:id="@+id/btn_read"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/read"-->
<!-- android:layout_margin="16dp"-->
<!-- android:clickable="false"-->
<!-- app:layout_constraintTop_toBottomOf="@id/btn_set_reference"-->
<!-- app:layout_constraintStart_toStartOf="parent" />-->
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progressbar_drawable"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@@ -6,6 +6,12 @@
<item>Denovix</item>
</string-array>
<string-array name="gender">
<item>Male</item>
<item>Female</item>
<item>Other</item>
</string-array>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="select_the_test">Select the Test</string>
<string name="set_reference">Set Reference</string>
@@ -15,10 +21,31 @@
<string name="please_place">Please place the cuvette containing sample for reference before moving forward</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="connect">Connect</string>
<string name="connected">Connected</string>
<string name="read">Read</string>
<string name="update_reference">Update Reference</string>
<!-- Instructions Text -->
<string name="Instructions">Instructions</string>
<string name="step1"><b><u>Step 1</u> : </b> Place the cuvette containing reference/baseline sample for referencing.</string>
<string name="step2"><b><u>Step 2</u> : </b> Press the button below to start the device reading values.</string>
<string name="step3"><b><u>Step 1</u> : </b> Enter the sample details to start.</string>
<string name="step4"><b><u>Step 2</u> : </b> Place the cuvette containing sample for experiment.</string>
<string name="step5"><b><u>Step 3</u> : </b> Press the button below to start the device reading values.</string>
<string name="acquire">Acquire</string>
<string name="enter_sample_details">Enter Sample Details</string>
<string name="sample_name">Sample Name</string>
<string name="age">Age</string>
<string name="gender">Gender</string>
<string name="name_error">Name can\'t be empty</string>
<string name="age_error">Age can\'t be empty</string>
<string name="gender_error">Gender can\'t be empty</string>
<string name="age_error_out_of_bound">Age should be valid</string>
</resources>