BackLog file added for nagpur consignment
This commit is contained in:
@@ -68,7 +68,9 @@ class LocalFileDataSource {
|
||||
"IsUnderTransfusion",
|
||||
"SickleCellHistory",
|
||||
"RegisteredBy",
|
||||
"UserImageURL"
|
||||
"userAbhaRegistrationLog",
|
||||
"userDetailslog",
|
||||
"UserImageURL",
|
||||
)
|
||||
csvWriter.writeNext(header)
|
||||
val imagesFolder = File(getExternalStorageDirectory(), "images${getCurrentDateTime()}")
|
||||
@@ -112,7 +114,10 @@ class LocalFileDataSource {
|
||||
data.isUnderTransfusion?.toString() ?: "",
|
||||
data.sickleCellHistory ?: "",
|
||||
data.registeredBy ?: "",
|
||||
localImageFile?.absolutePath ?: "" // Use the local image file path in the CSV
|
||||
data.userAbhaRegistrationLog,
|
||||
data.userDetailsLog,
|
||||
localImageFile?.absolutePath ?: "" ,
|
||||
|
||||
)
|
||||
csvWriter.writeNext(row)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ data class UserData(
|
||||
var testStatus: Boolean = false,
|
||||
var isCSVCreated: Boolean = false,
|
||||
var localFlag: Boolean = false,
|
||||
var userAbhaRegistrationLog:String = "",
|
||||
var userDetailsLog: String = "",
|
||||
){
|
||||
enum class Gender {
|
||||
MALE,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.hposregistration.ui.fragments.registration
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -19,6 +21,8 @@ import com.journeyapps.barcodescanner.ScanIntentResult
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hposregistration.R
|
||||
import `in`.sminnovations.hposregistration.databinding.FragmentAbhaRegistrationBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
@@ -29,7 +33,7 @@ class AbhaRegistrationFragment : BaseFragment() {
|
||||
|
||||
private var _binding: FragmentAbhaRegistrationBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private val viewModel by viewModels<RegistrationViewModel>()
|
||||
private val args: AbhaRegistrationFragmentArgs by navArgs()
|
||||
private var userData = UserData()
|
||||
@@ -49,6 +53,8 @@ class AbhaRegistrationFragment : BaseFragment() {
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentAbhaRegistrationBinding.inflate(inflater, container, false)
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("userAbhaRegistrationLog", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -90,10 +96,18 @@ class AbhaRegistrationFragment : BaseFragment() {
|
||||
abhaId = abhaIdInput
|
||||
registrationCenterName = centerName
|
||||
_id = aadharId + userName.substring(0, 3).uppercase() + centerName.substring(0, 3).uppercase()
|
||||
userAbhaRegistrationLog = "$abhaIdInput,$userName,$aadharIdInput,$centerName"
|
||||
}
|
||||
|
||||
|
||||
|
||||
viewModel.insert(userData)
|
||||
|
||||
val userDataString = userData.userAbhaRegistrationLog// Make sure this provides a meaningful string representation of userData
|
||||
sharedPreference.edit()
|
||||
.putString("userAbhaRegistrationLog", userDataString)
|
||||
.apply()
|
||||
|
||||
navigateToUserDetailsFragment(userData._id)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.example.hposregistration.ui.fragments.registration
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -19,6 +21,9 @@ import com.example.hposregistration.ui.viewmodels.RegistrationViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.sminnovations.hposregistration.R
|
||||
import `in`.sminnovations.hposregistration.databinding.FragmentReviewDetailsRegistrationBinding
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStreamWriter
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
@@ -53,6 +58,9 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
||||
viewModel.getUserByID(args.userId)
|
||||
viewModel.userData.observe(viewLifecycleOwner) { user ->
|
||||
userData = user
|
||||
userData.userAbhaRegistrationLog =
|
||||
sharedPreference.getString("userAbhaRegistrationLog", "").toString()
|
||||
userData.userDetailsLog = sharedPreference.getString("userDeatilsLOg", "").toString()
|
||||
setUserData(user)
|
||||
}
|
||||
|
||||
@@ -61,6 +69,7 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
logUserData()
|
||||
if (isOnline) {
|
||||
// showProgressBar(binding.progressBarCL)
|
||||
// addDataToFirebase()
|
||||
@@ -186,11 +195,125 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
||||
userData.createdAt = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
userData.userAbhaRegistrationLog =
|
||||
sharedPreference.getString("userAbhaRegistrationLog", "").toString()
|
||||
userData.userDetailsLog = sharedPreference.getString("userDeatilsLOg", "").toString()
|
||||
|
||||
val useAbhaRegistrationLog = sharedPreference.getString("userAbhaRegistrationLog", "").toString()
|
||||
val userDetailsLog = sharedPreference.getString("userDetailslog", "").toString()
|
||||
userData.userAbhaRegistrationLog= useAbhaRegistrationLog
|
||||
userData.userDetailsLog = userDetailsLog
|
||||
|
||||
}
|
||||
val userDataString = serializeUserData(userData)
|
||||
saveUserDataToSharedPreferences(userDataString)
|
||||
}
|
||||
|
||||
private fun serializeUserData(userData: UserData): String {
|
||||
return listOf(
|
||||
userData._id,
|
||||
userData.abhaId,
|
||||
userData.aadharId,
|
||||
userData.name,
|
||||
userData.birthYear,
|
||||
userData.gender,
|
||||
userData.phoneNumber,
|
||||
userData.careOf,
|
||||
userData.maritalStatus,
|
||||
userData.category,
|
||||
userData.caste,
|
||||
userData.subCaste ?: "",
|
||||
userData.house,
|
||||
userData.city,
|
||||
userData.district,
|
||||
userData.state,
|
||||
userData.pinCode,
|
||||
userData.registrationCenterName ?: "",
|
||||
userData.isUnderMedication?.toString() ?: "",
|
||||
userData.isUnderTransfusion?.toString() ?: "",
|
||||
userData.sickleCellHistory ?: "",
|
||||
userData.userImageURL,
|
||||
userData.appVersion ?: "",
|
||||
userData.createdAt ?: ""
|
||||
).joinToString(",")
|
||||
}
|
||||
private fun saveUserDataToSharedPreferences(userDataString: String) {
|
||||
val editor = sharedPreference.edit()
|
||||
editor.putString("PREFERENCE_NAME", userDataString)
|
||||
editor.apply()
|
||||
}
|
||||
private fun retrieveUserDataFromSharedPreferences(): UserData? {
|
||||
val userDataString = sharedPreference.getString("PREFERENCE_NAME", null)
|
||||
return userDataString?.let {
|
||||
val parts = it.split(",")
|
||||
(if (parts[22].isNotEmpty()) parts[22] else null)?.let { it1 ->
|
||||
UserData(
|
||||
_id = parts[0],
|
||||
abhaId = parts[1],
|
||||
aadharId = parts[2],
|
||||
name = parts[3],
|
||||
birthYear = parts[4],
|
||||
gender = parts[5],
|
||||
phoneNumber = parts[6],
|
||||
careOf = parts[7],
|
||||
maritalStatus = parts[8],
|
||||
category = parts[9],
|
||||
caste = parts[10],
|
||||
subCaste = if (parts[11].isNotEmpty()) parts[11] else null,
|
||||
house = parts[12],
|
||||
city = parts[13],
|
||||
district = parts[14],
|
||||
state = parts[15],
|
||||
pinCode = parts[16],
|
||||
registrationCenterName = if (parts[17].isNotEmpty()) parts[17] else null,
|
||||
isUnderMedication = parts[18].takeIf { it.equals("true", true) || it.equals("false", true) }?.toBoolean(),
|
||||
isUnderTransfusion = parts[19].takeIf { it.equals("true", true) || it.equals("false", true) }?.toBoolean(),
|
||||
sickleCellHistory = if (parts[20].isNotEmpty()) parts[20] else null,
|
||||
userImageURL = parts[21],
|
||||
appVersion = it1,
|
||||
createdAt = if (parts[23].isNotEmpty()) parts[23] else null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("LogNotTimber")
|
||||
private fun logUserData() {
|
||||
val userData = retrieveUserDataFromSharedPreferences()
|
||||
if (userData != null) {
|
||||
val userDataString = userDataToString(userData)
|
||||
writeToLogFile(userDataString)
|
||||
} else {
|
||||
Log.e("UserDataLog", "No user data found in SharedPreferences")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("LogNotTimber")
|
||||
private fun writeToLogFile(data: String) {
|
||||
try {
|
||||
val logFileName = "RegistrationLog.txt"
|
||||
val file = File(requireContext().filesDir, logFileName)
|
||||
if (!file.exists()) {
|
||||
file.createNewFile()
|
||||
}
|
||||
|
||||
val fileOutputStream = FileOutputStream(file, true) // True for append mode
|
||||
val writer = OutputStreamWriter(fileOutputStream)
|
||||
writer.append(data).append("\n")
|
||||
writer.close()
|
||||
fileOutputStream.close()
|
||||
|
||||
Log.d("UserDataLog", "Log file updated: $logFileName")
|
||||
} catch (e: Exception) {
|
||||
Log.e("UserDataLog", "Error writing to log file", e)
|
||||
}
|
||||
}
|
||||
private fun userDataToString(userData: UserData): String {
|
||||
// Convert your UserData object to a string format
|
||||
// You might want to format this nicely for readability
|
||||
return userData.toString() // Implement a more detailed conversion based on your needs
|
||||
}
|
||||
private fun navigateToUserListFragment() {
|
||||
hideProgressBar(binding.progressBarCL)
|
||||
|
||||
@@ -198,9 +321,9 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
||||
ReviewDetailsRegistrationFragmentDirections.actionReviewDetailsRegistrationFragmentToUserListFragment()
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.hposregistration.ui.fragments.registration
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -29,13 +31,15 @@ class UserDetailsRegistrationFragment : Fragment() {
|
||||
private val viewModel by viewModels<RegistrationViewModel>()
|
||||
|
||||
private lateinit var userData: UserData
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private val args: UserDetailsRegistrationFragmentArgs by navArgs()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = FragmentUserDetailsRegistrationBinding.inflate(inflater, container, false)
|
||||
sharedPreference =
|
||||
requireContext().getSharedPreferences("userDeatilsLOg", Context.MODE_PRIVATE)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -180,6 +184,36 @@ class UserDetailsRegistrationFragment : Fragment() {
|
||||
if (verifyUserDetails()) {
|
||||
userData._id = args.userId
|
||||
viewModel.insert(userData)
|
||||
userData.userDetailsLog = "${userData.birthYear}," +
|
||||
"${userData.gender}," +
|
||||
"${userData.phoneNumber}," +
|
||||
"${userData.careOf}," +
|
||||
"${userData.maritalStatus}," +
|
||||
"${userData.category}," +
|
||||
"${userData.caste}," +
|
||||
"${userData.subCaste ?: ""}," + // Using Elvis operator for nullable fields
|
||||
"${userData.appVersion}," +
|
||||
"${userData.house}," +
|
||||
"${userData.city}," +
|
||||
"${userData.district}," +
|
||||
"${userData.state}," +
|
||||
"${userData.pinCode}," +
|
||||
"${userData.bloodGroup}," +
|
||||
"${userData.isUnderMedication ?: false}," + // Converting null to false
|
||||
"${userData.isUnderTransfusion ?: false}," +
|
||||
"${userData.sickleCellHistory ?: ""}," +
|
||||
"${userData.userImageURL}," +
|
||||
"${userData.registeredBy ?: ""}," +
|
||||
"${userData.createdAt ?: ""}," +
|
||||
"${userData.registrationCenterName ?: ""}," +
|
||||
"${userData.testStatus}," +
|
||||
"${userData.isCSVCreated}," +
|
||||
"${userData.localFlag}"
|
||||
|
||||
val userDataString = userData.userDetailsLog// Make sure this provides a meaningful string representation of userData
|
||||
sharedPreference.edit()
|
||||
.putString("userDetailslog", userDataString)
|
||||
.apply()
|
||||
navigateToCaptureUserImageFragment()
|
||||
} else {
|
||||
showToast(getString(R.string.enter_details_properly))
|
||||
|
||||
Reference in New Issue
Block a user