Login Feature -completed
This commit is contained in:
@@ -32,21 +32,26 @@ object Constants {
|
|||||||
const val USER_ID = "usernameId"
|
const val USER_ID = "usernameId"
|
||||||
|
|
||||||
val STATICID = listOf(
|
val STATICID = listOf(
|
||||||
"SMIREG1",
|
"VIZ-1000-0001",
|
||||||
"SMIREG2",
|
"VIZ-1000-0002",
|
||||||
"SMIREG3",
|
"VIZ-1000-0003",
|
||||||
"SMIREG4",
|
"VIZ-1000-0004",
|
||||||
"SMIREG5",
|
"VIZ-1000-0005",
|
||||||
"SMIREG6",
|
"VIZ-1000-0006",
|
||||||
"SMIREG7",
|
"VIZ-1000-0007",
|
||||||
"SMIREG8",
|
"VIZ-1000-0008",
|
||||||
"SMIREG9",
|
"VIZ-1000-0009",
|
||||||
"SMIREG10",
|
"VIZ-1000-0010",
|
||||||
"SMIREG11",
|
"VIZ-1000-0011",
|
||||||
"SMIREG12",
|
"VIZ-1000-0012",
|
||||||
"SMIREG13",
|
"VIZ-1000-0013",
|
||||||
"SMIREG14",
|
"VIZ-1000-0014",
|
||||||
"SMIREG15"
|
"VIZ-1000-0015",
|
||||||
|
"VIZ-1000-0016",
|
||||||
|
"VIZ-1000-0017",
|
||||||
|
"VIZ-1000-0018",
|
||||||
|
"VIZ-1000-0019"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const val password = "SMI@12345"
|
const val password = "SMI@12345"
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ class UserListAdapter(options: FirestoreRecyclerOptions<UserData>, private val v
|
|||||||
userId.text = model._id
|
userId.text = model._id
|
||||||
Glide.with(view).load(model.userImageURL).into(userImage)
|
Glide.with(view).load(model.userImageURL).into(userImage)
|
||||||
if (model.testStatus!!) {
|
if (model.testStatus!!) {
|
||||||
userCard.setCardBackgroundColor(view.resources.getColor(R.color.gray))
|
teststatus.text = "Test concluded"
|
||||||
|
|
||||||
|
} else {
|
||||||
|
teststatus.text = "Test is Pending"
|
||||||
}
|
}
|
||||||
userCard.setOnClickListener {
|
userCard.setOnClickListener {
|
||||||
if (model.testStatus != null) {
|
if (model.testStatus != null) {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class HomeFragment : Fragment() {
|
|||||||
// Positive button
|
// Positive button
|
||||||
builder.setPositiveButton("Yes") { dialog, _ ->
|
builder.setPositiveButton("Yes") { dialog, _ ->
|
||||||
saveUserId("")
|
saveUserId("")
|
||||||
findNavController().navigate(R.id.action_userListFragment_to_loginFragment)
|
findNavController().navigate(R.id.action_nav_home_to_loginFragment)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,15 @@ class LoginFragment : Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
if (isUserLoggedIn()) {
|
if (isUserLoggedIn()) {
|
||||||
navigateToUserListFragment()
|
navigateToHomeFragment()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +60,8 @@ class LoginFragment : Fragment() {
|
|||||||
return sharedPreference.getString(Constants.USER_ID, "")?.isNotBlank() == true
|
return sharedPreference.getString(Constants.USER_ID, "")?.isNotBlank() == true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun navigateToUserListFragment() {
|
private fun navigateToHomeFragment() {
|
||||||
findNavController().navigate(R.id.action_loginFragment_to_userListFragment)
|
findNavController().navigate(R.id.action_loginFragment_to_homeFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun performLogin(loginId: String, password: String) {
|
private fun performLogin(loginId: String, password: String) {
|
||||||
@@ -65,7 +69,7 @@ class LoginFragment : Fragment() {
|
|||||||
if (matchingId != null) {
|
if (matchingId != null) {
|
||||||
if (password == Constants.password) {
|
if (password == Constants.password) {
|
||||||
saveUserId(loginId)
|
saveUserId(loginId)
|
||||||
navigateToUserListFragment()
|
navigateToHomeFragment()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(requireContext(), "Wrong Password", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), "Wrong Password", Toast.LENGTH_SHORT).show()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData
|
|||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
class GalleryViewModel : ViewModel() {
|
class mGalleryViewModel : ViewModel() {
|
||||||
|
|
||||||
private val _text = MutableLiveData<String>().apply {
|
private val _text = MutableLiveData<String>().apply {
|
||||||
value = "This is gallery Fragment"
|
value = "This is gallery Fragment"
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package com.example.hpostesting.presentation.testRight
|
package com.example.hpostesting.presentation.testRight
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -18,24 +19,21 @@ import com.example.hpostesting.util.MyUtils.calculateAgeFromYOB
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightResultsBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightResultsBinding
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class TestRightResults : Fragment() {
|
class TestRightResults : Fragment() {
|
||||||
|
|
||||||
private lateinit var binding: FragmentTestRightResultsBinding
|
private lateinit var binding: FragmentTestRightResultsBinding
|
||||||
private val viewModel: TestRightViewModel by activityViewModels()
|
private val viewModel: TestRightViewModel by activityViewModels()
|
||||||
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
private val TAG = "TestRightResults"
|
|
||||||
private var isOnline = false
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
binding = FragmentTestRightResultsBinding.inflate(inflater, container, false)
|
binding = FragmentTestRightResultsBinding.inflate(inflater, container, false)
|
||||||
|
sharedPreference =
|
||||||
|
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +133,12 @@ class TestRightResults : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||||
|
val deviceStaticId = sharedPreference.getString(Constants.USER_ID, "")
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
viewModel.uploadResultToDatabase(requireContext(), true)
|
viewModel.uploadResultToDatabase(requireContext(), true, deviceStaticId!!)
|
||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
viewModel.uploadResultToDatabase(requireContext(), false)
|
viewModel.uploadResultToDatabase(requireContext(), false, deviceStaticId!!)
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
"Internet not available, Test Data added to Local DB",
|
"Internet not available, Test Data added to Local DB",
|
||||||
@@ -150,7 +149,7 @@ class TestRightResults : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun moveToSamplePage() {
|
private fun moveToSamplePage() {
|
||||||
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
||||||
DataHolder.sampleReadCounter = 0
|
DataHolder.sampleReadCounter = 0
|
||||||
DataHolder.isReferenceTaken = false
|
DataHolder.isReferenceTaken = false
|
||||||
@@ -162,14 +161,5 @@ class TestRightResults : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveLog() {
|
|
||||||
Log.d(TAG, "saveLog() called")
|
|
||||||
|
|
||||||
val sdfDate = SimpleDateFormat("ddMMyyyy HHmmss")
|
|
||||||
val fileName: String = "log_" + sdfDate.format(Date()) + ".txt"
|
|
||||||
|
|
||||||
viewModel.saveLog(requireContext().applicationContext, fileName)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -455,11 +455,12 @@ class TestRightViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadResultToDatabase(context: Context, isOnline: Boolean) = viewModelScope.launch {
|
fun uploadResultToDatabase(context: Context, isOnline: Boolean,deviceSerialNumber: String) = viewModelScope.launch {
|
||||||
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
val csvFilePath = MyUtils.getAppFolderPath(context) + getCSVFileName()
|
||||||
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
val logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
|
||||||
testDetails?.csvPath = csvFilePath
|
testDetails?.csvPath = csvFilePath
|
||||||
testDetails?.reportPath = logTxtFilePath
|
testDetails?.reportPath = logTxtFilePath
|
||||||
|
testDetails?.deviceSerialNumber = deviceSerialNumber
|
||||||
if (isOnline) {
|
if (isOnline) {
|
||||||
val storageRef = FirebaseStorage.getInstance().reference
|
val storageRef = FirebaseStorage.getInstance().reference
|
||||||
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
|
||||||
@@ -476,7 +477,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
|
|
||||||
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
|
||||||
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
val logUri = logUploadTask.storage.downloadUrl.await().toString()
|
||||||
|
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
|
||||||
testDetails?.csvPath = csvUri
|
testDetails?.csvPath = csvUri
|
||||||
testDetails?.reportPath = logUri
|
testDetails?.reportPath = logUri
|
||||||
|
|
||||||
@@ -512,6 +513,7 @@ class TestRightViewModel @Inject constructor(
|
|||||||
userData.csvPath = csvUri
|
userData.csvPath = csvUri
|
||||||
userData.reportPath = logUri
|
userData.reportPath = logUri
|
||||||
|
|
||||||
|
|
||||||
bulkAddResultTestToDb(userData)
|
bulkAddResultTestToDb(userData)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
// Handle the exception appropriately (e.g., log the error, display an error message)
|
// Handle the exception appropriately (e.g., log the error, display an error message)
|
||||||
|
|||||||
BIN
app/src/main/res/drawable/sickle_cell_gov_logo.png
Normal file
BIN
app/src/main/res/drawable/sickle_cell_gov_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -62,7 +62,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/login_id"
|
android:hint="@string/login_id"
|
||||||
android:inputType="textCapCharacters"
|
android:inputType="textCapCharacters"
|
||||||
android:maxLength="12" />
|
android:maxLength="13" />
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
|||||||
@@ -54,6 +54,20 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/userName" />
|
app:layout_constraintTop_toBottomOf="@id/userName" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/teststatus"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/userId" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
</androidx.cardview.widget.CardView>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/mobile_navigation"
|
android:id="@+id/mobile_navigation"
|
||||||
app:startDestination="@+id/nav_home">
|
app:startDestination="@+id/loginFragment">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_home"
|
android:id="@+id/nav_home"
|
||||||
@@ -15,6 +15,10 @@
|
|||||||
<action
|
<action
|
||||||
android:id="@+id/action_nav_home_to_mainActivity"
|
android:id="@+id/action_nav_home_to_mainActivity"
|
||||||
app:destination="@id/mainActivity" />
|
app:destination="@id/mainActivity" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_home_to_loginFragment"
|
||||||
|
app:destination="@id/loginFragment"
|
||||||
|
app:popUpToInclusive="true"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
|||||||
Reference in New Issue
Block a user