Skip to content

Commit

Permalink
Fix wrong snackbar being displayed when importing files on low memory
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyDL-Infomaniak committed May 23, 2024
1 parent 8e11fd2 commit b64f0c9
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ class ImportFilesDialog : DialogFragment() {
val errorCount = importCount - successCount

if (errorCount > 0) {
val errorMessage = resources.getQuantityString(R.plurals.snackBarUploadError, errorCount, errorCount)
showSnackbar(errorMessage, showAboveFab = true)
if (isLowMemory()) {
showSnackbar(R.string.uploadOutOfMemoryError, showAboveFab = true)
} else {
val errorMessage = resources.getQuantityString(R.plurals.snackBarUploadError, errorCount, errorCount)
showSnackbar(errorMessage, showAboveFab = true)
}
}

if (successCount > 0) mainViewModel.refreshActivities.value = true
Expand Down Expand Up @@ -113,32 +117,27 @@ class ImportFilesDialog : DialogFragment() {

private suspend fun initUpload(uri: Uri) = withContext(Dispatchers.IO) {
requireContext().contentResolver.query(uri, null, null, null, null)?.use { cursor ->
if (isLowMemory()) return@withContext

if (cursor.moveToFirst()) {
val fileName = cursor.getFileName(uri)
val (fileCreatedAt, fileModifiedAt) = getFileDates(cursor)

when {
isLowMemory() -> withContext(Dispatchers.Main) {
showSnackbar(R.string.uploadOutOfMemoryError, showAboveFab = true)
}
else -> {
val outputFile = getOutputFile(uri, fileModifiedAt)
ensureActive()
UploadFile(
uri = outputFile.toUri().toString(),
driveId = navArgs.driveId,
fileCreatedAt = fileCreatedAt,
fileModifiedAt = fileModifiedAt,
fileName = fileName,
fileSize = outputFile.length(),
remoteFolder = navArgs.folderId,
type = UploadFile.Type.UPLOAD.name,
userId = AccountUtils.currentUserId,
).store()
successCount++
currentImportFile = null
}
}
val outputFile = getOutputFile(uri, fileModifiedAt)
ensureActive()
UploadFile(
uri = outputFile.toUri().toString(),
driveId = navArgs.driveId,
fileCreatedAt = fileCreatedAt,
fileModifiedAt = fileModifiedAt,
fileName = fileName,
fileSize = outputFile.length(),
remoteFolder = navArgs.folderId,
type = UploadFile.Type.UPLOAD.name,
userId = AccountUtils.currentUserId,
).store()
successCount++
currentImportFile = null
}
}
}
Expand Down

0 comments on commit b64f0c9

Please sign in to comment.