Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 9fdc63e

Browse files
authored
Merge pull request #154 from wordpress-mobile/media-picker-additions
Tweaks required for Media Library deletion in WPiOS
2 parents acbbb1c + ebce520 commit 9fdc63e

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Pod/Classes/WPMediaPickerViewController.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@
111111

112112
/**
113113
* Asks the delegate for a view controller to push when previewing the specified asset.
114-
* If this method isn't implemented or returns nil, the default view controller will be used.
114+
* If this method isn't implemented, the default view controller will be used.
115+
* If it returns nil, no preview will be displayed.
115116
*
116117
* @param picker The controller object managing the assets picker interface.
117118
* @param asset The asset to be previewed.
@@ -164,5 +165,10 @@
164165
*/
165166
- (void)setGroup:(nonnull id<WPMediaGroup>)group;
166167

168+
/**
169+
* Clears the current asset selection in the picker.
170+
*/
171+
- (void)clearSelectedAssets:(BOOL)animated;
172+
167173
@end
168174

Pod/Classes/WPMediaPickerViewController.m

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ - (BOOL)isShowingCaptureCell
139139
return self.allowCaptureOfMedia && [self isMediaDeviceAvailable] && !self.refreshGroupFirstTime;
140140
}
141141

142+
- (void)setAllowMultipleSelection:(BOOL)allowMultipleSelection
143+
{
144+
_allowMultipleSelection = allowMultipleSelection;
145+
146+
if (self.isViewLoaded) {
147+
self.collectionView.allowsMultipleSelection = allowMultipleSelection;
148+
}
149+
}
150+
151+
- (void)clearSelectedAssets:(BOOL)animated
152+
{
153+
for (NSIndexPath *indexPath in [self.collectionView indexPathsForSelectedItems]) {
154+
[self.collectionView deselectItemAtIndexPath:indexPath animated:animated];
155+
}
156+
157+
[self.selectedAssets removeAllObjects];
158+
}
159+
142160
#pragma mark - UICollectionViewDataSource
143161

144162
-(void)updateDataWithRemoved:(NSIndexSet *)removed inserted:(NSIndexSet *)inserted changed:(NSIndexSet *)changed moved:(NSArray<id<WPMediaMove>> *)moves {
@@ -709,18 +727,12 @@ - (nullable UIViewController *)previewControllerForTouchLocation:(CGPoint)locati
709727

710728
- (UIViewController *)previewViewControllerForAsset:(id <WPMediaAsset>)asset
711729
{
712-
UIViewController *previewViewController = nil;
713-
714730
if ([self.mediaPickerDelegate respondsToSelector:@selector(mediaPickerController:previewViewControllerForAsset:)]) {
715-
previewViewController = [self.mediaPickerDelegate mediaPickerController:self
716-
previewViewControllerForAsset:asset];
717-
}
718-
719-
if (!previewViewController) {
720-
previewViewController = [self defaultPreviewViewControllerForAsset:asset];
731+
return [self.mediaPickerDelegate mediaPickerController:self
732+
previewViewControllerForAsset:asset];
721733
}
722734

723-
return previewViewController;
735+
return [self defaultPreviewViewControllerForAsset:asset];
724736
}
725737

726738
- (UIViewController *)defaultPreviewViewControllerForAsset:(id <WPMediaAsset>)asset

0 commit comments

Comments
 (0)