fix(upload-status): show all uploads, even from past

This commit is contained in:
Prateek Sunal
2024-09-09 20:53:14 +05:30
parent 1e6d91b50f
commit 80aebe3869
6 changed files with 101 additions and 73 deletions

View File

@@ -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({

View File

@@ -3,5 +3,5 @@ enum BackupItemStatus {
inQueue,
inBackground,
uploading,
completed,
uploaded,
}

View File

@@ -67,6 +67,7 @@ class SearchService {
Future<List<EnteFile>> getAllFiles() async {
if (_cachedFilesFuture != null) {
_logger.fine("Reading all files from cache");
return _cachedFilesFuture!;
}
_logger.fine("Reading all files from db");

View File

@@ -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(

View File

@@ -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<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())
.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<FileUploadedEvent>().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<BackupStatusScreen> {
(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,
),
);
}
}

View File

@@ -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());