Fixed the issues of creating registration folder inside the device, when data stored locally
This commit is contained in:
@@ -47,6 +47,7 @@ dependencies {
|
||||
implementation 'com.google.android.material:material:1.11.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||
implementation 'androidx.games:games-activity:2.0.2'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
|
||||
tools:ignore="ScopedStorage" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.hposregistration.data.datasource
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import com.example.hposregistration.data.user.UserData
|
||||
@@ -10,7 +11,6 @@ import java.io.FileOutputStream
|
||||
import java.io.FileWriter
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@@ -71,13 +71,11 @@ class LocalFileDataSource {
|
||||
"userImageURL"
|
||||
)
|
||||
csvWriter.writeNext(header)
|
||||
|
||||
// Create a separate folder for user images
|
||||
val imagesFolder = File(getExternalStorageDirectory(), "Images/${getCurrentDateTime()}")
|
||||
val imagesFolder = File(getExternalStorageDirectory(), "Images${getCurrentDateTime()}")
|
||||
// val imagesFolder = File(getExternalStorageDirectory(), "Images")
|
||||
if (!imagesFolder.exists()) {
|
||||
if (!imagesFolder.mkdirs()) {
|
||||
Log.e("CSVExport", "Error creating images folder: ${imagesFolder.absolutePath}")
|
||||
Log.e("DirectoryCreation", "Error creating images folder: ${imagesFolder.absolutePath}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,14 +148,15 @@ class LocalFileDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun getExternalStorageDirectory(): File {
|
||||
return File(
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
|
||||
"HPOSRegistration"
|
||||
)
|
||||
}
|
||||
val folder = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "HposRegister")
|
||||
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs()
|
||||
}
|
||||
|
||||
return folder
|
||||
}
|
||||
private fun getCurrentDateTime(): String {
|
||||
val dateFormat = SimpleDateFormat("dd-MM-yy", Locale.getDefault())
|
||||
val currentDateTime = Date()
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.example.hposregistration.ui.fragments
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.media.audiofx.BassBoost
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -20,10 +26,12 @@ 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.androidgamesdk.gametextinput.Settings
|
||||
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 dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import `in`.sminnovations.hposregistration.R
|
||||
import `in`.sminnovations.hposregistration.databinding.FragmentUserListBinding
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -40,6 +48,8 @@ class UserListFragment : BaseFragment() {
|
||||
private var isOnline = false
|
||||
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private val REQUEST_CODE_MANAGE_EXTERNAL_STORAGE = 123
|
||||
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
@@ -47,7 +57,20 @@ class UserListFragment : BaseFragment() {
|
||||
_binding = FragmentUserListBinding.inflate(inflater, container, false)
|
||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||
setupViews()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
val intent = Intent(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
|
||||
intent.data = Uri.parse("package:" + requireContext().packageName)
|
||||
startActivityForResult(intent, REQUEST_CODE_MANAGE_EXTERNAL_STORAGE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return binding.root
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -252,6 +275,7 @@ class UserListFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("LogNotTimber")
|
||||
private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
var csvDownloaded = false
|
||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
@@ -306,4 +330,5 @@ class UserListFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ class RegistrationViewModel @Inject constructor(
|
||||
mainRepository.deleteById(id = userId)
|
||||
}
|
||||
|
||||
fun createCSV(userData: List<UserData>, appContext: Context) =
|
||||
fun createCSV(userData: List<UserData>, context: Context) =
|
||||
viewModelScope.launch {
|
||||
val fileName = "${getCurrentDateTime()}.csv"
|
||||
if (localFileDataSource.exportDataToCSV(fileName, userData)) {
|
||||
val fileName = "HPOS${getCurrentDate()}.csv"
|
||||
if (localFileDataSource.exportDataToCSV(fileName, userData,context)) {
|
||||
userData.forEach { data ->
|
||||
data.localFlag = true
|
||||
mainRepository.updateCSVFieldById(
|
||||
@@ -103,4 +103,10 @@ class RegistrationViewModel @Inject constructor(
|
||||
return dateFormat.format(currentDateTime)
|
||||
}
|
||||
|
||||
|
||||
private fun getCurrentDate(): String {
|
||||
val dateFormat = SimpleDateFormat("dd-MM-yy", Locale.getDefault())
|
||||
val currentDate = Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@
|
||||
<string name="center_name_error">Center name can\'t be empty or less than 3 characters</string>
|
||||
<string name="registration_success">Registration Done Successfully</string>
|
||||
<string name="internt_not_local">Internet not available, test details stored locally</string>
|
||||
<string name="local">test details stored locally</string>
|
||||
<string name="local">details stored locally</string>
|
||||
<string name="no_data_available">No data available in the local database</string>
|
||||
|
||||
<string name="enter_details_properly">Please enter all the details properly</string>
|
||||
|
||||
Reference in New Issue
Block a user