Logout Feature
This commit is contained in:
@@ -27,7 +27,7 @@ data class UserData(
|
||||
var isUnderTransfusion: Boolean? = false,
|
||||
var sickleCellHistory: String? = "",
|
||||
var userImageURL: String = "",
|
||||
var createdBy: String? = "",
|
||||
var registeredBy: String? = "",
|
||||
var createdAt: String? = "",
|
||||
var registrationCenterName: String? = "",
|
||||
){
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.hposregistration.ui.fragments
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -12,6 +13,7 @@ import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.example.hposregistration.adapters.UserListOfflineAdapter
|
||||
import com.example.hposregistration.adapters.UserListOnlineAdapter
|
||||
import com.example.hposregistration.data.Constant
|
||||
import com.example.hposregistration.data.user.UserData
|
||||
import com.example.hposregistration.ui.viewmodels.RegistrationViewModel
|
||||
import com.firebase.ui.firestore.FirestoreRecyclerOptions
|
||||
@@ -31,10 +33,13 @@ class UserListFragment : BaseFragment() {
|
||||
|
||||
private var isOnline = false
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentUserListBinding.inflate(inflater, container, false)
|
||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
setupViews()
|
||||
return binding.root
|
||||
}
|
||||
@@ -53,6 +58,9 @@ class UserListFragment : BaseFragment() {
|
||||
binding.btnRegisterUser.setOnClickListener {
|
||||
findNavController().navigate(R.id.action_userListFragment_to_registrationFragment)
|
||||
}
|
||||
binding.btnLogout.setOnClickListener {
|
||||
logoutUser(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
@@ -72,6 +80,33 @@ class UserListFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
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 saveUserId(userId: String) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constant.USER_ID, userId)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
private fun showUploadDialog(context: Context) {
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle("Upload DB Registration")
|
||||
|
||||
@@ -98,7 +98,7 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
||||
userData.createdAt = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
userData.createdBy = sharedPreference.getString(Constant.USER_ID, "")
|
||||
userData.registeredBy = sharedPreference.getString(Constant.USER_ID, "")
|
||||
viewModel.addUserToDatabase(userData)
|
||||
viewModel.deleteById(args.userId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user