diff --git a/.idea/shelf/Changes3.xml b/.idea/shelf/Changes3.xml
new file mode 100644
index 0000000..15b4ce4
--- /dev/null
+++ b/.idea/shelf/Changes3.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_04-12-2023_02_50_pm_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_04-12-2023_02_50_pm_[Changes]/shelved.patch
deleted file mode 100644
index e69de29..0000000
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_04-12-2023_02_50_pm__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_04-12-2023_02_50_pm__Changes_.xml
deleted file mode 100644
index 536290a..0000000
--- a/.idea/shelf/Uncommitted_changes_before_Checkout_at_04-12-2023_02_50_pm__Changes_.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
index 42afabf..ebe0879 100644
--- a/app/.gitignore
+++ b/app/.gitignore
@@ -1 +1,2 @@
-/build
\ No newline at end of file
+/build
+/google-services*
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 07b1ee5..4e0ca32 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -16,8 +16,8 @@ android {
applicationId "in.sminnovations.hposregistration"
minSdk 26
targetSdk 34
- versionCode 1
- versionName "1.0"
+ versionCode 8
+ versionName "1.0.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -46,6 +46,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+ implementation 'androidx.preference:preference-ktx:1.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
@@ -59,6 +60,8 @@ dependencies {
implementation 'com.google.firebase:firebase-storage-ktx'
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
implementation 'com.google.android.gms:play-services-auth:20.7.0'
+ implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
+ implementation("com.google.firebase:firebase-appdistribution-api-ktx:16.0.0-beta11")
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
@@ -91,14 +94,15 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
+ implementation 'com.opencsv:opencsv:5.5'
+
//Room
- implementation "androidx.room:room-ktx:2.6.0"
- implementation "androidx.room:room-runtime:2.6.0"
- kapt ("androidx.room:room-compiler:2.6.0")
+ implementation "androidx.room:room-ktx:2.6.1"
+ implementation "androidx.room:room-runtime:2.6.1"
+ kapt ("androidx.room:room-compiler:2.6.1")
// Barcode scanner
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
- implementation 'androidx.preference:preference-ktx:1.2.1'
- implementation 'androidx.preference:preference-ktx:1.2.1'
+
}
\ No newline at end of file
diff --git a/app/google-services.json b/app/google-services.json
deleted file mode 100644
index a593d99..0000000
--- a/app/google-services.json
+++ /dev/null
@@ -1,113 +0,0 @@
-{
- "project_info": {
- "project_number": "650071678820",
- "project_id": "hpos-af3cc",
- "storage_bucket": "hpos-af3cc.appspot.com"
- },
- "client": [
- {
- "client_info": {
- "mobilesdk_app_id": "1:650071678820:android:f1435a1c07f710036c6471",
- "android_client_info": {
- "package_name": "com.example.hposconsentform"
- }
- },
- "oauth_client": [
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ],
- "api_key": [
- {
- "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
- }
- ],
- "services": {
- "appinvite_service": {
- "other_platform_oauth_client": [
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ]
- }
- }
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:650071678820:android:7569c1cad4fc99916c6471",
- "android_client_info": {
- "package_name": "in.sminnovations.hposregistration"
- }
- },
- "oauth_client": [
- {
- "client_id": "650071678820-70kp5jvjda4r5diqch2kn4lc40p4f42g.apps.googleusercontent.com",
- "client_type": 1,
- "android_info": {
- "package_name": "in.sminnovations.hposregistration",
- "certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
- }
- },
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ],
- "api_key": [
- {
- "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
- }
- ],
- "services": {
- "appinvite_service": {
- "other_platform_oauth_client": [
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ]
- }
- }
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:650071678820:android:f96be19e5d43102b6c6471",
- "android_client_info": {
- "package_name": "in.sminnovations.hpostesting"
- }
- },
- "oauth_client": [
- {
- "client_id": "650071678820-l87dnr0bdj95get0khgnvfv2an1k6ogq.apps.googleusercontent.com",
- "client_type": 1,
- "android_info": {
- "package_name": "in.sminnovations.hpostesting",
- "certificate_hash": "7714b9268a81d0cf0fb178b0af8dbb630f8fc70a"
- }
- },
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ],
- "api_key": [
- {
- "current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
- }
- ],
- "services": {
- "appinvite_service": {
- "other_platform_oauth_client": [
- {
- "client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
- "client_type": 3
- }
- ]
- }
- }
- }
- ],
- "configuration_version": "1"
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 14f9ab4..9cda14d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -7,7 +7,9 @@
android:required="false" />
+
+
@@ -43,7 +45,7 @@
diff --git a/app/src/main/java/com/example/hposregistration/dao/MyDataBase.kt b/app/src/main/java/com/example/hposregistration/dao/MyDataBase.kt
index cdcf480..b2ff720 100644
--- a/app/src/main/java/com/example/hposregistration/dao/MyDataBase.kt
+++ b/app/src/main/java/com/example/hposregistration/dao/MyDataBase.kt
@@ -1,11 +1,36 @@
package com.example.hposregistration.dao
+import android.content.Context
import androidx.room.Database
+import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
+import androidx.room.migration.Migration
+import androidx.sqlite.db.SupportSQLiteDatabase
import com.example.hposregistration.data.user.UserData
-@Database(entities = [UserData::class], version = 1, exportSchema = false)
+@Database(entities = [UserData::class], version = 3, exportSchema = false)
abstract class MyDatabase : RoomDatabase() {
+
abstract fun userDao(): UserDao
-}
\ No newline at end of file
+
+ companion object {
+ val MIGRATION_2_3: Migration = object : Migration(2, 3) {
+ override fun migrate(database: SupportSQLiteDatabase) {
+ // Define the necessary SQL statements for migration from version 2 to 3
+ // For example, you can alter tables or create new ones
+ database.execSQL("ALTER TABLE user_table ADD COLUMN aadharIdSearch TEXT")
+ }
+ }
+
+ fun getInstance(context: Context): MyDatabase {
+ return Room.databaseBuilder(
+ context.applicationContext,
+ MyDatabase::class.java,
+ "my_database"
+ )
+ .addMigrations(MIGRATION_2_3)
+ .build()
+ }
+ }
+}
diff --git a/app/src/main/java/com/example/hposregistration/dao/UserDao.kt b/app/src/main/java/com/example/hposregistration/dao/UserDao.kt
index bdff697..3028322 100644
--- a/app/src/main/java/com/example/hposregistration/dao/UserDao.kt
+++ b/app/src/main/java/com/example/hposregistration/dao/UserDao.kt
@@ -20,4 +20,7 @@ interface UserDao {
@Query("DELETE FROM user_table WHERE _id = :id")
suspend fun deleteById(id: String)
+
+ @Query("UPDATE user_table SET isCSVCreated = :newValue WHERE _id = :id")
+ suspend fun updateCSVFieldById(id: String, newValue: Boolean)
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/data/MainRepository.kt b/app/src/main/java/com/example/hposregistration/data/MainRepository.kt
index 715827d..7151662 100644
--- a/app/src/main/java/com/example/hposregistration/data/MainRepository.kt
+++ b/app/src/main/java/com/example/hposregistration/data/MainRepository.kt
@@ -30,4 +30,8 @@ class MainRepository @Inject constructor(
return userFireBaseDao.addUserToDatabase(userData)
}
+ suspend fun updateCSVFieldById(id: String, isCSVCreated: Boolean) {
+ userDao.updateCSVFieldById(id, isCSVCreated)
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/data/datasource/LocalFileDataSource.kt b/app/src/main/java/com/example/hposregistration/data/datasource/LocalFileDataSource.kt
new file mode 100644
index 0000000..829bf9e
--- /dev/null
+++ b/app/src/main/java/com/example/hposregistration/data/datasource/LocalFileDataSource.kt
@@ -0,0 +1,124 @@
+package com.example.hpostesting.data.datasource
+
+import android.os.Environment
+import com.example.hposregistration.data.user.UserData
+
+import com.opencsv.CSVWriter
+import java.io.File
+import java.io.FileWriter
+import java.io.IOException
+
+class LocalFileDataSource {
+
+ fun saveCsvToDisk(filepath: String, contents: ArrayList>){
+ val writer = CSVWriter(FileWriter(filepath))
+ writer.writeAll(contents) // data is adding to csv
+ writer.close()
+ }
+
+ fun saveTextToDisk(filepath: String, contents: String){
+ val writer = FileWriter(File(filepath))
+
+ writer.append(contents)
+ writer.flush()
+ writer.close()
+ }
+
+
+ fun exportDataToCSV(
+ fileName: String, dataList: List
+ ): Boolean {
+ try {
+ val formattedFileName = fileName.replace(Regex("[^a-zA-Z0-9.-]"), "_") // Replace special characters with underscores
+ val filePath = File(getExternalStorageDirectory(), formattedFileName)
+ val writer = FileWriter(filePath)
+ val csvWriter = CSVWriter(writer)
+ // Write CSV header
+ val header = arrayOf(
+ "_id",
+ "name",
+ "bloodGroup",
+ "birthYear", // Include other fields from the data class
+ "state",
+ "abhaId",
+ "userImageURL",
+ "testStatus", // Assuming testStatus is a boolean field
+ "gender",
+ "appVersion",
+ "phoneNumber",
+ "careOf",
+ "maritalStatus",
+ "category",
+ "caste",
+ "subCaste",
+ "house",
+ "city",
+ "district",
+ "state",
+ "pinCode",
+ "isUnderMedication",
+ "isUnderTransfusion",
+ "sickleCellHistory",
+ "userImageURL",
+ "registeredBy",
+ "createdAt",
+ "registrationCenterName"
+
+ )
+ csvWriter.writeNext(header)
+
+ // Write data rows
+ for (data in dataList) {
+ val row = arrayOf(
+ data._id,
+ data.name,
+ data.bloodGroup,
+ data.birthYear ?: "", // Replace with the actual birthYear field
+ data.state,
+ data.abhaId,
+ data.userImageURL,
+ data.testStatus?.toString() ?: "",
+ data.gender,
+ data.appVersion ?: "",
+ data.phoneNumber,
+ data.careOf,
+ data.maritalStatus,
+ data.category,
+ data.caste,
+ data.subCaste ?: "",
+ data.house,
+ data.city,
+ data.district,
+ data.state,
+ data.pinCode,
+ data.isUnderMedication?.toString() ?: "",
+ data.isUnderTransfusion?.toString() ?: "",
+ data.sickleCellHistory ?: "",
+ data.userImageURL,
+ data.registeredBy ?: "",
+ data.createdAt ?: "",
+ data.registrationCenterName ?: ""
+
+ )
+ csvWriter.writeNext(row)
+ }
+ writer.close()
+ return true
+ } catch (e: IOException) {
+ e.printStackTrace()
+ return false
+ }
+ }
+
+ private fun getExternalStorageDirectory(): File {
+ val folder = File(Environment.getExternalStorageDirectory(), "HPOSRegistration")
+
+ if (!folder.exists()) {
+ folder.mkdirs()
+ }
+
+ return folder
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/data/user/UserData.kt b/app/src/main/java/com/example/hposregistration/data/user/UserData.kt
index 5ecc79d..8ba7c60 100644
--- a/app/src/main/java/com/example/hposregistration/data/user/UserData.kt
+++ b/app/src/main/java/com/example/hposregistration/data/user/UserData.kt
@@ -7,8 +7,11 @@ import androidx.room.PrimaryKey
data class UserData(
@PrimaryKey
var _id: String = "",
+ var _idSearch: String = "",
var abhaId: String = "",
+ var abhaIdSearch: String = "",
var aadharId: String = "",
+ var aadharIdSearch: String = "",
var name: String = "",
var birthYear: String = "",
var gender: String = "",
@@ -32,7 +35,9 @@ data class UserData(
var registeredBy: String? = "",
var createdAt: String? = "",
var registrationCenterName: String? = "",
- var testStatus: Boolean = false
+ var testStatus: Boolean = false,
+ var isCSVCreated: Boolean = false,
+ var localFlag: Boolean = false,
){
enum class Gender {
MALE,
diff --git a/app/src/main/java/com/example/hposregistration/di/AppModule.kt b/app/src/main/java/com/example/hposregistration/di/AppModule.kt
index 9f0bdf2..bda8c90 100644
--- a/app/src/main/java/com/example/hposregistration/di/AppModule.kt
+++ b/app/src/main/java/com/example/hposregistration/di/AppModule.kt
@@ -5,6 +5,7 @@ import android.content.Context
import androidx.room.Room
import com.example.hposregistration.dao.MyDatabase
import com.example.hposregistration.dao.UserDao
+import com.example.hpostesting.data.datasource.LocalFileDataSource
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -41,4 +42,10 @@ object AppModule {
fun provideContext(application: Application): Context {
return application.applicationContext
}
+
+ @Provides
+ @Singleton
+ fun provideLocalFileDataSource(): LocalFileDataSource {
+ return LocalFileDataSource()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/network/UserDao.kt b/app/src/main/java/com/example/hposregistration/network/UserDao.kt
index a05f0bf..b993bec 100644
--- a/app/src/main/java/com/example/hposregistration/network/UserDao.kt
+++ b/app/src/main/java/com/example/hposregistration/network/UserDao.kt
@@ -1,5 +1,6 @@
package com.example.hposregistration.network
+import androidx.room.Query
import com.example.hposregistration.data.Response
import com.example.hposregistration.data.user.UserData
import com.google.firebase.firestore.FirebaseFirestore
@@ -24,7 +25,12 @@ class UserDao {
}
}
+
+
// suspend fun getPatientList(): List {
// return patientCollection.get().await().toObjects(UserData::class.java)
// }
+
+
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/ui/activities/MainActivity.kt b/app/src/main/java/com/example/hposregistration/ui/activities/MainActivity.kt
index 0793368..85c53af 100644
--- a/app/src/main/java/com/example/hposregistration/ui/activities/MainActivity.kt
+++ b/app/src/main/java/com/example/hposregistration/ui/activities/MainActivity.kt
@@ -3,7 +3,11 @@ package com.example.hposregistration.ui.activities
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
+import android.widget.Toast
import com.example.hposregistration.data.LanguageManager
+import com.google.firebase.appdistribution.FirebaseAppDistribution
+import com.google.firebase.appdistribution.FirebaseAppDistributionException
+import com.google.firebase.crashlytics.FirebaseCrashlytics
import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hposregistration.databinding.ActivityMainBinding
@@ -11,17 +15,58 @@ import `in`.sminnovations.hposregistration.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
+
+
override fun attachBaseContext(newBase: Context?) {
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
LanguageManager.setLocale(newBase, languageCode)
super.attachBaseContext(newBase)
}
-
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}
+
+ override fun onResume() {
+ super.onResume()
+
+ val firebaseAppDistribution = FirebaseAppDistribution.getInstance()
+ firebaseAppDistribution.updateIfNewReleaseAvailable()
+ .addOnProgressListener { updateProgress ->
+
+ if (updateProgress.apkBytesDownloaded > 0) {
+ Toast.makeText(
+ this,
+ "${updateProgress.updateStatus}. ${updateProgress.apkBytesDownloaded / 1048576} /${updateProgress.apkFileTotalBytes / 1048576} MB",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ .addOnFailureListener { e ->
+ // (Optional) Handle errors.
+ if (e is FirebaseAppDistributionException) {
+ when (e.errorCode) {
+ FirebaseAppDistributionException.Status.NOT_IMPLEMENTED -> {
+ // SDK did nothing. This is expected when building for Play.
+ }
+
+ else -> {
+ // Handle other errors.
+ Toast.makeText(
+ this,
+ "AppDistribution error, status: ${e.errorCode}",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ FirebaseCrashlytics.getInstance().recordException(e)
+ }
+ }
+ .addOnSuccessListener {
+// Toast.makeText(this, "App Update: Success!", Toast.LENGTH_SHORT).show()
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hposregistration/ui/fragments/LanguageSettingsFragment.kt b/app/src/main/java/com/example/hposregistration/ui/fragments/LanguageSettingsFragment.kt
index 6533bbe..87de1a4 100644
--- a/app/src/main/java/com/example/hposregistration/ui/fragments/LanguageSettingsFragment.kt
+++ b/app/src/main/java/com/example/hposregistration/ui/fragments/LanguageSettingsFragment.kt
@@ -3,14 +3,10 @@ package com.example.hposregistration.ui.fragments
import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
-import android.preference.ListPreference
-import androidx.fragment.app.Fragment
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
+
+import android.widget.Toast
import com.example.hposregistration.data.LanguageManager
import `in`.sminnovations.hposregistration.R
diff --git a/app/src/main/java/com/example/hposregistration/ui/fragments/UserListFragment.kt b/app/src/main/java/com/example/hposregistration/ui/fragments/UserListFragment.kt
index 5b303e2..d660275 100644
--- a/app/src/main/java/com/example/hposregistration/ui/fragments/UserListFragment.kt
+++ b/app/src/main/java/com/example/hposregistration/ui/fragments/UserListFragment.kt
@@ -5,11 +5,13 @@ import android.content.Context
import android.content.DialogInterface
import android.content.SharedPreferences
import android.os.Bundle
+import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
+import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.example.hposregistration.adapters.UserListOfflineAdapter
@@ -18,11 +20,14 @@ 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
+import com.google.firebase.firestore.Query
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hposregistration.R
import `in`.sminnovations.hposregistration.databinding.FragmentUserListBinding
+import java.text.SimpleDateFormat
+import java.util.Date
@AndroidEntryPoint
class UserListFragment : BaseFragment() {
@@ -30,7 +35,7 @@ class UserListFragment : BaseFragment() {
private var _binding: FragmentUserListBinding? = null
private val binding get() = _binding!!
- private val viewModel by viewModels()
+ private val viewModel:RegistrationViewModel by activityViewModels()
private var isOnline = false
@@ -80,6 +85,10 @@ class UserListFragment : BaseFragment() {
showUploadDialog(requireContext())
}
+ binding.btnSaveLocal.setOnClickListener {
+ showDownloadDialog(requireContext())
+ }
+
binding.btnsettings.setOnClickListener{
findNavController().navigate(R.id.action_userListFragment_to_languageSettingsFragment)
@@ -164,7 +173,17 @@ class UserListFragment : BaseFragment() {
private fun fetchFromServer() {
binding.noList.visibility = View.GONE
binding.rvOrder.visibility = View.VISIBLE
+ val dateFormat = SimpleDateFormat("yyyy-MM-dd")
+ val currentDate = Date()
+ val today = dateFormat.format(currentDate)
val query = Firebase.firestore.collection("patientData")
+ .whereGreaterThanOrEqualTo("createdAt", today)
+ .orderBy("createdAt", Query.Direction.DESCENDING)
+ query.get().addOnSuccessListener {
+ if (it.documents.isEmpty() && isOnline) {
+ binding.emptyRegistrations.visibility = View.VISIBLE
+ }
+ }
val recyclerViewOptions =
FirestoreRecyclerOptions.Builder().setQuery(query, UserData::class.java)
.build()
@@ -173,6 +192,25 @@ class UserListFragment : BaseFragment() {
adapter.startListening()
}
+
+ private fun showDownloadDialog(context: Context) {
+ val builder = AlertDialog.Builder(context)
+ builder.setTitle(R.string.download_db_registration_title)
+ builder.setMessage(R.string.download_db_registration_message)
+
+ builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
+ downloadLocalDBData(dialog)
+ }
+
+ builder.setNegativeButton(R.string.cancel) { dialog, _ ->
+ dialog.dismiss()
+ }
+
+ val dialog = builder.create()
+ dialog.show()
+ }
+
+
private fun fetchFromLocalDB() {
binding.uploadData.visibility = View.GONE
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
@@ -195,6 +233,38 @@ class UserListFragment : BaseFragment() {
}
}
+
+ private fun downloadLocalDBData(dialog: DialogInterface) {
+ viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
+ try {
+ val downloadList = mutableListOf()
+
+ userDataList.forEach { userData ->
+ Log.d("DownloadDebug", "userData: $userData, isCSVCreated: ${userData.isCSVCreated}")
+ if (!userData.isCSVCreated) {
+ downloadList.add(userData)
+ }
+ }
+ // Log the size of downloadList for debugging
+ Log.d("DownloadDebug", "downloadList size: ${downloadList.size}")
+
+ if (downloadList.isNotEmpty()) {
+ // Call ViewModel function to create CSV with filtered data
+ viewModel.createCSV(downloadList, requireContext())
+ Toast.makeText(requireContext(), "CSV file downloaded successfully", Toast.LENGTH_SHORT).show()
+ } else {
+ Toast.makeText(requireContext(), "No data to download", Toast.LENGTH_SHORT).show()
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ Toast.makeText(requireContext(), "Error downloading CSV file", Toast.LENGTH_SHORT).show()
+ } finally {
+ dialog.dismiss()
+ }
+ }
+ }
+
+
private fun deteleIncompleteRegistration(userDataList: List) {
userDataList.forEach {
if (it.userImageURL.isEmpty()) {
diff --git a/app/src/main/java/com/example/hposregistration/ui/viewmodels/RegistrationViewModel.kt b/app/src/main/java/com/example/hposregistration/ui/viewmodels/RegistrationViewModel.kt
index 930e4ca..e1fa3a9 100644
--- a/app/src/main/java/com/example/hposregistration/ui/viewmodels/RegistrationViewModel.kt
+++ b/app/src/main/java/com/example/hposregistration/ui/viewmodels/RegistrationViewModel.kt
@@ -10,14 +10,21 @@ import com.example.hposregistration.data.MainRepository
import com.example.hposregistration.data.NetworkStatusLiveData
import com.example.hposregistration.data.Response
import com.example.hposregistration.data.user.UserData
+import com.example.hposregistration.dao.UserDao
+import com.example.hpostesting.data.datasource.LocalFileDataSource
import com.google.firebase.storage.FirebaseStorage
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
import javax.inject.Inject
@HiltViewModel
class RegistrationViewModel @Inject constructor(
private val mainRepository: MainRepository,
+ private val userdao: UserDao,
+ private val localFileDataSource: LocalFileDataSource,
context: Context
) : ViewModel() {
@@ -73,4 +80,25 @@ class RegistrationViewModel @Inject constructor(
fun deleteById(userId: String) = viewModelScope.launch {
mainRepository.deleteById(id = userId)
}
+
+ fun createCSV(userData: List, appContext: Context) =
+ viewModelScope.launch {
+ val fileName = "${getCurrentDateTime()}.csv"
+ if (localFileDataSource.exportDataToCSV(fileName, userData)) {
+ userData.forEach { data ->
+ data.localFlag = true
+ mainRepository.updateCSVFieldById(
+ data._id,
+ true
+ )
+ }
+ }
+ }
+
+ private fun getCurrentDateTime(): String {
+ val dateFormat = SimpleDateFormat("dd-MM-yy HH:mm:ss", Locale.getDefault())
+ val currentDateTime = Date()
+ return dateFormat.format(currentDateTime)
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/downloads.xml b/app/src/main/res/drawable/downloads.xml
new file mode 100644
index 0000000..17e7f58
--- /dev/null
+++ b/app/src/main/res/drawable/downloads.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/layout/fragment_user_list.xml b/app/src/main/res/layout/fragment_user_list.xml
index 4c3db74..dcc6b44 100644
--- a/app/src/main/res/layout/fragment_user_list.xml
+++ b/app/src/main/res/layout/fragment_user_list.xml
@@ -34,6 +34,20 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
+
+
+
+
क्या आप स्थानीय डीबी को क्लाउड पर अपलोड करना चाहते हैं?
अपलोड
अपलोड सफलतापूर्वक हुआ
-
+ प्रदर्शन के लिए कोई पंजीकरण उपलब्ध नहीं है
कृपया सही लॉगिन आईडी दर्ज करें
कृपया सही पासवर्ड दर्ज करें
गलत पासवर्ड
diff --git a/app/src/main/res/values-kn/strings.xml b/app/src/main/res/values-kn/strings.xml
index 0bdd11e..d984f3a 100644
--- a/app/src/main/res/values-kn/strings.xml
+++ b/app/src/main/res/values-kn/strings.xml
@@ -129,6 +129,7 @@
ತಪ್ಪಾದ ಪಾಸ್ವರ್ಡ್
ತಪ್ಪಾದ ಬಳಕೆದಾರ ಐಡಿ
ನೀವು ಆಧಾರ್ ಐಡನ್ನು ಸ್ಕ್ಯಾನ್ ಮಾಡಿದ್ದೀರಿ, ದಯವಿಟ್ಟು ಆಧಾರ್ ಐಡನ್ನು ನೀವು ಸ್ಕ್ಯಾನ್ ಮಾಡಿದ ಮತ್ತು ಅಭಾ ಐಡನ್ನು ಕೈಯಾರೆ ನಮೂದಿಸಿ
+ ಪ್ರದರ್ಶಿಸಲಿರುವ ಯಾವ ನೋಂದಾಯಿಗಳೂ ಲಭ್ಯವಿಲ್ಲ
ನೀವು ಅಭಾ ಐಡಿಯನ್ನು ಸ್ಕ್ಯಾನ್ ಮಾಡಿದ್ದೀರಿ
ನೀವು ಆಧಾರ್ ಐಡನ್ನು ಸ್ಕ್ಯಾನ್ ಮಾಡಿದಿರಿ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a600066..9272a1e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -136,11 +136,18 @@
User Id
Name
OK
+
+ No registrations available for display
+
+
Add Blood Group
You have scanned the Aadhar ID, need to enter Aadhar ID number you have scanned and Abha ID manually
You have scanned the Abha ID
You have scanned the Aadhar ID
-
+ Download CSV
+ Download DB Tests
+ Do you want to download the local DB tests in CSV format?
+ Upload done successfully
- NT-A
- NT-B