Browse Source

changes in getting filesCount

ashilkn 2 years ago
parent
commit
11a6724868

+ 5 - 10
lib/db/files_db.dart

@@ -7,7 +7,6 @@ import 'package:logging/logging.dart';
 import 'package:path/path.dart';
 import 'package:path_provider/path_provider.dart';
 import 'package:photos/models/backup_status.dart';
-import 'package:photos/models/count_of_file_types.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_load_result.dart';
 import 'package:photos/models/file_type.dart';
@@ -1286,21 +1285,17 @@ class FilesDB {
     return deduplicatedFiles;
   }
 
-  Future<CountOfFileTypes> fetchPhotoAndVideoCount(int userID) async {
+  Future<Map<int, int>> fetchFilesCountbyType(int userID) async {
     final db = await instance.database;
     final result = await db.rawQuery(
       "SELECT $columnFileType, COUNT(DISTINCT $columnUploadedFileID) FROM $filesTable WHERE $columnUploadedFileID != -1 AND $columnOwnerID == $userID GROUP BY $columnFileType",
     );
-    int photosCount = 0;
-    int videosCount = 0;
+
+    final filesCount = <int, int>{};
     for (var e in result) {
-      if (e[columnFileType] == 0) {
-        photosCount = e.values.last;
-      } else if (e[columnFileType] == 1) {
-        videosCount = e.values.last;
-      }
+      filesCount.addAll({e[columnFileType]: e.values.last});
     }
-    return CountOfFileTypes(photosCount: photosCount, videosCount: videosCount);
+    return filesCount;
   }
 
   Map<String, dynamic> _getRowForFile(File file) {

+ 0 - 9
lib/models/count_of_file_types.dart

@@ -1,9 +0,0 @@
-class CountOfFileTypes {
-  final int photosCount;
-  final int videosCount;
-
-  CountOfFileTypes({
-    this.photosCount = 0,
-    this.videosCount = 0,
-  });
-}

+ 21 - 0
lib/models/user_details.dart

@@ -118,3 +118,24 @@ class FamilyData {
     );
   }
 }
+
+class FilesCount {
+  final Map<int, int> filesCount;
+  FilesCount(this.filesCount);
+
+  int get total {
+    return images + videos + livePhotos + (filesCount[-1] ?? 0);
+  }
+
+  int get images {
+    return filesCount[0] ?? 0;
+  }
+
+  int get videos {
+    return filesCount[1] ?? 0;
+  }
+
+  int get livePhotos {
+    return filesCount[2] ?? 0;
+  }
+}

+ 4 - 6
lib/ui/settings/details_section_widget.dart

@@ -3,7 +3,6 @@ import 'package:intl/intl.dart';
 import 'package:logging/logging.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/db/files_db.dart';
-import 'package:photos/models/count_of_file_types.dart';
 import 'package:photos/models/user_details.dart';
 import 'package:photos/states/user_details_state.dart';
 import 'package:photos/theme/colors.dart';
@@ -251,24 +250,23 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
                           ],
                         )
                       : FutureBuilder(
-                          future: FilesDB.instance.fetchPhotoAndVideoCount(
+                          future: FilesDB.instance.fetchFilesCountbyType(
                             Configuration.instance.getUserID(),
                           ),
                           builder: (context, snapshot) {
                             if (snapshot.hasData) {
-                              final countOfFileTypes =
-                                  snapshot.data as CountOfFileTypes;
+                              final filesCount = snapshot.data as Map<int, int>;
                               return Column(
                                 crossAxisAlignment: CrossAxisAlignment.start,
                                 children: [
                                   Text(
-                                    "${NumberFormat().format(countOfFileTypes.photosCount)} photos",
+                                    "${NumberFormat().format(FilesCount(filesCount).images + FilesCount(filesCount).livePhotos)} photos",
                                     style: getEnteTextTheme(context)
                                         .mini
                                         .copyWith(color: textBaseDark),
                                   ),
                                   Text(
-                                    "${NumberFormat().format(countOfFileTypes.videosCount)} videos",
+                                    "${NumberFormat().format(FilesCount(filesCount).videos)} videos",
                                     style: getEnteTextTheme(context)
                                         .mini
                                         .copyWith(color: textBaseDark),