public CollectionViewBatchAnimation(UICollectionView collectionView, int sectionIndex, PHFetchResultChangeDetails changes) { _collectionView = collectionView; _sectionIndex = sectionIndex; _changes = changes; }
private PHFetchResult AdjustAssets(PHFetchResult assets, PHFetchResultChangeDetails changes) { if (assets == null) { return(null); } var before = assets; assets = changes.FetchResultAfterChanges; foreach (var asset in before.OfType <PHAsset>()) { if (!assets.Contains(asset)) { AllAssets.Remove(asset); } } foreach (var asset in assets.OfType <PHAsset>().OrderBy(a => a.CreationDate.SecondsSinceReferenceDate)) { if (!AllAssets.Contains(asset)) { AllAssets.Insert(0, asset); } } return(assets); }
/// <summary> /// Updates collection view. /// </summary> /// <param name="changes">Changes.</param> /// <param name="inSection">In section.</param> public void PerformChanges(PHFetchResultChangeDetails changes, int inSection) { if (changes.HasIncrementalChanges) { var operation = new CollectionViewBatchAnimation(_сollectionView, inSection, changes); _serialMainQueue.AddOperation(operation.Execute); } else { _serialMainQueue.AddOperation(_сollectionView.ReloadData); } }
public void PhotoLibraryDidChange(PHChange changeInstance) { DispatchQueue.MainQueue.DispatchAsync(() => { // Loop through the section fetch results, replacing any fetch results that have been updated. for (int i = 0; i < sectionFetchResults.Length; i++) { PHFetchResultChangeDetails changeDetails = changeInstance.GetFetchResultChangeDetails(sectionFetchResults [i]); if (changeDetails != null) { sectionFetchResults [i] = changeDetails.FetchResultAfterChanges; } } TableView.ReloadData(); }); }
public override void PhotoLibraryDidChange(PHChange changeInstance) { PHFetchResultChangeDetails imageDetails = changeInstance.GetFetchResultChangeDetails(_imageFetchResult); PHFetchResultChangeDetails videoDetails = changeInstance.GetFetchResultChangeDetails(_videoFetchResult); List <PHObject> insertedObjects = new List <PHObject>(); if (imageDetails != null && imageDetails.InsertedObjects.Any()) { insertedObjects.AddRange(imageDetails.InsertedObjects); _imageFetchResult = imageDetails.FetchResultAfterChanges; } if (videoDetails != null && videoDetails.InsertedObjects.Any()) { insertedObjects.AddRange(videoDetails.InsertedObjects); _videoFetchResult = videoDetails.FetchResultAfterChanges; } HandleImage(insertedObjects); }