Prevent duplication of images within iOS
This commit is contained in:
parent
6990faa451
commit
650e2f3161
3 changed files with 34 additions and 29 deletions
|
@ -91,23 +91,11 @@ class Photo {
|
|||
return o is Photo &&
|
||||
o.generatedId == generatedId &&
|
||||
o.uploadedFileId == uploadedFileId &&
|
||||
o.localId == localId &&
|
||||
o.title == title &&
|
||||
o.deviceFolder == deviceFolder &&
|
||||
o.remotePath == remotePath &&
|
||||
o.createTimestamp == createTimestamp &&
|
||||
o.updateTimestamp == updateTimestamp;
|
||||
o.localId == localId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return generatedId.hashCode ^
|
||||
uploadedFileId.hashCode ^
|
||||
localId.hashCode ^
|
||||
title.hashCode ^
|
||||
deviceFolder.hashCode ^
|
||||
remotePath.hashCode ^
|
||||
createTimestamp.hashCode ^
|
||||
updateTimestamp.hashCode;
|
||||
return generatedId.hashCode ^ uploadedFileId.hashCode ^ localId.hashCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ class PhotoProvider {
|
|||
final filterOptionGroup = FilterOptionGroup();
|
||||
filterOptionGroup.setOption(AssetType.image, FilterOption(needTitle: true));
|
||||
var galleryList = await PhotoManager.getAssetPathList(
|
||||
type: RequestType.image, filterOption: filterOptionGroup);
|
||||
hasAll: true,
|
||||
type: RequestType.image,
|
||||
filterOption: filterOptionGroup,
|
||||
);
|
||||
|
||||
galleryList.sort((s1, s2) {
|
||||
return s2.assetCount.compareTo(s1.assetCount);
|
||||
|
|
|
@ -54,23 +54,18 @@ class PhotoSyncManager {
|
|||
await PhotoProvider.instance.refreshGalleryList();
|
||||
final pathEntities = PhotoProvider.instance.list;
|
||||
final photos = List<Photo>();
|
||||
AssetPathEntity recents;
|
||||
for (AssetPathEntity pathEntity in pathEntities) {
|
||||
if (Platform.isIOS || pathEntity.name != "Recent") {
|
||||
// "Recents" contain duplicate information on Android
|
||||
var assetList = await pathEntity.assetList;
|
||||
for (AssetEntity entity in assetList) {
|
||||
if (max(entity.createDateTime.microsecondsSinceEpoch,
|
||||
entity.modifiedDateTime.microsecondsSinceEpoch) >
|
||||
lastDBUpdateTimestamp) {
|
||||
try {
|
||||
photos.add(await Photo.fromAsset(pathEntity, entity));
|
||||
} catch (e) {
|
||||
_logger.severe(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pathEntity.name == "Recent" || pathEntity.name == "Recents") {
|
||||
recents = pathEntity;
|
||||
} else {
|
||||
await _addToPhotos(pathEntity, lastDBUpdateTimestamp, photos);
|
||||
}
|
||||
}
|
||||
if (recents != null) {
|
||||
await _addToPhotos(recents, lastDBUpdateTimestamp, photos);
|
||||
}
|
||||
|
||||
if (photos.isEmpty) {
|
||||
_isSyncInProgress = false;
|
||||
_syncWithRemote(prefs);
|
||||
|
@ -84,6 +79,25 @@ class PhotoSyncManager {
|
|||
}
|
||||
}
|
||||
|
||||
Future _addToPhotos(AssetPathEntity pathEntity, int lastDBUpdateTimestamp,
|
||||
List<Photo> photos) async {
|
||||
final assetList = await pathEntity.assetList;
|
||||
for (AssetEntity entity in assetList) {
|
||||
if (max(entity.createDateTime.microsecondsSinceEpoch,
|
||||
entity.modifiedDateTime.microsecondsSinceEpoch) >
|
||||
lastDBUpdateTimestamp) {
|
||||
try {
|
||||
final photo = await Photo.fromAsset(pathEntity, entity);
|
||||
if (!photos.contains(photo)) {
|
||||
photos.add(photo);
|
||||
}
|
||||
} catch (e) {
|
||||
_logger.severe(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncWithRemote(SharedPreferences prefs) {
|
||||
// TODO: Fix race conditions triggered due to concurrent syncs.
|
||||
// Add device_id/last_sync_timestamp to the upload request?
|
||||
|
|
Loading…
Add table
Reference in a new issue