Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
A401D4F51D537AEC006B2909 /* DBAttachmentPickerController.strings in Resources */ = {isa = PBXBuildFile; fileRef = A401D4F71D537AEC006B2909 /* DBAttachmentPickerController.strings */; };
A401D4FE1D5545F5006B2909 /* DBAttachmentPickerController.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = A401D5001D5545F5006B2909 /* DBAttachmentPickerController.stringsdict */; };
A41C4BD71D557B9A002FEA0B /* NSBundle+DBLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = A41C4BD61D557B9A002FEA0B /* NSBundle+DBLibrary.m */; };
C3134EB41C9C30990023B9E6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C3134EB31C9C30990023B9E6 /* main.m */; };
C3134EB71C9C30990023B9E6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C3134EB61C9C30990023B9E6 /* AppDelegate.m */; };
Expand Down Expand Up @@ -37,24 +35,6 @@

/* Begin PBXFileReference section */
A401D4F41D537A13006B2909 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
A401D4F81D537AEF006B2909 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D4F91D537AF0006B2909 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D4FF1D5545F5006B2909 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A401D5011D5545F7006B2909 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ru; path = ru.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A401D5021D554922006B2909 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/DBAttachmentPickerController.strings"; sourceTree = "<group>"; };
A401D5041D554AD3006B2909 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hans"; path = "zh-Hans.lproj/DBAttachmentPickerController.stringsdict"; sourceTree = "<group>"; };
A401D5051D554BD0006B2909 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/DBAttachmentPickerController.strings"; sourceTree = "<group>"; };
A401D5061D554BD0006B2909 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant"; path = "zh-Hant.lproj/DBAttachmentPickerController.stringsdict"; sourceTree = "<group>"; };
A401D5071D554D71006B2909 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D5081D554D71006B2909 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = es; path = es.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A401D5091D554FCD006B2909 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D50B1D555228006B2909 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D50C1D555228006B2909 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ja; path = ja.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A401D50D1D5553CA006B2909 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D50E1D5553ED006B2909 /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = uk; path = uk.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A401D50F1D55560A006B2909 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/DBAttachmentPickerController.strings; sourceTree = "<group>"; };
A401D5101D55560A006B2909 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = fr; path = fr.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A41C4BD31D557B1A002FEA0B /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = de; path = de.lproj/DBAttachmentPickerController.stringsdict; sourceTree = "<group>"; };
A41C4BD51D557B9A002FEA0B /* NSBundle+DBLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+DBLibrary.h"; sourceTree = "<group>"; };
A41C4BD61D557B9A002FEA0B /* NSBundle+DBLibrary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+DBLibrary.m"; sourceTree = "<group>"; };
C3134EAF1C9C30990023B9E6 /* DBAttachmentPickerControllerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DBAttachmentPickerControllerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -114,8 +94,6 @@
A401D4F11D5378F2006B2909 /* Localization */ = {
isa = PBXGroup;
children = (
A401D4F71D537AEC006B2909 /* DBAttachmentPickerController.strings */,
A401D5001D5545F5006B2909 /* DBAttachmentPickerController.stringsdict */,
);
name = Localization;
path = ../../Source/Localization;
Expand Down Expand Up @@ -326,6 +304,7 @@
ja,
uk,
fr,
"pt-BR",
);
mainGroup = C3134EA61C9C30990023B9E6;
productRefGroup = C3134EB01C9C30990023B9E6 /* Products */;
Expand All @@ -346,9 +325,7 @@
C3134EC21C9C30990023B9E6 /* LaunchScreen.storyboard in Resources */,
C3849AB61C9C3D8C00D12EEF /* DBAssetGroupsViewController.xib in Resources */,
C3134EEB1C9C323C0023B9E6 /* DBAssetGroupCell.xib in Resources */,
A401D4FE1D5545F5006B2909 /* DBAttachmentPickerController.stringsdict in Resources */,
C3134EED1C9C323C0023B9E6 /* DBThumbnailPhotoCell.xib in Resources */,
A401D4F51D537AEC006B2909 /* DBAttachmentPickerController.strings in Resources */,
C3134EFC1C9C34340023B9E6 /* Assets.xcassets in Resources */,
C3134EBD1C9C30990023B9E6 /* Main.storyboard in Resources */,
);
Expand Down Expand Up @@ -383,38 +360,6 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
A401D4F71D537AEC006B2909 /* DBAttachmentPickerController.strings */ = {
isa = PBXVariantGroup;
children = (
A401D4F81D537AEF006B2909 /* en */,
A401D4F91D537AF0006B2909 /* ru */,
A401D5021D554922006B2909 /* zh-Hans */,
A401D5051D554BD0006B2909 /* zh-Hant */,
A401D5071D554D71006B2909 /* es */,
A401D5091D554FCD006B2909 /* de */,
A401D50B1D555228006B2909 /* ja */,
A401D50D1D5553CA006B2909 /* uk */,
A401D50F1D55560A006B2909 /* fr */,
);
name = DBAttachmentPickerController.strings;
sourceTree = "<group>";
};
A401D5001D5545F5006B2909 /* DBAttachmentPickerController.stringsdict */ = {
isa = PBXVariantGroup;
children = (
A401D4FF1D5545F5006B2909 /* en */,
A401D5011D5545F7006B2909 /* ru */,
A401D5041D554AD3006B2909 /* zh-Hans */,
A401D5061D554BD0006B2909 /* zh-Hant */,
A401D5081D554D71006B2909 /* es */,
A401D50C1D555228006B2909 /* ja */,
A401D50E1D5553ED006B2909 /* uk */,
A401D5101D55560A006B2909 /* fr */,
A41C4BD31D557B1A002FEA0B /* de */,
);
name = DBAttachmentPickerController.stringsdict;
sourceTree = "<group>";
};
C3134EBB1C9C30990023B9E6 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
6 changes: 5 additions & 1 deletion Example/DBAttachmentPickerControllerExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.3</string>
<string>1.1.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down Expand Up @@ -43,5 +43,9 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSCameraUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
</dict>
</plist>
20 changes: 20 additions & 0 deletions Example/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
4 changes: 3 additions & 1 deletion Source/Categories/NSBundle+DBLibrary.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ + (instancetype)dbAttachmentPickerResourceBundle {
// but in framework bundle
bundlePath = [[NSBundle bundleForClass:[DBAttachmentPickerController class]] pathForResource:@"DBAttachmentPickerController" ofType:@"bundle"];
}
bundle = [NSBundle bundleWithPath:bundlePath];
if (bundlePath) {
bundle = [NSBundle bundleWithPath:bundlePath];
}
return bundle;
}

