Neeraj Gupta před 2 roky
rodič
revize
97bf760c3b

+ 35 - 0
lib/models/files_split.dart

@@ -0,0 +1,35 @@
+import 'package:photos/models/file.dart';
+
+class FilesSplit {
+  final List<File> pendingUploads;
+  final List<File> ownedByCurrentUser;
+  final List<File> ownedByOtherUsers;
+
+  FilesSplit({
+    required this.pendingUploads,
+    required this.ownedByCurrentUser,
+    required this.ownedByOtherUsers,
+  });
+
+  int get totalFileOwnedCount =>
+      pendingUploads.length + ownedByCurrentUser.length;
+
+  static split(Iterable<File> files, int currentUserID) {
+    final List<File> ownedByCurrentUser = [],
+        ownedByOtherUsers = [],
+        pendingUploads = [];
+    for (var f in files) {
+      if (f.ownerID == null || f.uploadedFileID == null) {
+        pendingUploads.add(f);
+      } else if (f.ownerID == currentUserID) {
+        ownedByCurrentUser.add(f);
+      } else {
+        ownedByOtherUsers.add(f);
+      }
+      return FilesSplit(
+        pendingUploads: pendingUploads,
+        ownedByCurrentUser: ownedByCurrentUser,
+        ownedByOtherUsers: ownedByOtherUsers,
+      );
+    }
+  }

+ 0 - 16
lib/models/selected_file_breakup.dart

@@ -1,16 +0,0 @@
-import 'package:photos/models/file.dart';
-
-class SelectedFileSplit {
-  final List<File> pendingUploads;
-  final List<File> ownedByCurrentUser;
-  final List<File> ownedByOtherUsers;
-
-  SelectedFileSplit({
-    required this.pendingUploads,
-    required this.ownedByCurrentUser,
-    required this.ownedByOtherUsers,
-  });
-
-  int get totalFileOwnedCount =>
-      pendingUploads.length + ownedByCurrentUser.length;
-}

+ 0 - 21
lib/models/selected_files.dart

@@ -3,7 +3,6 @@ import 'package:flutter/foundation.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/events/clear_selections_event.dart';
 import 'package:photos/models/file.dart';
-import 'package:photos/models/selected_file_breakup.dart';
 
 class SelectedFiles extends ChangeNotifier {
   final files = <File>{};
@@ -66,26 +65,6 @@ class SelectedFiles extends ChangeNotifier {
     return false;
   }
 
-  SelectedFileSplit split(int currentUseID) {
-    final List<File> ownedByCurrentUser = [],
-        ownedByOtherUsers = [],
-        pendingUploads = [];
-    for (var f in files) {
-      if (f.ownerID == null || f.uploadedFileID == null) {
-        pendingUploads.add(f);
-      } else if (f.ownerID == currentUseID) {
-        ownedByCurrentUser.add(f);
-      } else {
-        ownedByOtherUsers.add(f);
-      }
-    }
-    return SelectedFileSplit(
-      pendingUploads: pendingUploads,
-      ownedByCurrentUser: ownedByCurrentUser,
-      ownedByOtherUsers: ownedByOtherUsers,
-    );
-  }
-
   void clearAll() {
     Bus.instance.fire(ClearSelectionsEvent());
     lastSelections.addAll(files);

+ 4 - 4
lib/ui/viewer/actions/file_selection_actions_widget.dart

@@ -5,9 +5,9 @@ import 'package:page_transition/page_transition.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/models/collection.dart';
 import 'package:photos/models/device_collection.dart';
+import 'package:photos/models/files_split.dart';
 import 'package:photos/models/gallery_type.dart';
 import 'package:photos/models/magic_metadata.dart';
-import 'package:photos/models/selected_file_breakup.dart';
 import 'package:photos/models/selected_files.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/hidden_service.dart';
@@ -47,7 +47,7 @@ class FileSelectionActionWidget extends StatefulWidget {
 
 class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
   late int currentUserID;
-  late SelectedFileSplit split;
+  late FilesSplit split;
   late CollectionActions collectionActions;
 
   // _cachedCollectionForSharedLink is primarly used to avoid creating duplicate
@@ -58,7 +58,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
   @override
   void initState() {
     currentUserID = Configuration.instance.getUserID()!;
-    split = widget.selectedFiles.split(currentUserID);
+    split = FilesSplit.split(widget.selectedFiles.files, currentUserID);
     widget.selectedFiles.addListener(_selectFileChangeListener);
     collectionActions = CollectionActions(CollectionsService.instance);
     super.initState();
@@ -74,7 +74,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     if (_cachedCollectionForSharedLink != null) {
       _cachedCollectionForSharedLink = null;
     }
-    split = widget.selectedFiles.split(currentUserID);
+    split = FilesSplit.split(widget.selectedFiles.files, currentUserID);
     if (mounted) {
       setState(() => {});
     }