Skip to content

Commit

Permalink
[mob][photos] Fix blank screen coming up when an error is thrown when…
Browse files Browse the repository at this point in the history
… freeing up space (#3792)
  • Loading branch information
ashilkn authored Oct 21, 2024
2 parents 1c02d6d + a5016d3 commit 745513f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 52 deletions.
1 change: 0 additions & 1 deletion mobile/lib/l10n/intl_ro.arb
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,6 @@
"referFriendsAnd2xYourPlan": "Recomandați un prieten și dublați-vă planul",
"shareAlbumHint": "Deschideți un album și atingeți butonul de distribuire din dreapta sus pentru a distribui.",
"itemsShowTheNumberOfDaysRemainingBeforePermanentDeletion": "Articolele afișează numărul de zile rămase până la ștergerea definitivă",
"trashDaysLeft": "{count, plural, one {} few {{count} zile}=0 {} =1 {O zi} other {{count} de zile}}",
"@trashDaysLeft": {
"description": "Text to indicate number of days remaining before permanent deletion",
"placeholders": {
Expand Down
1 change: 0 additions & 1 deletion mobile/lib/l10n/intl_uk.arb
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,6 @@
"encryptingBackup": "Шифруємо резервну копію...",
"syncStopped": "Синхронізацію зупинено",
"syncProgress": "{completed} / {total} спогадів збережено",
"uploadingMultipleMemories": "{count, plural, few {Зберігаємо {count} спогади...} many {Зберігаємо {count} спогадів...}}",
"uploadingSingleMemory": "Зберігаємо 1 спогад...",
"@syncProgress": {
"description": "Text to tell user how many memories have been preserved",
Expand Down
109 changes: 59 additions & 50 deletions mobile/lib/utils/delete_file_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,60 +328,69 @@ Future<bool> deleteLocalFiles(
final List<String> deletedIDs = [];
final List<String> localAssetIDs = [];
final List<String> localSharedMediaIDs = [];
for (String id in localIDs) {
if (id.startsWith(oldSharedMediaIdentifier) ||
id.startsWith(sharedMediaIdentifier)) {
localSharedMediaIDs.add(id);
try {
for (String id in localIDs) {
if (id.startsWith(oldSharedMediaIdentifier) ||
id.startsWith(sharedMediaIdentifier)) {
localSharedMediaIDs.add(id);
} else {
localAssetIDs.add(id);
}
}
deletedIDs.addAll(await _tryDeleteSharedMediaFiles(localSharedMediaIDs));

final bool shouldDeleteInBatches =
await isAndroidSDKVersionLowerThan(android11SDKINT);
if (shouldDeleteInBatches) {
_logger.info("Deleting in batches");
deletedIDs
.addAll(await deleteLocalFilesInBatches(context, localAssetIDs));
} else {
localAssetIDs.add(id);
_logger.info("Deleting in one shot");
deletedIDs
.addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs));
}
// In IOS, the library returns no error and fail to delete any file is
// there's any shared file. As a stop-gap solution, we initiate deletion in
// batches. Similar in Android, for large number of files, we have observed
// that the library fails to delete any file. So, we initiate deletion in
// batches.
if (deletedIDs.isEmpty) {
deletedIDs.addAll(
await deleteLocalFilesInBatches(
context,
localAssetIDs,
maximumBatchSize: 1000,
minimumBatchSize: 10,
),
);
_logger
.severe("iOS free-space fallback, deleted ${deletedIDs.length} files "
"in batches}");
}
}
deletedIDs.addAll(await _tryDeleteSharedMediaFiles(localSharedMediaIDs));

final bool shouldDeleteInBatches =
await isAndroidSDKVersionLowerThan(android11SDKINT);
if (shouldDeleteInBatches) {
_logger.info("Deleting in batches");
deletedIDs.addAll(await deleteLocalFilesInBatches(context, localAssetIDs));
} else {
_logger.info("Deleting in one shot");
deletedIDs.addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs));
}
// In IOS, the library returns no error and fail to delete any file is
// there's any shared file. As a stop-gap solution, we initiate deletion in
// batches. Similar in Android, for large number of files, we have observed
// that the library fails to delete any file. So, we initiate deletion in
// batches.
if (deletedIDs.isEmpty) {
deletedIDs.addAll(
await deleteLocalFilesInBatches(
context,
localAssetIDs,
maximumBatchSize: 1000,
minimumBatchSize: 10,
),
);
_logger
.severe("iOS free-space fallback, deleted ${deletedIDs.length} files "
"in batches}");
}
if (deletedIDs.isNotEmpty) {
final deletedFiles = await FilesDB.instance.getLocalFiles(deletedIDs);
await FilesDB.instance.deleteLocalFiles(deletedIDs);
_logger.info(deletedFiles.length.toString() + " files deleted locally");
Bus.instance.fire(
LocalPhotosUpdatedEvent(deletedFiles, source: "deleteLocal"),
);
return true;
} else {
//On android 10, even if files were deleted, deletedIDs is empty.
//This is a workaround so that users are not shown an error message on
//android 10
if (!await isAndroidSDKVersionLowerThan(android11SDKINT)) {
showToast(context, S.of(context).couldNotFreeUpSpace);
return false;
if (deletedIDs.isNotEmpty) {
final deletedFiles = await FilesDB.instance.getLocalFiles(deletedIDs);
await FilesDB.instance.deleteLocalFiles(deletedIDs);
_logger.info(deletedFiles.length.toString() + " files deleted locally");
Bus.instance.fire(
LocalPhotosUpdatedEvent(deletedFiles, source: "deleteLocal"),
);
return true;
} else {
//On android 10, even if files were deleted, deletedIDs is empty.
//This is a workaround so that users are not shown an error message on
//android 10
if (!await isAndroidSDKVersionLowerThan(android11SDKINT)) {
showToast(context, S.of(context).couldNotFreeUpSpace);
return false;
}
return true;
}
return true;
} catch (e, s) {
_logger.severe("Could not delete local files", e, s);
showToast(context, S.of(context).couldNotFreeUpSpace);
return false;
}
}

Expand Down

0 comments on commit 745513f

Please sign in to comment.