Expand Down
9 changes: 6 additions & 3 deletions Source/DBAssetPickerController/DBAssetPickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@protocol DBAssetPickerControllerDelegate <NSObject>

NS_ASSUME_NONNULL_BEGIN

@optional
- (void)DBAssetPickerController:(DBAssetPickerController *)controller didFinishPickingAssetArray:(NSArray<PHAsset *> *)assetArray;
- (void)DBAssetPickerControllerDidCancel:(DBAssetPickerController *)controller;
Expand All @@ -36,9 +37,11 @@ NS_ASSUME_NONNULL_BEGIN

@property (weak, nonatomic, nullable) id<DBAssetPickerControllerDelegate> assetPickerDelegate;
@property (assign, nonatomic) PHAssetMediaType assetMediaType;
@property (nonatomic, assign, nonnull) NSArray *selectedItems;
@property (nonatomic, assign, nullable) NSPredicate *customPredicate;
@property (nonatomic, retain, nonnull) NSNumber *maxItems;

@property (strong, nonatomic) NSArray *selectedItems;
@property (strong, nonatomic, nullable) NSPredicate *customPredicate;
@property (strong, nonatomic) NSNumber *maxItems;

NS_ASSUME_NONNULL_END

@end
1 change: 0 additions & 1 deletion Source/DBAssetPickerController/DBAssetPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ - (void)viewDidLoad {
}
groupController.assetGroupsDelegate = self;
[self setViewControllers:@[groupController]];

}

