Login Feature - 1
This commit is contained in:
@@ -28,4 +28,26 @@ object Constants {
|
|||||||
const val ERROR_CRITICAL = 401
|
const val ERROR_CRITICAL = 401
|
||||||
|
|
||||||
const val NO_OF_TIMES_TO_RUN_SAMPLE = 1
|
const val NO_OF_TIMES_TO_RUN_SAMPLE = 1
|
||||||
|
|
||||||
|
const val USER_ID = "usernameId"
|
||||||
|
|
||||||
|
val STATICID = listOf(
|
||||||
|
"SMIREG1",
|
||||||
|
"SMIREG2",
|
||||||
|
"SMIREG3",
|
||||||
|
"SMIREG4",
|
||||||
|
"SMIREG5",
|
||||||
|
"SMIREG6",
|
||||||
|
"SMIREG7",
|
||||||
|
"SMIREG8",
|
||||||
|
"SMIREG9",
|
||||||
|
"SMIREG10",
|
||||||
|
"SMIREG11",
|
||||||
|
"SMIREG12",
|
||||||
|
"SMIREG13",
|
||||||
|
"SMIREG14",
|
||||||
|
"SMIREG15"
|
||||||
|
)
|
||||||
|
|
||||||
|
const val password = "SMI@12345"
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.example.hpostesting.presentation.dashboard
|
|||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -13,6 +14,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.DataHolder
|
import com.example.hpostesting.data.DataHolder
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
import com.example.hpostesting.presentation.adapter.UserListAdapter
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
@@ -31,11 +33,12 @@ class HomeFragment : Fragment() {
|
|||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
private lateinit var rvAdapter: UserListAdapter
|
private lateinit var rvAdapter: UserListAdapter
|
||||||
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||||
|
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
DataHolder.selectedTest = null
|
DataHolder.selectedTest = null
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
@@ -59,7 +62,9 @@ class HomeFragment : Fragment() {
|
|||||||
setUserId()
|
setUserId()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
binding.btnLogout.setOnClickListener {
|
||||||
|
logoutUser(requireContext())
|
||||||
|
}
|
||||||
binding.uploadData.setOnClickListener {
|
binding.uploadData.setOnClickListener {
|
||||||
showUploadDialog(requireContext())
|
showUploadDialog(requireContext())
|
||||||
}
|
}
|
||||||
@@ -90,6 +95,35 @@ class HomeFragment : Fragment() {
|
|||||||
rvAdapter.startListening()
|
rvAdapter.startListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveUserId(userId: String) {
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString(Constants.USER_ID, userId)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private fun logoutUser(context: Context) {
|
||||||
|
val builder = AlertDialog.Builder(context)
|
||||||
|
builder.setTitle("Log Out")
|
||||||
|
builder.setMessage("Do you want to LogOut the Application?")
|
||||||
|
|
||||||
|
// Positive button
|
||||||
|
builder.setPositiveButton("Yes") { dialog, _ ->
|
||||||
|
saveUserId("")
|
||||||
|
findNavController().navigate(R.id.action_userListFragment_to_loginFragment)
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Negative button
|
||||||
|
builder.setNegativeButton("No") { dialog, _ ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
val dialog = builder.create()
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun getData(search: String?, field: String) {
|
private fun getData(search: String?, field: String) {
|
||||||
val capitalizedSearch = search?.replaceFirstChar {
|
val capitalizedSearch = search?.replaceFirstChar {
|
||||||
if (search.lowercase()
|
if (search.lowercase()
|
||||||
|
|||||||
@@ -1,29 +1,88 @@
|
|||||||
package com.example.hpostesting.presentation.dashboard.ui
|
package com.example.hpostesting.presentation.dashboard.ui
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentLoginBinding
|
||||||
|
|
||||||
class LoginFragment : Fragment() {
|
class LoginFragment : Fragment() {
|
||||||
|
|
||||||
private var _binding: FragmentLoginBinding? = null
|
private var _binding: FragmentLoginBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
_binding = FragmentLoginBinding.inflate(inflater, container, false)
|
||||||
|
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private fun init() {
|
||||||
|
if (isUserLoggedIn()) {
|
||||||
|
navigateToUserListFragment()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.btnLogin.setOnClickListener {
|
||||||
|
val loginId = binding.loginId.text.toString()
|
||||||
|
val password = binding.password.text.toString()
|
||||||
|
|
||||||
|
if (loginId.isNotBlank() && password.isNotBlank()) {
|
||||||
|
performLogin(loginId, password)
|
||||||
|
} else {
|
||||||
|
if (loginId.isBlank()) {
|
||||||
|
binding.loginId.error = "Please enter a proper Login ID"
|
||||||
|
}
|
||||||
|
if (password.isBlank()) {
|
||||||
|
binding.password.error = "Please enter a proper password"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isUserLoggedIn(): Boolean {
|
||||||
|
return sharedPreference.getString(Constants.USER_ID, "")?.isNotBlank() == true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun navigateToUserListFragment() {
|
||||||
|
findNavController().navigate(R.id.action_loginFragment_to_userListFragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun performLogin(loginId: String, password: String) {
|
||||||
|
val matchingId = Constants.STATICID.firstOrNull { it == loginId }
|
||||||
|
if (matchingId != null) {
|
||||||
|
if (password == Constants.password) {
|
||||||
|
saveUserId(loginId)
|
||||||
|
navigateToUserListFragment()
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
Toast.makeText(requireContext(), "Wrong Password", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Toast.makeText(requireContext(), "Wrong UserID", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveUserId(userId: String) {
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString(Constants.USER_ID, userId)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
app/src/main/res/drawable/baseline_logout_24.xml
Normal file
5
app/src/main/res/drawable/baseline_logout_24.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<vector android:autoMirrored="true" android:height="24dp"
|
||||||
|
android:tint="#EF0A0A" 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="M17,7l-1.41,1.41L18.17,11H8v2h10.17l-2.58,2.58L17,17l5,-5zM4,5h8V3H4c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h8v-2H4V5z"/>
|
||||||
|
</vector>
|
||||||
BIN
app/src/main/res/drawable/smi_logo.png
Normal file
BIN
app/src/main/res/drawable/smi_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -84,6 +84,15 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="@+id/tv_title"
|
app:layout_constraintBottom_toBottomOf="@+id/tv_title"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/tv_title" />
|
app:layout_constraintTop_toTopOf="@+id/tv_title" />
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btnLogout"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:src="@drawable/baseline_logout_24"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/tv_title"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/uploadData"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/tv_title" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_not_available"
|
android:id="@+id/tv_not_available"
|
||||||
|
|||||||
@@ -1,13 +1,106 @@
|
|||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context="com.example.hpostesting.presentation.dashboard.ui.LoginFragment">
|
tools:context="com.example.hpostesting.presentation.dashboard.ui.LoginFragment">
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:text="@string/hello_blank_fragment" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_title"
|
||||||
|
style="@style/title1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/login"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:src="@drawable/smi_logo"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/imageView2"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView2"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:src="@drawable/sickle_cell_gov_logo"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/imageView"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/et_aadharID"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/imageView">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/loginId"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/login_id"
|
||||||
|
android:inputType="textCapCharacters"
|
||||||
|
android:maxLength="12" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/et_centerName"
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/et_aadharID">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/password"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/password"
|
||||||
|
android:inputType="text"
|
||||||
|
android:maxLength="12" />
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/btnLogin"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/login"
|
||||||
|
app:cornerRadius="16dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/et_centerName" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -36,5 +36,11 @@
|
|||||||
android:id="@+id/loginFragment"
|
android:id="@+id/loginFragment"
|
||||||
android:name="com.example.hpostesting.presentation.dashboard.ui.LoginFragment"
|
android:name="com.example.hpostesting.presentation.dashboard.ui.LoginFragment"
|
||||||
android:label="fragment_login"
|
android:label="fragment_login"
|
||||||
tools:layout="@layout/fragment_login" />
|
tools:layout="@layout/fragment_login" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_loginFragment_to_homeFragment"
|
||||||
|
app:destination="@id/nav_home"
|
||||||
|
app:popUpTo="@id/mobile_navigation"
|
||||||
|
app:popUpToInclusive="true"/>
|
||||||
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -66,7 +66,9 @@
|
|||||||
<string name="step4"><b><u>Step 1</u> : </b> Place the cuvette containing blood sample mixed with kit solution.</string>
|
<string name="step4"><b><u>Step 1</u> : </b> Place the cuvette containing blood sample mixed with kit solution.</string>
|
||||||
<string name="step5"><b><u>Step 2</u> : </b> Press the button below to start the device reading values.</string>
|
<string name="step5"><b><u>Step 2</u> : </b> Press the button below to start the device reading values.</string>
|
||||||
|
|
||||||
|
<string name="login_id">Login ID</string>
|
||||||
|
<string name="password">Password</string>
|
||||||
|
<string name="login">Login</string>
|
||||||
<string name="acquire">Acquire</string>
|
<string name="acquire">Acquire</string>
|
||||||
<string name="enter_patient_details">Enter Patient Details</string>
|
<string name="enter_patient_details">Enter Patient Details</string>
|
||||||
<string name="patient_name">Patient Name</string>
|
<string name="patient_name">Patient Name</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user