added code for uploading logs only once

This commit is contained in:
Mariya
2024-02-29 14:18:09 +05:30
parent f7dc879c75
commit 80ab69c772

View File

@@ -338,6 +338,14 @@ class HomeFragment : Fragment() {
// "Log uploaded ${response.data.data?.filename}", // "Log uploaded ${response.data.data?.filename}",
// Toast.LENGTH_SHORT // Toast.LENGTH_SHORT
// ).show() // ).show()
if (!hasLogsBeenUploaded()) {
// Your code to upload logs
// Assuming the upload process is initiated here
// After successful upload, save the flag
saveUploadSuccessFlag(true)
}
} }
is Result.Error -> { is Result.Error -> {
@@ -378,7 +386,7 @@ class HomeFragment : Fragment() {
response.exception.let { message -> response.exception.let { message ->
Toast.makeText( Toast.makeText(
activity, activity,
"An error occurred in uploading logs: $message", "$message",
Toast.LENGTH_LONG Toast.LENGTH_LONG
) )
.show() .show()
@@ -1097,4 +1105,14 @@ class HomeFragment : Fragment() {
return matchResult?.groups?.get(1)?.value ?: "" return matchResult?.groups?.get(1)?.value ?: ""
} }
private fun saveUploadSuccessFlag(isSuccess: Boolean) {
sharedPreference = requireActivity().getSharedPreferences("AppPrefs", Context.MODE_PRIVATE)
sharedPreference.edit().putBoolean("LogsUploaded", isSuccess).apply()
}
private fun hasLogsBeenUploaded(): Boolean {
sharedPreference = requireActivity().getSharedPreferences("AppPrefs", Context.MODE_PRIVATE)
return sharedPreference.getBoolean("LogsUploaded", false)
}
} }