#pragma mark - DBAssetGroupsViewControllerDelegate
Expand Down
11 changes: 7 additions & 4 deletions Source/DBAttachmentAlertController/DBAttachmentAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ typedef void (^AlertAttachAssetsHandler)(NSArray * _Nonnull assetArray);
typedef void (^AlertActionHandler)(UIAlertAction * _Nonnull action);

@interface DBAttachmentAlertController : UIAlertController
@property (assign, nonatomic) NSNumber * _Nonnull maxItems;

NS_ASSUME_NONNULL_BEGIN

@property (assign, nonatomic, readonly) PHAssetMediaType assetMediaType;
@property (assign, nonatomic, readonly) BOOL allowsMultipleSelection;
@property (assign, nonatomic) NSArray *selectedItems;
@property (assign, nonatomic) NSPredicate *customPredicate;

@property (strong, nonatomic) NSNumber *maxItems;
@property (strong, nonatomic) NSArray *selectedItems;
@property (strong, nonatomic) NSPredicate *customPredicate;

+ (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaType)assetMediaType
allowsMultipleSelection:(BOOL)allowsMultipleSelection
allowsMediaLibrary:(BOOL)allowsPhotoOrVideo
allowsOtherApps:(BOOL)allowsOtherApps
customActions:(NSArray *) customActions
customActions:(nullable NSArray *) customActions
attachHandler:(nullable AlertAttachAssetsHandler)attachHandler
allAlbumsHandler:(nullable AlertActionHandler)allAlbumsHandler
takePictureHandler:(nullable AlertActionHandler)takePictureHandler
Expand All @@ -54,6 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
takePictureHandler:(nullable AlertActionHandler)takePictureHandler
otherAppsHandler:(nullable AlertActionHandler)otherAppsHandler
cancelHandler:(nullable AlertActionHandler)cancelHandler;

NS_ASSUME_NONNULL_END

@end
60 changes: 26 additions & 34 deletions Source/DBAttachmentAlertController/DBAttachmentAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ @interface DBAttachmentAlertController () <UICollectionViewDataSource, UICollect

@property (assign, nonatomic) BOOL showCollectionView;
@property (strong, nonatomic) UICollectionView *collectionView;
@property (copy, nonatomic) NSString *attachActionText;
@property (copy, nonatomic) NSString *attachActionText;

@property (strong, nonatomic) PHFetchResult *assetsFetchResult;
@property (strong, nonatomic) PHCachingImageManager *imageManager;
Expand All @@ -47,7 +47,6 @@ @interface DBAttachmentAlertController () <UICollectionViewDataSource, UICollect
@property (strong, nonatomic) NSMutableArray *oldSelectedIndexPathArray;
@property (strong, nonatomic) NSMutableArray *customActions;


@property (strong, nonatomic) AlertAttachAssetsHandler extensionAttachHandler;

