Login Feature -completed

This commit is contained in:
smileomi18@gmail.com
2023-07-11 16:56:26 +05:30
parent 9a1fc15902
commit ab9392cd59
11 changed files with 67 additions and 45 deletions

View File

@@ -32,21 +32,26 @@ object Constants {
const val USER_ID = "usernameId"
val STATICID = listOf(
"SMIREG1",
"SMIREG2",
"SMIREG3",
"SMIREG4",
"SMIREG5",
"SMIREG6",
"SMIREG7",
"SMIREG8",
"SMIREG9",
"SMIREG10",
"SMIREG11",
"SMIREG12",
"SMIREG13",
"SMIREG14",
"SMIREG15"
"VIZ-1000-0001",
"VIZ-1000-0002",
"VIZ-1000-0003",
"VIZ-1000-0004",
"VIZ-1000-0005",
"VIZ-1000-0006",
"VIZ-1000-0007",
"VIZ-1000-0008",
"VIZ-1000-0009",
"VIZ-1000-0010",
"VIZ-1000-0011",
"VIZ-1000-0012",
"VIZ-1000-0013",
"VIZ-1000-0014",
"VIZ-1000-0015",
"VIZ-1000-0016",
"VIZ-1000-0017",
"VIZ-1000-0018",
"VIZ-1000-0019"
)
const val password = "SMI@12345"

View File

@@ -34,7 +34,10 @@ class UserListAdapter(options: FirestoreRecyclerOptions<UserData>, private val v
userId.text = model._id
Glide.with(view).load(model.userImageURL).into(userImage)
if (model.testStatus!!) {
userCard.setCardBackgroundColor(view.resources.getColor(R.color.gray))
teststatus.text = "Test concluded"
} else {
teststatus.text = "Test is Pending"
}
userCard.setOnClickListener {
if (model.testStatus != null) {

View File

@@ -109,7 +109,7 @@ class HomeFragment : Fragment() {
// Positive button
builder.setPositiveButton("Yes") { dialog, _ ->
saveUserId("")
findNavController().navigate(R.id.action_userListFragment_to_loginFragment)
findNavController().navigate(R.id.action_nav_home_to_loginFragment)
dialog.dismiss()
}

View File

@@ -27,11 +27,15 @@ class LoginFragment : Fragment() {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
init()
}
private fun init() {
if (isUserLoggedIn()) {
navigateToUserListFragment()
navigateToHomeFragment()
return
}
@@ -56,8 +60,8 @@ class LoginFragment : Fragment() {
return sharedPreference.getString(Constants.USER_ID, "")?.isNotBlank() == true
}
private fun navigateToUserListFragment() {
findNavController().navigate(R.id.action_loginFragment_to_userListFragment)
private fun navigateToHomeFragment() {
findNavController().navigate(R.id.action_loginFragment_to_homeFragment)
}
private fun performLogin(loginId: String, password: String) {
@@ -65,7 +69,7 @@ class LoginFragment : Fragment() {
if (matchingId != null) {
if (password == Constants.password) {
saveUserId(loginId)
navigateToUserListFragment()
navigateToHomeFragment()
return
} else {
Toast.makeText(requireContext(), "Wrong Password", Toast.LENGTH_SHORT).show()

View File

@@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class GalleryViewModel : ViewModel() {
class mGalleryViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is gallery Fragment"

View File

@@ -1,8 +1,9 @@
package com.example.hpostesting.presentation.testRight
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -18,24 +19,21 @@ import com.example.hpostesting.util.MyUtils.calculateAgeFromYOB
import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightResultsBinding
import java.text.SimpleDateFormat
import java.util.Date
@AndroidEntryPoint
class TestRightResults : Fragment() {
private lateinit var binding: FragmentTestRightResultsBinding
private val viewModel: TestRightViewModel by activityViewModels()
private val TAG = "TestRightResults"
private var isOnline = false
private lateinit var sharedPreference: SharedPreferences
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
// Inflate the layout for this fragment
binding = FragmentTestRightResultsBinding.inflate(inflater, container, false)
sharedPreference =
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
return binding.root
}
@@ -135,11 +133,12 @@ class TestRightResults : Fragment() {
}
}
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
val deviceStaticId = sharedPreference.getString(Constants.USER_ID, "")
if (isNetworkAvailable) {
viewModel.uploadResultToDatabase(requireContext(), true)
viewModel.uploadResultToDatabase(requireContext(), true, deviceStaticId!!)
binding.progressBar.visibility = View.VISIBLE
} else {
viewModel.uploadResultToDatabase(requireContext(), false)
viewModel.uploadResultToDatabase(requireContext(), false, deviceStaticId!!)
Toast.makeText(
requireContext(),
"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) {
DataHolder.sampleReadCounter = 0
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)
}
}

View File

@@ -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 logTxtFilePath = MyUtils.getAppFolderPath(context) + getLogFileName()
testDetails?.csvPath = csvFilePath
testDetails?.reportPath = logTxtFilePath
testDetails?.deviceSerialNumber = deviceSerialNumber
if (isOnline) {
val storageRef = FirebaseStorage.getInstance().reference
val storageTestDetailsRef = storageRef.child("${testDetails?._id}/")
@@ -476,7 +477,7 @@ class TestRightViewModel @Inject constructor(
val csvUri = csvUploadTask.storage.downloadUrl.await().toString()
val logUri = logUploadTask.storage.downloadUrl.await().toString()
val serialNumber = Constants.STATICID.firstOrNull { it == deviceSerialNumber }
testDetails?.csvPath = csvUri
testDetails?.reportPath = logUri
@@ -512,6 +513,7 @@ class TestRightViewModel @Inject constructor(
userData.csvPath = csvUri
userData.reportPath = logUri
bulkAddResultTestToDb(userData)
} catch (exception: Exception) {
// Handle the exception appropriately (e.g., log the error, display an error message)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -62,7 +62,7 @@
android:layout_height="wrap_content"
android:hint="@string/login_id"
android:inputType="textCapCharacters"
android:maxLength="12" />
android:maxLength="13" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout

View File

@@ -54,6 +54,20 @@
app:layout_constraintStart_toStartOf="parent"
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.cardview.widget.CardView>

View File

@@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/nav_home">
app:startDestination="@+id/loginFragment">
<fragment
android:id="@+id/nav_home"
@@ -15,6 +15,10 @@
<action
android:id="@+id/action_nav_home_to_mainActivity"
app:destination="@id/mainActivity" />
<action
android:id="@+id/action_nav_home_to_loginFragment"
app:destination="@id/loginFragment"
app:popUpToInclusive="true"/>
</fragment>
<fragment