mirror of
https://github.com/ente-io/ente.git
synced 2025-08-07 07:03:35 +00:00
fix: update code for backup status
This commit is contained in:
parent
094e08c387
commit
d625816eb3
@ -1,4 +1,5 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import "dart:async";
|
||||
import "dart:collection";
|
||||
|
||||
import "package:collection/collection.dart";
|
||||
@ -6,6 +7,7 @@ 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/events/preview_updated_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";
|
||||
@ -27,6 +29,9 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
LinkedHashMap<String, BackupItem> items = FileUploader.instance.allBackups;
|
||||
List<BackupItem>? result;
|
||||
var previewResult = PreviewVideoStore.instance.previews;
|
||||
StreamSubscription? _fileUploadedSubscription;
|
||||
StreamSubscription? _backupUpdatedSubscription;
|
||||
StreamSubscription? _previewUpdatedSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -55,7 +60,8 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
(a, b) => (b.file.uploadedFileID!).compareTo(a.file.uploadedFileID!),
|
||||
)
|
||||
.toList();
|
||||
Bus.instance.on<FileUploadedEvent>().listen((event) {
|
||||
_fileUploadedSubscription =
|
||||
Bus.instance.on<FileUploadedEvent>().listen((event) {
|
||||
result!.insert(
|
||||
0,
|
||||
BackupItem(
|
||||
@ -71,10 +77,16 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
}
|
||||
|
||||
void checkBackupUpdatedEvent() {
|
||||
Bus.instance.on<BackupUpdatedEvent>().listen((event) {
|
||||
_backupUpdatedSubscription =
|
||||
Bus.instance.on<BackupUpdatedEvent>().listen((event) {
|
||||
items = event.items;
|
||||
safeSetState();
|
||||
});
|
||||
_previewUpdatedSubscription =
|
||||
Bus.instance.on<PreviewUpdatedEvent>().listen((event) {
|
||||
previewResult = event.items;
|
||||
safeSetState();
|
||||
});
|
||||
}
|
||||
|
||||
void safeSetState() {
|
||||
@ -83,6 +95,14 @@ class _BackupStatusScreenState extends State<BackupStatusScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_fileUploadedSubscription?.cancel();
|
||||
_backupUpdatedSubscription?.cancel();
|
||||
_previewUpdatedSubscription?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<BackupItem> items = this.items.values.toList().sorted(
|
||||
|
Loading…
x
Reference in New Issue
Block a user