Ver Fonte

Request photos from a specific timestamp

Vishnu Mohandas há 5 anos atrás
pai
commit
c9d5cc9e1a
2 ficheiros alterados com 17 adições e 7 exclusões
  1. 6 1
      lib/photo_provider.dart
  2. 11 6
      lib/photo_sync_manager.dart

+ 6 - 1
lib/photo_provider.dart

@@ -6,13 +6,18 @@ class PhotoProvider {
 
   List<AssetPathEntity> list = [];
 
-  Future<void> refreshGalleryList() async {
+  Future<void> refreshGalleryList(
+      final int fromTimestamp, final int toTimestamp) async {
     var result = await PhotoManager.requestPermission();
     if (!result) {
       print("Did not get permission");
     }
     final filterOptionGroup = FilterOptionGroup();
     filterOptionGroup.setOption(AssetType.image, FilterOption(needTitle: true));
+    filterOptionGroup.dateTimeCond = DateTimeCond(
+      min: DateTime.fromMicrosecondsSinceEpoch(fromTimestamp),
+      max: DateTime.fromMicrosecondsSinceEpoch(toTimestamp),
+    );
     var galleryList = await PhotoManager.getAssetPathList(
       hasAll: true,
       type: RequestType.image,

+ 11 - 6
lib/photo_sync_manager.dart

@@ -46,13 +46,15 @@ class PhotoSyncManager {
     _logger.info("Syncing...");
 
     final prefs = await SharedPreferences.getInstance();
+    final syncStartTimestamp = DateTime.now().microsecondsSinceEpoch;
     var lastDBUpdateTimestamp = prefs.getInt(_lastDBUpdateTimestampKey);
     if (lastDBUpdateTimestamp == null) {
       lastDBUpdateTimestamp = 0;
       await _initializeDirectories();
     }
 
-    await PhotoProvider.instance.refreshGalleryList();
+    await PhotoProvider.instance
+        .refreshGalleryList(lastDBUpdateTimestamp, syncStartTimestamp);
     final pathEntities = PhotoProvider.instance.list;
     final photos = List<Photo>();
     AssetPathEntity recents;
@@ -73,7 +75,8 @@ class PhotoSyncManager {
     } else {
       photos.sort((first, second) =>
           first.createTimestamp.compareTo(second.createTimestamp));
-      _updateDatabase(photos, prefs, lastDBUpdateTimestamp).then((_) {
+      _updateDatabase(photos, prefs, lastDBUpdateTimestamp, syncStartTimestamp)
+          .then((_) {
         _isSyncInProgress = false;
         _syncWithRemote(prefs);
       });
@@ -112,16 +115,18 @@ class PhotoSyncManager {
     });
   }
 
-  Future<bool> _updateDatabase(final List<Photo> photos,
-      SharedPreferences prefs, int lastDBUpdateTimestamp) async {
+  Future<bool> _updateDatabase(
+      final List<Photo> photos,
+      SharedPreferences prefs,
+      int lastDBUpdateTimestamp,
+      int syncStartTimestamp) async {
     var photosToBeAdded = List<Photo>();
     for (Photo photo in photos) {
       if (photo.createTimestamp > lastDBUpdateTimestamp) {
         photosToBeAdded.add(photo);
       }
     }
-    return await _insertPhotosToDB(
-        photosToBeAdded, prefs, DateTime.now().microsecondsSinceEpoch);
+    return await _insertPhotosToDB(photosToBeAdded, prefs, syncStartTimestamp);
   }
 
   Future<void> _downloadDiff(SharedPreferences prefs) async {