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