From 1e6d91b50f42b6494c6cda74897157235995cf3e Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Fri, 6 Sep 2024 02:38:54 +0530 Subject: [PATCH 1/5] fix(upload-status): always sort list --- mobile/lib/models/backup/backup_item_status.dart | 4 ++-- mobile/lib/ui/settings/backup/backup_status_screen.dart | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mobile/lib/models/backup/backup_item_status.dart b/mobile/lib/models/backup/backup_item_status.dart index b4aedfa562..3133903500 100644 --- a/mobile/lib/models/backup/backup_item_status.dart +++ b/mobile/lib/models/backup/backup_item_status.dart @@ -1,7 +1,7 @@ enum BackupItemStatus { - inBackground, + retry, inQueue, + inBackground, uploading, completed, - retry, } diff --git a/mobile/lib/ui/settings/backup/backup_status_screen.dart b/mobile/lib/ui/settings/backup/backup_status_screen.dart index 0d7199ca47..a32b1e8e09 100644 --- a/mobile/lib/ui/settings/backup/backup_status_screen.dart +++ b/mobile/lib/ui/settings/backup/backup_status_screen.dart @@ -1,6 +1,7 @@ // ignore_for_file: public_member_api_docs, sort_constructors_first import "dart:collection"; +import "package:collection/collection.dart"; import 'package:flutter/material.dart'; import "package:photos/core/event_bus.dart"; import "package:photos/events/backup_updated_event.dart"; @@ -37,7 +38,9 @@ class _BackupStatusScreenState extends State { @override Widget build(BuildContext context) { - final List items = this.items.values.toList(); + final List items = this.items.values.toList().sorted( + (a, b) => a.status.index.compareTo(b.status.index), + ); return Scaffold( body: CustomScrollView( From 80aebe3869030f29bb17c8626cb82180239e486f Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Mon, 9 Sep 2024 20:53:14 +0530 Subject: [PATCH 2/5] fix(upload-status): show all uploads, even from past --- mobile/lib/models/backup/backup_item.dart | 2 +- .../lib/models/backup/backup_item_status.dart | 2 +- mobile/lib/services/search_service.dart | 1 + .../ui/settings/backup/backup_item_card.dart | 2 +- .../settings/backup/backup_status_screen.dart | 161 ++++++++++-------- mobile/lib/utils/file_uploader.dart | 6 +- 6 files changed, 101 insertions(+), 73 deletions(-) diff --git a/mobile/lib/models/backup/backup_item.dart b/mobile/lib/models/backup/backup_item.dart index 957f0f883c..a1c57a6fe3 100644 --- a/mobile/lib/models/backup/backup_item.dart +++ b/mobile/lib/models/backup/backup_item.dart @@ -7,7 +7,7 @@ class BackupItem { final BackupItemStatus status; final EnteFile file; final int collectionID; - final Completer completer; + final Completer? completer; final Object? error; BackupItem({ diff --git a/mobile/lib/models/backup/backup_item_status.dart b/mobile/lib/models/backup/backup_item_status.dart index 3133903500..75579e77b6 100644 --- a/mobile/lib/models/backup/backup_item_status.dart +++ b/mobile/lib/models/backup/backup_item_status.dart @@ -3,5 +3,5 @@ enum BackupItemStatus { inQueue, inBackground, uploading, - completed, + uploaded, } diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dart index 88462d7add..f88fbbf86d 100644 --- a/mobile/lib/services/search_service.dart +++ b/mobile/lib/services/search_service.dart @@ -67,6 +67,7 @@ class SearchService { Future> getAllFiles() async { if (_cachedFilesFuture != null) { + _logger.fine("Reading all files from cache"); return _cachedFilesFuture!; } _logger.fine("Reading all files from db"); diff --git a/mobile/lib/ui/settings/backup/backup_item_card.dart b/mobile/lib/ui/settings/backup/backup_item_card.dart index 40be26cbdc..e25bc659d8 100644 --- a/mobile/lib/ui/settings/backup/backup_item_card.dart +++ b/mobile/lib/ui/settings/backup/backup_item_card.dart @@ -123,7 +123,7 @@ class _BackupItemCardState extends State { color: colorScheme.primary700, ), ), - BackupItemStatus.completed => const SizedBox( + BackupItemStatus.uploaded => const SizedBox( width: 24, height: 24, child: Icon( diff --git a/mobile/lib/ui/settings/backup/backup_status_screen.dart b/mobile/lib/ui/settings/backup/backup_status_screen.dart index a32b1e8e09..6f7618173d 100644 --- a/mobile/lib/ui/settings/backup/backup_status_screen.dart +++ b/mobile/lib/ui/settings/backup/backup_status_screen.dart @@ -5,10 +5,12 @@ import "package:collection/collection.dart"; import 'package:flutter/material.dart'; import "package:photos/core/event_bus.dart"; import "package:photos/events/backup_updated_event.dart"; +import "package:photos/events/file_uploaded_event.dart"; import "package:photos/generated/l10n.dart"; import "package:photos/models/backup/backup_item.dart"; -import 'package:photos/ui/components/title_bar_title_widget.dart'; -import 'package:photos/ui/components/title_bar_widget.dart'; +import "package:photos/models/backup/backup_item_status.dart"; +import "package:photos/services/search_service.dart"; +import "package:photos/ui/components/title_bar_widget.dart"; import "package:photos/ui/settings/backup/backup_item_card.dart"; import "package:photos/utils/file_uploader.dart"; @@ -21,12 +23,47 @@ class BackupStatusScreen extends StatefulWidget { class _BackupStatusScreenState extends State { LinkedHashMap items = FileUploader.instance.allBackups; + List? result; @override void initState() { super.initState(); checkBackupUpdatedEvent(); + getAllFiles(); + } + + Future getAllFiles() async { + result = (await SearchService.instance.getAllFiles()) + .map( + (e) { + return BackupItem( + status: BackupItemStatus.uploaded, + file: e, + collectionID: e.collectionID ?? 0, + completer: null, + ); + }, + ) + .toList() + .sorted( + (a, b) => (a.file.uploadedFileID ?? 0) + .compareTo(b.file.uploadedFileID ?? 0), + ); + Bus.instance.on().listen((event) { + setState(() { + result!.insert( + 0, + BackupItem( + status: BackupItemStatus.uploaded, + file: event.file, + collectionID: event.file.collectionID ?? 0, + completer: null, + ), + ); + }); + }); + setState(() {}); } void checkBackupUpdatedEvent() { @@ -42,73 +79,63 @@ class _BackupStatusScreenState extends State { (a, b) => a.status.index.compareTo(b.status.index), ); + final allItems = [ + ...items.where((element) => element.status != BackupItemStatus.uploaded), + if (result != null) ...result!, + ]; + return Scaffold( - body: CustomScrollView( - primary: false, - slivers: [ - TitleBarWidget( - flexibleSpaceTitle: TitleBarTitleWidget( - title: S.of(context).backupStatus, - ), - ), - items.isEmpty - ? SliverFillRemaining( - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 60, - vertical: 12, - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.cloud_upload_outlined, - color: - Theme.of(context).brightness == Brightness.light - ? const Color.fromRGBO(0, 0, 0, 0.6) - : const Color.fromRGBO(255, 255, 255, 0.6), - ), - const SizedBox(height: 16), - Text( - S.of(context).backupStatusDescription, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 16, - height: 20 / 16, - color: - Theme.of(context).brightness == Brightness.light - ? const Color(0xFF000000).withOpacity(0.7) - : const Color(0xFFFFFFFF).withOpacity(0.7), - ), - ), - const SizedBox(height: 48), - ], - ), - ), - ) - : SliverList( - delegate: SliverChildBuilderDelegate( - (delegateBuildContext, index) { - return Padding( - padding: const EdgeInsets.symmetric( - vertical: 20, - horizontal: 16, - ), - child: ListView.builder( - shrinkWrap: true, - primary: false, - itemBuilder: (context, index) { - return BackupItemCard(item: items[index]); - }, - itemCount: items.length, - ), - ); - }, - childCount: 1, - ), - ), - ], + appBar: AppBar( + leadingWidth: 32, + title: TitleWidget( + title: S.of(context).backupStatus, + caption: null, + isTitleH2WithoutLeading: false, + ), ), + body: allItems.isEmpty + ? Padding( + padding: const EdgeInsets.symmetric( + horizontal: 60, + vertical: 12, + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.cloud_upload_outlined, + color: Theme.of(context).brightness == Brightness.light + ? const Color.fromRGBO(0, 0, 0, 0.6) + : const Color.fromRGBO(255, 255, 255, 0.6), + ), + const SizedBox(height: 16), + Text( + S.of(context).backupStatusDescription, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 16, + height: 20 / 16, + color: Theme.of(context).brightness == Brightness.light + ? const Color(0xFF000000).withOpacity(0.7) + : const Color(0xFFFFFFFF).withOpacity(0.7), + ), + ), + const SizedBox(height: 48), + ], + ), + ) + : ListView.builder( + padding: const EdgeInsets.symmetric( + vertical: 20, + horizontal: 16, + ), + shrinkWrap: true, + primary: false, + itemBuilder: (context, index) { + return BackupItemCard(item: allItems[index]); + }, + itemCount: allItems.length, + ), ); } } diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart index 0b3ee1c4bc..4be9e2d8fd 100644 --- a/mobile/lib/utils/file_uploader.dart +++ b/mobile/lib/utils/file_uploader.dart @@ -318,7 +318,7 @@ class FileUploader { ); _queue.remove(localID)!.completer.complete(uploadedFile); _allBackups[localID] = - _allBackups[localID]!.copyWith(status: BackupItemStatus.completed); + _allBackups[localID]!.copyWith(status: BackupItemStatus.uploaded); Bus.instance.fire(BackupUpdatedEvent(_allBackups)); return uploadedFile; } catch (e) { @@ -446,7 +446,7 @@ class FileUploader { final result = await _tryToUpload(file, collectionID, true); if (isInQueue) { _allBackups[file.localID!] = _allBackups[file.localID]!.copyWith( - status: BackupItemStatus.completed, + status: BackupItemStatus.uploaded, ); Bus.instance.fire(BackupUpdatedEvent(_allBackups)); } @@ -1343,7 +1343,7 @@ class FileUploader { _logger.info("Background upload success detected"); completer?.complete(dbFile); _allBackups[upload.key] = _allBackups[upload.key]! - .copyWith(status: BackupItemStatus.completed); + .copyWith(status: BackupItemStatus.uploaded); } else { _logger.info("Background upload failure detected"); completer?.completeError(SilentlyCancelUploadsError()); From d2f2028f55fcba2970634f2a3811e5662eebd286 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Mon, 9 Sep 2024 21:04:50 +0530 Subject: [PATCH 3/5] fix(intl): remove extra { in front of {{{count --- mobile/lib/l10n/intl_ja.arb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/lib/l10n/intl_ja.arb b/mobile/lib/l10n/intl_ja.arb index eabbed8c14..cb128bef83 100644 --- a/mobile/lib/l10n/intl_ja.arb +++ b/mobile/lib/l10n/intl_ja.arb @@ -433,7 +433,7 @@ "selectAll": "全て選択", "skip": "スキップ", "updatingFolderSelection": "フォルダの選択をアップデート中", - "itemCount": "{count, plural, one{{{count} アイテム} other {{count} アイテム}}", + "itemCount": "{count, plural, one{{count} アイテム} other {{count} アイテム}}", "deleteItemCount": "{count, plural,=1 {{count} 個の項目を削除} other {{count} 個の項目を削除}}", "duplicateItemsGroup": "{count} 個のファイル、それぞれ{formattedSize}", "@duplicateItemsGroup": { From a3c0e46f1de54d62b9b9ad70a3307538eecbed53 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Tue, 10 Sep 2024 19:07:15 +0530 Subject: [PATCH 4/5] fix: remove unwanted log --- mobile/lib/services/search_service.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dart index f88fbbf86d..88462d7add 100644 --- a/mobile/lib/services/search_service.dart +++ b/mobile/lib/services/search_service.dart @@ -67,7 +67,6 @@ class SearchService { Future> getAllFiles() async { if (_cachedFilesFuture != null) { - _logger.fine("Reading all files from cache"); return _cachedFilesFuture!; } _logger.fine("Reading all files from db"); From a947cc69de45b65ca0831799150e1b8fabbf0028 Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Tue, 10 Sep 2024 19:08:53 +0530 Subject: [PATCH 5/5] fix(upload-status): only get files that have upload file id and are owned by user --- .../lib/ui/settings/backup/backup_status_screen.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mobile/lib/ui/settings/backup/backup_status_screen.dart b/mobile/lib/ui/settings/backup/backup_status_screen.dart index 6f7618173d..abd5abf9e7 100644 --- a/mobile/lib/ui/settings/backup/backup_status_screen.dart +++ b/mobile/lib/ui/settings/backup/backup_status_screen.dart @@ -9,6 +9,7 @@ import "package:photos/events/file_uploaded_event.dart"; import "package:photos/generated/l10n.dart"; import "package:photos/models/backup/backup_item.dart"; import "package:photos/models/backup/backup_item_status.dart"; +import "package:photos/models/file/extensions/file_props.dart"; import "package:photos/services/search_service.dart"; import "package:photos/ui/components/title_bar_widget.dart"; import "package:photos/ui/settings/backup/backup_item_card.dart"; @@ -35,6 +36,9 @@ class _BackupStatusScreenState extends State { Future getAllFiles() async { result = (await SearchService.instance.getAllFiles()) + .where( + (e) => e.uploadedFileID != null && e.isOwner, + ) .map( (e) { return BackupItem( @@ -45,11 +49,10 @@ class _BackupStatusScreenState extends State { ); }, ) - .toList() .sorted( - (a, b) => (a.file.uploadedFileID ?? 0) - .compareTo(b.file.uploadedFileID ?? 0), - ); + (a, b) => (a.file.uploadedFileID!).compareTo(b.file.uploadedFileID!), + ) + .toList(); Bus.instance.on().listen((event) { setState(() { result!.insert(