Ver código fonte

Move the pull to sync logic out of Gallery

Vishnu Mohandas 5 anos atrás
pai
commit
c8e7e9bedb
2 arquivos alterados com 10 adições e 10 exclusões
  1. 6 9
      lib/ui/gallery.dart
  2. 4 1
      lib/ui/home_widget.dart

+ 6 - 9
lib/ui/gallery.dart

@@ -7,7 +7,6 @@ import 'package:flutter/services.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/events/photo_opened_event.dart';
 import 'package:photos/models/photo.dart';
-import 'package:photos/photo_sync_manager.dart';
 import 'package:photos/ui/detail_page.dart';
 import 'package:photos/ui/thumbnail_widget.dart';
 import 'package:photos/utils/date_time_util.dart';
@@ -17,10 +16,10 @@ class Gallery extends StatefulWidget {
   final List<Photo> photos;
   final Set<Photo> selectedPhotos;
   final Function(Set<Photo>) photoSelectionChangeCallback;
-  final bool enablePullToSync;
+  final Future<void> Function() syncFunction;
 
   Gallery(this.photos, this.selectedPhotos,
-      {this.photoSelectionChangeCallback, this.enablePullToSync = false});
+      {this.photoSelectionChangeCallback, this.syncFunction});
 
   @override
   _GalleryState createState() {
@@ -33,8 +32,7 @@ class _GalleryState extends State<Gallery> {
   final List<List<Photo>> _collatedPhotos = List<List<Photo>>();
   Set<Photo> _selectedPhotos = HashSet<Photo>();
   List<Photo> _photos;
-  RefreshController _refreshController =
-      RefreshController(initialRefresh: true);
+  RefreshController _refreshController = RefreshController();
   StreamSubscription<PhotoOpenedEvent> _subscription;
   Photo _openedPhoto;
 
@@ -66,10 +64,9 @@ class _GalleryState extends State<Gallery> {
       controller: _scrollController,
       cacheExtent: 1000,
     );
-    if (widget.enablePullToSync) {
+    if (widget.syncFunction != null) {
       return SmartRefresher(
         controller: _refreshController,
-        enablePullUp: true,
         child: list,
         header: ClassicHeader(
           idleText: "Pull down to sync.",
@@ -78,8 +75,8 @@ class _GalleryState extends State<Gallery> {
           completeText: "Sync completed.",
           failedText: "Sync unsuccessful.",
         ),
-        onRefresh: () async {
-          PhotoSyncManager.instance.sync().then((value) {
+        onRefresh: () {
+          widget.syncFunction().then((value) {
             _refreshController.refreshCompleted();
           }).catchError((e) {
             _refreshController.refreshFailed();

+ 4 - 1
lib/ui/home_widget.dart

@@ -9,6 +9,7 @@ import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/models/filters/important_items_filter.dart';
 import 'package:photos/models/photo.dart';
 import 'package:photos/photo_repository.dart';
+import 'package:photos/photo_sync_manager.dart';
 import 'package:photos/ui/device_folders_gallery_widget.dart';
 import 'package:photos/ui/gallery.dart';
 import 'package:photos/ui/gallery_app_bar_widget.dart';
@@ -112,7 +113,9 @@ class _HomeWidgetState extends State<HomeWidget> {
           _selectedPhotos = selectedPhotos;
         });
       },
-      enablePullToSync: true,
+      syncFunction: () {
+        return PhotoSyncManager.instance.sync();
+      },
     );
   }