diff --git a/lib/ui/gallery.dart b/lib/ui/gallery.dart index e3fa8f01b..4d1476ce2 100644 --- a/lib/ui/gallery.dart +++ b/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 photos; final Set selectedPhotos; final Function(Set) photoSelectionChangeCallback; - final bool enablePullToSync; + final Future 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 { final List> _collatedPhotos = List>(); Set _selectedPhotos = HashSet(); List _photos; - RefreshController _refreshController = - RefreshController(initialRefresh: true); + RefreshController _refreshController = RefreshController(); StreamSubscription _subscription; Photo _openedPhoto; @@ -66,10 +64,9 @@ class _GalleryState extends State { 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 { completeText: "Sync completed.", failedText: "Sync unsuccessful.", ), - onRefresh: () async { - PhotoSyncManager.instance.sync().then((value) { + onRefresh: () { + widget.syncFunction().then((value) { _refreshController.refreshCompleted(); }).catchError((e) { _refreshController.refreshFailed(); diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 0d891cc03..daa8798b0 100644 --- a/lib/ui/home_widget.dart +++ b/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 { _selectedPhotos = selectedPhotos; }); }, - enablePullToSync: true, + syncFunction: () { + return PhotoSyncManager.instance.sync(); + }, ); }