Created sample experiment page with form to take user input.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user