[mob](upload-status): fixes (#3141)
## Description These PR does following fixes to upload status: - Always maintain order or backup status. - failed -> in queue -> in background -> uploading -> uploaded - Show previous uploaded items in this too
This commit is contained in:
@@ -7,7 +7,7 @@ class BackupItem {
|
||||
final BackupItemStatus status;
|
||||
final EnteFile file;
|
||||
final int collectionID;
|
||||
final Completer<EnteFile> completer;
|
||||
final Completer<EnteFile>? completer;
|
||||
final Object? error;
|
||||
|
||||
BackupItem({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
enum BackupItemStatus {
|
||||
inBackground,
|
||||
inQueue,
|
||||
uploading,
|
||||
completed,
|
||||
retry,
|
||||
inQueue,
|
||||
inBackground,
|
||||
uploading,
|
||||
uploaded,
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class _BackupItemCardState extends State<BackupItemCard> {
|
||||
color: colorScheme.primary700,
|
||||
),
|
||||
),
|
||||
BackupItemStatus.completed => const SizedBox(
|
||||
BackupItemStatus.uploaded => const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Icon(
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
// 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";
|
||||
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/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";
|
||||
import "package:photos/utils/file_uploader.dart";
|
||||
|
||||
@@ -20,12 +24,49 @@ class BackupStatusScreen extends StatefulWidget {
|
||||
|
||||
class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
LinkedHashMap<String, BackupItem> items = FileUploader.instance.allBackups;
|
||||
List<BackupItem>? result;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
checkBackupUpdatedEvent();
|
||||
getAllFiles();
|
||||
}
|
||||
|
||||
Future<void> getAllFiles() async {
|
||||
result = (await SearchService.instance.getAllFiles())
|
||||
.where(
|
||||
(e) => e.uploadedFileID != null && e.isOwner,
|
||||
)
|
||||
.map(
|
||||
(e) {
|
||||
return BackupItem(
|
||||
status: BackupItemStatus.uploaded,
|
||||
file: e,
|
||||
collectionID: e.collectionID ?? 0,
|
||||
completer: null,
|
||||
);
|
||||
},
|
||||
)
|
||||
.sorted(
|
||||
(a, b) => (a.file.uploadedFileID!).compareTo(b.file.uploadedFileID!),
|
||||
)
|
||||
.toList();
|
||||
Bus.instance.on<FileUploadedEvent>().listen((event) {
|
||||
setState(() {
|
||||
result!.insert(
|
||||
0,
|
||||
BackupItem(
|
||||
status: BackupItemStatus.uploaded,
|
||||
file: event.file,
|
||||
collectionID: event.file.collectionID ?? 0,
|
||||
completer: null,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void checkBackupUpdatedEvent() {
|
||||
@@ -37,75 +78,67 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<BackupItem> items = this.items.values.toList();
|
||||
final List<BackupItem> items = this.items.values.toList().sorted(
|
||||
(a, b) => a.status.index.compareTo(b.status.index),
|
||||
);
|
||||
|
||||
final allItems = <BackupItem>[
|
||||
...items.where((element) => element.status != BackupItemStatus.uploaded),
|
||||
if (result != null) ...result!,
|
||||
];
|
||||
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
primary: false,
|
||||
slivers: <Widget>[
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -1345,7 +1345,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());
|
||||
|
||||
Reference in New Issue
Block a user