@end
Expand All @@ -65,23 +64,23 @@ + (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaTyp
otherAppsHandler:(nullable AlertActionHandler)otherAppsHandler
cancelHandler:(nullable AlertActionHandler)cancelHandler {

[self attachmentAlertControllerWithMediaType:assetMediaType
allowsMultipleSelection:allowsMultipleSelection
allowsMediaLibrary:allowsPhotoOrVideo
allowsOtherApps:allowsOtherApps
customActions:nil
attachHandler:attachHandler
allAlbumsHandler:allAlbumsHandler
takePictureHandler:takePictureHandler
otherAppsHandler:otherAppsHandler
cancelHandler:cancelHandler];
return [self attachmentAlertControllerWithMediaType:assetMediaType
allowsMultipleSelection:allowsMultipleSelection
allowsMediaLibrary:allowsPhotoOrVideo
allowsOtherApps:allowsOtherApps
customActions:nil
attachHandler:attachHandler
allAlbumsHandler:allAlbumsHandler
takePictureHandler:takePictureHandler
otherAppsHandler:otherAppsHandler
cancelHandler:cancelHandler];
}

+ (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaType)assetMediaType
allowsMultipleSelection:(BOOL)allowsMultipleSelection
allowsMediaLibrary:(BOOL)allowsPhotoOrVideo
allowsOtherApps:(BOOL)allowsOtherApps
customActions:(NSArray *) customActions
customActions:(nullable NSArray *) customActions
attachHandler:(nullable AlertAttachAssetsHandler)attachHandler
allAlbumsHandler:(nullable AlertActionHandler)allAlbumsHandler
takePictureHandler:(nullable AlertActionHandler)takePictureHandler
Expand All @@ -97,7 +96,7 @@ + (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaTyp
controller.title = ( controller.showCollectionView ? @"\n\n\n\n\n" : NSLocalizedString(@"Attach files", @"Title") );

if (customActions.count > 0) {
controller.customActions = customActions;
controller.customActions = [NSMutableArray arrayWithArray:customActions];
}

if (showPhotoOrVideo && controller.assetsFetchResult.count ) {
Expand Down Expand Up @@ -126,14 +125,14 @@ + (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaTyp
NSString *buttonTitle;
switch (controller.assetMediaType) {
case PHAssetMediaTypeVideo:
buttonTitle = NSLocalizedString(@"Take a video", @"Button on main menu");
break;
buttonTitle = NSLocalizedString(@"Take a video", @"Button on main menu");
break;
case PHAssetMediaTypeImage:
buttonTitle = NSLocalizedString(@"Take a picture", @"Button on main menu");
break;
buttonTitle = NSLocalizedString(@"Take a picture", @"Button on main menu");
break;
default:
buttonTitle = NSLocalizedString(@"Take a picture or a video", @"Button on main menu");
break;
buttonTitle = NSLocalizedString(@"Take a picture or a video", @"Button on main menu");
break;
}
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:takePictureHandler];
[controller addAction:cameraAction];
Expand All @@ -144,7 +143,6 @@ + (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaTyp
[controller addAction:otherAppsAction];
}


__weak DBAttachmentAlertController *weakController = controller;
NSArray *actions = weakController.customActions;
if (actions.count > 0) {
Expand All @@ -163,10 +161,10 @@ + (_Nonnull instancetype)attachmentAlertControllerWithMediaType:(PHAssetMediaTyp

- (void)viewDidLoad {
[super viewDidLoad];

self.selectedIndexPathArray = [NSMutableArray arrayWithCapacity:100];
self.oldSelectedIndexPathArray = [NSMutableArray new];


if (self.showCollectionView) {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
Expand Down Expand Up @@ -212,23 +210,12 @@ - (void)viewDidLoad {
[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];
}
}
- (void) orderByIndexPath: (NSMutableArray * )array {
[self.selectedIndexPathArray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSIndexPath *indexPath1 = obj1;
NSIndexPath *indexPath2 = obj2;
return [@(indexPath1.row) compare:@(indexPath2.row)];
}];

}

- (void) viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self recalculateVisibleCellsSelectorOffsetWithScrollViewOffsetX:self.collectionView.contentOffset.x];
[self updateAttachPhotoCountIfNedded];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}

- (void)dealloc {
if (self.showCollectionView) {
Expand Down Expand Up @@ -271,6 +258,12 @@ - (NSArray *)getSelectedAssetArray {
return [assetArray copy];
}

//- (void)orderByIndexPath:(NSMutableArray *) array {
// [self.selectedIndexPathArray sortUsingComparator:^NSComparisonResult(NSIndexPath *indexPath1, NSIndexPath *indexPath2) {
// return [@(indexPath1.row) compare:@(indexPath2.row)];
// }];
//}

#pragma mark - Accessors

- (void)setNeedsDisplayEmptySelectedIndicator:(BOOL)needsDisplayEmptySelectedIndicator {
Expand Down Expand Up @@ -420,7 +413,6 @@ - (void) selectItemAtIndex: (NSIndexPath *) indexPath {
} else {
self.extensionAttachHandler([self getSelectedAssetArray]);
}

}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
Expand Down
Loading