From 09241b236f3ccdb1946fe6e4dd4073c1a688127e Mon Sep 17 00:00:00 2001 From: Vishal Deep Kanojia Date: Thu, 20 Jun 2019 13:11:47 +0530 Subject: [PATCH 1/2] Added option to customize showDialog --- .gitignore | 11 ++++++++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++++ .../Picker/FMPhotoPickerViewController.swift | 21 ++++++++++++++++--- .../Utilities/FMPhotoPickerConfig.swift | 5 +++++ .../source/Utilities/Helper.swift | 12 +++++------ 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 FMPhotoPicker/FMPhotoPicker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/.gitignore b/.gitignore index 66433a2..f914194 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,13 @@ FMPhotoPickerExample/FMPhotoPickerExample.xcodeproj/project.xcworkspace/xcuserdata/ FMPhotoPickerExample/FMPhotoPickerExample.xcodeproj/xcuserdata/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ diff --git a/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerViewController.swift b/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerViewController.swift index 616a5b3..76214f5 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerViewController.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerViewController.swift @@ -104,9 +104,24 @@ public class FMPhotoPickerViewController: UIViewController { if Helper.canAccessPhotoLib() { self.fetchPhotos() } else { - Helper.showDialog(in: self, ok: { - Helper.requestAuthorizationForPhotoAccess(authorized: self.fetchPhotos, rejected: Helper.openIphoneSetting) - }) + let okAction = UIAlertAction( + title: config.strings["permission_button_ok"], + style: .default) { (_) in + Helper.requestAuthorizationForPhotoAccess(authorized: self.fetchPhotos, rejected: Helper.openIphoneSetting) + } + + let cancelAction = UIAlertAction( + title: config.strings["permission_button_cancel"], + style: .cancel, + handler: nil) + + Helper.showDialog( + in: self, + okAction: okAction, + cancelAction: cancelAction, + title: config.strings["permission_dialog_title"], + message: config.strings["permission_dialog_message"] + ) } } diff --git a/FMPhotoPicker/FMPhotoPicker/source/Utilities/FMPhotoPickerConfig.swift b/FMPhotoPicker/FMPhotoPicker/source/Utilities/FMPhotoPickerConfig.swift index 264c184..404787c 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Utilities/FMPhotoPickerConfig.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Utilities/FMPhotoPickerConfig.swift @@ -78,6 +78,11 @@ public struct FMPhotoPickerConfig { "editor_crop_ratioCustom": "Custom", "editor_crop_ratioOrigin": "Origin", "editor_crop_ratioSquare": "Square", + + "permission_dialog_title": "FMPhotoPicker", + "permission_dialog_message": "FMPhotoPicker wants to access Photo Library", + "permission_button_ok": "OK", + "permission_button_cancel": "Cancel" ] public init() { diff --git a/FMPhotoPicker/FMPhotoPicker/source/Utilities/Helper.swift b/FMPhotoPicker/FMPhotoPicker/source/Utilities/Helper.swift index ae58d4d..a60c8b6 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Utilities/Helper.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Utilities/Helper.swift @@ -178,14 +178,14 @@ class Helper: NSObject { } static func showDialog(in viewController: UIViewController, - ok: (() -> Void)? = nil, - cancel: (() -> Void)? = nil, - title: String = "FMPhotoPicker", - message: String = "FMPhotoPicker want to access Photo Library") { + okAction: UIAlertAction = UIAlertAction(title: "OK", style: .default, handler: nil), + cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil), + title: String? = "FMPhotoPicker", + message: String? = "FMPhotoPicker want to access Photo Library") { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in ok?() })) - alertController.addAction(UIAlertAction(title: "キャンセル", style: .cancel, handler: { _ in cancel?() })) + alertController.addAction(okAction) + alertController.addAction(cancelAction) viewController.present(alertController, animated: true) } From bb52a4ef10ec0b2147399ce8e9bcd0dce1aa285c Mon Sep 17 00:00:00 2001 From: Vishal Deep Kanojia Date: Thu, 20 Jun 2019 13:20:25 +0530 Subject: [PATCH 2/2] Updated to Swift 5 --- .../FMPhotoPicker.xcodeproj/project.pbxproj | 18 ++++++++++++------ .../xcschemes/FMPhotoPicker.xcscheme | 4 +--- .../source/Data/FMPhotosDataSource.swift | 8 ++++---- .../Picker/FMPhotoPickerBatchSelector.swift | 4 ++-- .../Editor/FMImageEditorViewController.swift | 12 ++++++++++-- .../Editor/Views/FMCropMenuView.swift | 2 +- .../Editor/Views/FMFiltersMenuView.swift | 2 +- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.pbxproj b/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.pbxproj index 9dc767f..c2f36e7 100644 --- a/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.pbxproj +++ b/FMPhotoPicker/FMPhotoPicker.xcodeproj/project.pbxproj @@ -437,16 +437,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Tribal Media House"; TargetAttributes = { CEE50D0820196DF9005AE708 = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 0920; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; CEE50D1120196DF9005AE708 = { CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; }; @@ -457,6 +458,7 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = CEE50CFF20196DF9005AE708; productRefGroup = CEE50D0A20196DF9005AE708 /* Products */; @@ -581,6 +583,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -588,6 +591,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -641,6 +645,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -648,6 +653,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -698,7 +704,7 @@ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -720,7 +726,7 @@ PRODUCT_BUNDLE_IDENTIFIER = jp.co.tribalmedia.FMPhotoPicker; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -734,7 +740,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.tribalmedia.FMPhotoPickerTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -748,7 +754,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.tribalmedia.FMPhotoPickerTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/FMPhotoPicker/FMPhotoPicker.xcodeproj/xcshareddata/xcschemes/FMPhotoPicker.xcscheme b/FMPhotoPicker/FMPhotoPicker.xcodeproj/xcshareddata/xcschemes/FMPhotoPicker.xcscheme index 37f31de..c1bc434 100644 --- a/FMPhotoPicker/FMPhotoPicker.xcodeproj/xcshareddata/xcschemes/FMPhotoPicker.xcscheme +++ b/FMPhotoPicker/FMPhotoPicker.xcodeproj/xcshareddata/xcschemes/FMPhotoPicker.xcscheme @@ -1,6 +1,6 @@ Int? { - return self.selectedPhotoIndexes.index(where: { $0 == index }) + return self.selectedPhotoIndexes.firstIndex(where: { $0 == index }) } public func numberOfSelectedPhoto() -> Int { @@ -70,7 +70,7 @@ class FMPhotosDataSource { } public func index(ofPhoto photo: FMPhotoAsset) -> Int? { - return self.photoAssets.index(where: { $0 === photo }) + return self.photoAssets.firstIndex(where: { $0 === photo }) } public func contains(photo: FMPhotoAsset) -> Bool { diff --git a/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerBatchSelector.swift b/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerBatchSelector.swift index 6b027a7..3f7eb5c 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerBatchSelector.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Scene/Picker/FMPhotoPickerBatchSelector.swift @@ -185,7 +185,7 @@ class FMPhotoPickerBatchSelector: NSObject { var result = [PanSelection]() for index in fromIndex...toIndex { - let found = self.panSelections.index(where: { $0.indexPath.item == index }) + let found = self.panSelections.firstIndex(where: { $0.indexPath.item == index }) if let found = found { result.append(self.panSelections[found]) } @@ -198,7 +198,7 @@ class FMPhotoPickerBatchSelector: NSObject { */ private func removeFromPrevSection(panSelectionsTobeReset: [PanSelection]) { panSelectionsTobeReset.forEach { panSelection in - if let found = self.panSelections.index(where: { $0.indexPath == panSelection.indexPath }) { + if let found = self.panSelections.firstIndex(where: { $0.indexPath == panSelection.indexPath }) { self.panSelections.remove(at: found) } } diff --git a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/FMImageEditorViewController.swift b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/FMImageEditorViewController.swift index 1db2017..8959942 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/FMImageEditorViewController.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/FMImageEditorViewController.swift @@ -433,10 +433,18 @@ public class FMImageEditorViewController: UIViewController { // MARK: - Logics private func contentFrameCrop() -> CGRect { + let frameWidth: CGFloat = view.bounds.width - 2 * kContentFrameSpacing + var frameHeight: CGFloat = view.bounds.height + frameHeight -= transparentViewHeightConstraint.constant + frameHeight -= bottomMenuContainer.frame.height + frameHeight -= subMenuContainer.frame.height + frameHeight -= unsafeAreaBottomViewHeightConstraint.constant + frameHeight -= 2 * kContentFrameSpacing + return CGRect(x: kContentFrameSpacing, y: kContentFrameSpacing + transparentViewHeightConstraint.constant, - width: view.bounds.width - 2 * kContentFrameSpacing, - height: view.bounds.height - transparentViewHeightConstraint.constant - bottomMenuContainer.frame.height - subMenuContainer.frame.height - unsafeAreaBottomViewHeightConstraint.constant - 2 * kContentFrameSpacing) + width: frameWidth, + height: frameHeight) } private func contentFrameFilter() -> CGRect { diff --git a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMCropMenuView.swift b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMCropMenuView.swift index 5ffa5e3..ea6625c 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMCropMenuView.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMCropMenuView.swift @@ -165,7 +165,7 @@ extension FMCropMenuView: UICollectionViewDelegate { cell.setSelected() if let prevCropItem = prevCropItem, - let prevRow = cropItems.index(where: { $0.identifier() == prevCropItem.identifier() }) { + let prevRow = cropItems.firstIndex(where: { $0.identifier() == prevCropItem.identifier() }) { collectionView.reloadItems(at: [IndexPath(row: prevRow, section: 1)]) } } diff --git a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMFiltersMenuView.swift b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMFiltersMenuView.swift index 2297f51..d531007 100644 --- a/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMFiltersMenuView.swift +++ b/FMPhotoPicker/FMPhotoPicker/source/Scene/Presenter/Editor/Views/FMFiltersMenuView.swift @@ -36,7 +36,7 @@ class FMFiltersMenuView: UIView { super.init(frame: .zero) - if let index = self.availableFilters.index(where: { return $0.filterName() == appliedFilter?.filterName() }) { + if let index = self.availableFilters.firstIndex(where: { return $0.filterName() == appliedFilter?.filterName() }) { self.selectedCellIndex = index }