Ver código fonte

Merge pull request #610 from ente-io/fetch-count-from-api

Fetch count from network API for consistency
Neeraj Gupta 2 anos atrás
pai
commit
a2ba68c281

+ 2 - 50
lib/ui/settings/details_section_widget.dart

@@ -1,9 +1,5 @@
 import 'package:flutter/material.dart';
-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/file_type.dart';
 import 'package:photos/models/user_details.dart';
 import 'package:photos/states/user_details_state.dart';
 import 'package:photos/theme/colors.dart';
@@ -145,13 +141,7 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
         16,
         20,
         16,
-        isMobileScreenSmall
-            ? userDetails.isPartOfFamily()
-                ? 12
-                : 8
-            : userDetails.isPartOfFamily()
-                ? 20
-                : 12,
+        isMobileScreenSmall ? 12 : 20,
       ),
       child: Column(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -253,45 +243,7 @@ class _DetailsSectionWidgetState extends State<DetailsSectionWidget> {
                             ),
                           ],
                         )
-                      : FutureBuilder(
-                          future: FilesDB.instance.fetchFilesCountbyType(
-                            Configuration.instance.getUserID(),
-                          ),
-                          builder: (context, snapshot) {
-                            if (snapshot.hasData) {
-                              final filesCount = FilesCount(
-                                snapshot.data as Map<FileType, int>,
-                              );
-                              return Column(
-                                crossAxisAlignment: CrossAxisAlignment.start,
-                                children: [
-                                  Text(
-                                    "${NumberFormat().format(filesCount.photos)} photos",
-                                    style: getEnteTextTheme(context)
-                                        .mini
-                                        .copyWith(color: textBaseDark),
-                                  ),
-                                  Text(
-                                    "${NumberFormat().format(filesCount.videos)} videos",
-                                    style: getEnteTextTheme(context)
-                                        .mini
-                                        .copyWith(color: textBaseDark),
-                                  ),
-                                ],
-                              );
-                            } else if (snapshot.hasError) {
-                              _logger.severe(
-                                'Error fetching photo and video count',
-                                snapshot.error,
-                              );
-                              return const SizedBox.shrink();
-                            } else {
-                              return const EnteLoadingWidget(
-                                color: strokeBaseDark,
-                              );
-                            }
-                          },
-                        ),
+                      : const SizedBox.shrink(),
                   RichText(
                     text: TextSpan(
                       style: getEnteTextTheme(context)

+ 17 - 13
lib/ui/settings/settings_title_bar_widget.dart

@@ -1,10 +1,8 @@
 import 'package:flutter/material.dart';
 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/file_type.dart';
 import 'package:photos/models/user_details.dart';
+import 'package:photos/states/user_details_state.dart';
 import 'package:photos/theme/ente_theme.dart';
 import 'package:photos/ui/common/loading_widget.dart';
 
@@ -29,22 +27,28 @@ class SettingsTitleBarWidget extends StatelessWidget {
               icon: const Icon(Icons.keyboard_double_arrow_left_outlined),
             ),
             FutureBuilder(
-              future: FilesDB.instance
-                  .fetchFilesCountbyType(Configuration.instance.getUserID()),
+              future: InheritedUserDetails.of(context)?.userDetails,
               builder: (context, snapshot) {
-                if (snapshot.hasData) {
-                  final totalFiles =
-                      FilesCount(snapshot.data as Map<FileType, int>).total;
+                if (InheritedUserDetails.of(context) == null) {
+                  logger.severe(
+                    (InheritedUserDetails).toString() +
+                        ' not found before ' +
+                        (SettingsTitleBarWidget).toString() +
+                        ' on tree',
+                  );
+                  throw Error();
+                } else if (snapshot.hasData) {
+                  final userDetails = snapshot.data as UserDetails;
                   return Text(
-                    totalFiles == 0
-                        ? "No memories yet"
-                        : "${NumberFormat().format(totalFiles)} memories",
+                    "${NumberFormat().format(userDetails.fileCount)} memories",
                     style: getEnteTextTheme(context).largeBold,
                   );
                 } else if (snapshot.hasError) {
-                  logger.severe('failed to fetch filesCount');
+                  logger.severe('failed to load user details');
+                  return const EnteLoadingWidget();
+                } else {
+                  return const EnteLoadingWidget();
                 }
-                return const EnteLoadingWidget();
               },
             )
           ],