CSV FILE CREATED
This commit is contained in:
@@ -5,6 +5,7 @@ import androidx.room.Dao
|
|||||||
import androidx.room.Insert
|
import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.Update
|
||||||
import com.example.hposregistration.data.user.UserData
|
import com.example.hposregistration.data.user.UserData
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -23,4 +24,8 @@ interface UserDao {
|
|||||||
|
|
||||||
@Query("UPDATE user_table SET isCSVCreated = :newValue WHERE _id = :id")
|
@Query("UPDATE user_table SET isCSVCreated = :newValue WHERE _id = :id")
|
||||||
suspend fun updateCSVFieldById(id: String, newValue: Boolean)
|
suspend fun updateCSVFieldById(id: String, newValue: Boolean)
|
||||||
|
|
||||||
|
@Update
|
||||||
|
suspend fun updateUserData(userData: List<UserData>)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.example.hposregistration.data
|
|||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import com.example.hposregistration.dao.UserDao
|
import com.example.hposregistration.dao.UserDao
|
||||||
import com.example.hposregistration.data.user.UserData
|
import com.example.hposregistration.data.user.UserData
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -34,4 +36,6 @@ class MainRepository @Inject constructor(
|
|||||||
userDao.updateCSVFieldById(id, isCSVCreated)
|
userDao.updateCSVFieldById(id, isCSVCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.hpostesting.data.datasource
|
package com.example.hpostesting.data.datasource
|
||||||
|
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import android.util.Log
|
||||||
import com.example.hposregistration.data.user.UserData
|
import com.example.hposregistration.data.user.UserData
|
||||||
|
|
||||||
import com.opencsv.CSVWriter
|
import com.opencsv.CSVWriter
|
||||||
@@ -29,7 +30,7 @@ class LocalFileDataSource {
|
|||||||
fileName: String, dataList: List<UserData>
|
fileName: String, dataList: List<UserData>
|
||||||
): Boolean {
|
): Boolean {
|
||||||
try {
|
try {
|
||||||
val formattedFileName = fileName.replace(Regex("[^a-zA-Z0-9.-]"), "_") // Replace special characters with underscores
|
val formattedFileName = fileName.replace(Regex("[^a-zA-Z0-9.-]"), "_")
|
||||||
val filePath = File(getExternalStorageDirectory(), formattedFileName)
|
val filePath = File(getExternalStorageDirectory(), formattedFileName)
|
||||||
val writer = FileWriter(filePath)
|
val writer = FileWriter(filePath)
|
||||||
val csvWriter = CSVWriter(writer)
|
val csvWriter = CSVWriter(writer)
|
||||||
@@ -106,19 +107,24 @@ class LocalFileDataSource {
|
|||||||
return true
|
return true
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
Log.e("CSVExport", "Error exporting data to CSV: ${e.message}")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getExternalStorageDirectory(): File {
|
private fun getExternalStorageDirectory(): File {
|
||||||
val folder = File(Environment.getExternalStorageDirectory(), "HPOSRegistration")
|
val directory = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "HPOSRegistration")
|
||||||
|
|
||||||
if (!folder.exists()) {
|
if (!directory.exists()) {
|
||||||
folder.mkdirs()
|
if (!directory.mkdirs()) {
|
||||||
|
Log.e("CSVExport", "Error creating directory: ${directory.absolutePath}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return directory
|
||||||
return folder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -73,8 +73,9 @@ class UserListFragment : BaseFragment() {
|
|||||||
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
viewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
isOnline = isNetworkAvailable
|
isOnline = isNetworkAvailable
|
||||||
fetchFromServer()
|
fetchFromLocalDB()
|
||||||
checkForLocalDBData()
|
// fetchFromServer()
|
||||||
|
// checkForLocalDBData()
|
||||||
} else {
|
} else {
|
||||||
isOnline = isNetworkAvailable
|
isOnline = isNetworkAvailable
|
||||||
fetchFromLocalDB()
|
fetchFromLocalDB()
|
||||||
@@ -180,9 +181,9 @@ class UserListFragment : BaseFragment() {
|
|||||||
.whereGreaterThanOrEqualTo("createdAt", today)
|
.whereGreaterThanOrEqualTo("createdAt", today)
|
||||||
.orderBy("createdAt", Query.Direction.DESCENDING)
|
.orderBy("createdAt", Query.Direction.DESCENDING)
|
||||||
query.get().addOnSuccessListener {
|
query.get().addOnSuccessListener {
|
||||||
if (it.documents.isEmpty() && isOnline) {
|
// if (it.documents.isEmpty() && isOnline) {
|
||||||
binding.emptyRegistrations.visibility = View.VISIBLE
|
// binding.emptyRegistrations.visibility = View.VISIBLE
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
val recyclerViewOptions =
|
val recyclerViewOptions =
|
||||||
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
FirestoreRecyclerOptions.Builder<UserData>().setQuery(query, UserData::class.java)
|
||||||
@@ -214,10 +215,10 @@ class UserListFragment : BaseFragment() {
|
|||||||
private fun fetchFromLocalDB() {
|
private fun fetchFromLocalDB() {
|
||||||
binding.uploadData.visibility = View.GONE
|
binding.uploadData.visibility = View.GONE
|
||||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
if (isOnline) {
|
// if (isOnline) {
|
||||||
binding.noList.visibility = View.GONE
|
// binding.noList.visibility = View.GONE
|
||||||
binding.rvOrder.visibility = View.VISIBLE
|
// binding.rvOrder.visibility = View.VISIBLE
|
||||||
} else {
|
// } else {
|
||||||
if (userDataList.isEmpty()) {
|
if (userDataList.isEmpty()) {
|
||||||
binding.noList.visibility = View.VISIBLE
|
binding.noList.visibility = View.VISIBLE
|
||||||
binding.rvOrder.visibility = View.GONE
|
binding.rvOrder.visibility = View.GONE
|
||||||
@@ -229,7 +230,6 @@ class UserListFragment : BaseFragment() {
|
|||||||
adapter.differ.submitList(userDataList)
|
adapter.differ.submitList(userDataList)
|
||||||
binding.rvOrder.adapter = adapter
|
binding.rvOrder.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,6 +245,8 @@ class UserListFragment : BaseFragment() {
|
|||||||
downloadList.add(userData)
|
downloadList.add(userData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Log the size of downloadList for debugging
|
// Log the size of downloadList for debugging
|
||||||
Log.d("DownloadDebug", "downloadList size: ${downloadList.size}")
|
Log.d("DownloadDebug", "downloadList size: ${downloadList.size}")
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,14 @@ class ReviewDetailsRegistrationFragment : BaseFragment() {
|
|||||||
|
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
if (isOnline) {
|
if (isOnline) {
|
||||||
showProgressBar(binding.progressBarCL)
|
// showProgressBar(binding.progressBarCL)
|
||||||
addDataToFirebase()
|
// addDataToFirebase()
|
||||||
|
Toast.makeText(
|
||||||
|
requireContext(),
|
||||||
|
R.string.internt_not_local,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
navigateToUserListFragment()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class RegistrationViewModel @Inject constructor(
|
|||||||
|
|
||||||
val userData = MutableLiveData<UserData>()
|
val userData = MutableLiveData<UserData>()
|
||||||
|
|
||||||
val allUserData = mainRepository.allUsers
|
val allUserData = userdao.getAll()
|
||||||
|
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ class RegistrationViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getCurrentDateTime(): String {
|
private fun getCurrentDateTime(): String {
|
||||||
val dateFormat = SimpleDateFormat("dd-MM-yy HH:mm:ss", Locale.getDefault())
|
val dateFormat = SimpleDateFormat("dd-MM-yy", Locale.getDefault())
|
||||||
val currentDateTime = Date()
|
val currentDateTime = Date()
|
||||||
return dateFormat.format(currentDateTime)
|
return dateFormat.format(currentDateTime)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,19 +34,7 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/emptyRegistrations"
|
|
||||||
style="@style/title1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/empty_registrations"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/noList"
|
android:id="@+id/noList"
|
||||||
|
|||||||
@@ -115,12 +115,8 @@
|
|||||||
<string name="enter_father_husband_name">पिता / पति का नाम दर्ज करें</string>
|
<string name="enter_father_husband_name">पिता / पति का नाम दर्ज करें</string>
|
||||||
<string name="do_log_out">क्या आप ऐप्लिकेशन से लॉग आउट करना चाहते हैं?</string>
|
<string name="do_log_out">क्या आप ऐप्लिकेशन से लॉग आउट करना चाहते हैं?</string>
|
||||||
<string name="log_out">लॉग आउट</string>
|
<string name="log_out">लॉग आउट</string>
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
<string name="no_data_available">स्थानीय डेटाबेस में कोई डेटा उपलब्ध नहीं है</string>
|
<string name="no_data_available">स्थानीय डेटाबेस में कोई डेटा उपलब्ध नहीं है</string>
|
||||||
<string name="test_details_stored_locally">टेस्ट विवरण स्थानीय रूप से संग्रहित हैं</string>
|
<string name="test_details_stored_locally">टेस्ट विवरण स्थानीय रूप से संग्रहित हैं</string>
|
||||||
>>>>>>> parent of 5d42da8 (csv)
|
|
||||||
|
|
||||||
<string name="upload_db_registration">डीबी पंजीकरण अपलोड करें</string>
|
<string name="upload_db_registration">डीबी पंजीकरण अपलोड करें</string>
|
||||||
<string name="upload_local_db_to_cloud">क्या आप स्थानीय डीबी को क्लाउड पर अपलोड करना चाहते हैं?</string>
|
<string name="upload_local_db_to_cloud">क्या आप स्थानीय डीबी को क्लाउड पर अपलोड करना चाहते हैं?</string>
|
||||||
<string name="upload">अपलोड</string>
|
<string name="upload">अपलोड</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user