Request photos from a specific timestamp
This commit is contained in:
parent
81d90da546
commit
c9d5cc9e1a
2 changed files with 17 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue