From b2256329eef0d8eb8469676a7292991a26dffc9f Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Mon, 15 Apr 2019 14:28:51 +0800 Subject: [PATCH 01/10] Add media type options support for image and video --- Example/CarousellImagePickerController.swift | 3 +++ Pickle/Classes/ImagePickerConfigurable.swift | 17 +++++++++++++++++ Pickle/Classes/Parameters.swift | 4 ++++ .../Classes/PhotoGalleryViewController.swift | 18 +++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Example/CarousellImagePickerController.swift b/Example/CarousellImagePickerController.swift index 6a963b1..e53e0c4 100644 --- a/Example/CarousellImagePickerController.swift +++ b/Example/CarousellImagePickerController.swift @@ -108,4 +108,7 @@ private struct CarousellTheme: ImagePickerConfigurable { let hintTextMargin: UIEdgeInsets? = .zero + // MARK: Media Types + + var mediaType: ImagePickerMediaType? = .unknown } diff --git a/Pickle/Classes/ImagePickerConfigurable.swift b/Pickle/Classes/ImagePickerConfigurable.swift index 0370359..1b6b071 100644 --- a/Pickle/Classes/ImagePickerConfigurable.swift +++ b/Pickle/Classes/ImagePickerConfigurable.swift @@ -80,8 +80,25 @@ public protocol ImagePickerConfigurable { /// Specifies whether the camera button shows a live preview. var isLiveCameraViewEnabled: Bool? { get } + + // MARK: - Media Types + + /// Specifies the supported media types + var mediaType: ImagePickerMediaType? { get } } +/// An enum that represents media type selections in ImagePickerController +public enum ImagePickerMediaType { + + /// Show images and videos in ImagePickerController + case unknown + + /// Only show images in ImagePickerController + case image + + /// Only show videos in ImagePickerController + case video +} /// An enum that represents photo selections allowed in ImagePickerController. public enum ImagePickerSelection { diff --git a/Pickle/Classes/Parameters.swift b/Pickle/Classes/Parameters.swift index 919ad4d..718a3cb 100644 --- a/Pickle/Classes/Parameters.swift +++ b/Pickle/Classes/Parameters.swift @@ -84,4 +84,8 @@ public struct Parameters: ImagePickerConfigurable { /// Specifies whether the camera button shows a live preview. public var isLiveCameraViewEnabled: Bool? + // MARK: - Media Types + + /// Specifies the supported media types + public var mediaType: ImagePickerMediaType? } diff --git a/Pickle/Classes/PhotoGalleryViewController.swift b/Pickle/Classes/PhotoGalleryViewController.swift index 09ee7fa..0c39a1c 100644 --- a/Pickle/Classes/PhotoGalleryViewController.swift +++ b/Pickle/Classes/PhotoGalleryViewController.swift @@ -81,7 +81,23 @@ internal final class PhotoGalleryViewController: UIViewController, internal private(set) lazy var fetchResult: PHFetchResult = { let options = PHFetchOptions() options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] - options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) + + guard let configuration = configuration, + let mediaType = configuration.mediaType + else { + options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) + return PHAsset.fetchAssets(in: self.album, options: options) + } + + switch mediaType { + case .image: + options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) + case .video: + options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue) + default: + break + } + return PHAsset.fetchAssets(in: self.album, options: options) }() From d17c0a8967fc4bb61c26c4cccf7b7194dfb4729b Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Mon, 15 Apr 2019 15:44:43 +0800 Subject: [PATCH 02/10] Add video icon and duration --- Example/Images.xcassets/Contents.json | 6 ++ .../video-icon.imageset/Contents.json | 12 ++++ .../video-icon.imageset/video-icon.pdf | Bin 0 -> 5711 bytes Pickle.xcodeproj/project.pbxproj | 4 ++ Pickle/Classes/PhotoGalleryCell.swift | 15 ++++ Pickle/Classes/UIColor+Palette.swift | 1 + Pickle/Classes/VideoPropertyView.swift | 66 ++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 Example/Images.xcassets/Contents.json create mode 100644 Example/Images.xcassets/video-icon.imageset/Contents.json create mode 100644 Example/Images.xcassets/video-icon.imageset/video-icon.pdf create mode 100644 Pickle/Classes/VideoPropertyView.swift diff --git a/Example/Images.xcassets/Contents.json b/Example/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Example/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Images.xcassets/video-icon.imageset/Contents.json b/Example/Images.xcassets/video-icon.imageset/Contents.json new file mode 100644 index 0000000..4c4a333 --- /dev/null +++ b/Example/Images.xcassets/video-icon.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "video-icon.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Images.xcassets/video-icon.imageset/video-icon.pdf b/Example/Images.xcassets/video-icon.imageset/video-icon.pdf new file mode 100644 index 0000000000000000000000000000000000000000..6bcb87c37118d7405b392cc59ec3df7b083fe1fe GIT binary patch literal 5711 zcmbtYcUTkK)21m95Ks}M2rHM+q$DAfi1a2!LJ_57fY2crdXpkWnlzCnAVm=oM1xX8 z2SJ2@bde@ax|B;5`GU&5-s^py-yh#Td3HCmb7p7WnKOIN3)WUr5rPVfg1}AFYtsw) z>kqq{T0n3B0$?ocL6PRkumo!ErFtuqgjIt!Dm9M<;3!$a>joY-%^eVqe0-_I~IdxDHjy9>OT ztJW*MLB(M^{*il7MTX8M4eT~AzT`L*D#f8D_&R}a^~0^YfSaFgOVoH(3pcNauhZ+W zz%oH-XRDt+67LQ}JB;V>3KbJQe0X>Z`z7kD-Y#fBL>p!E{ftFBy8)s<5YR=tV%)Ko zXjee|hd>eI>_&X<3LK)Qdx*wQdxy`DP}Ig^EcMWCfHBdik_uo7h!`L(?9rBPz#+ye zPEbJN=jdMy9Ey$%{7i%7cdh?SgUAn`kL-%*xm&n>k3t25bt1llcs|qsK>-m31&kM9 z3;~2BBmgJ`3c%n*hyD%>@#7_`Sd6>NcmMPNk*ipgv#Se=h=ip#Afl*89CxS%5>W%( zuTXwW zW%AG5n2{^VWEL=bA(3~Jmb!L0GG@9d{lZUCo zf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proj/project.pbxproj @@ -15,6 +15,7 @@ 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; + 94F4BF192264609C00E7A672 /* VideoPropertyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */; }; B55833221EC08E180061E182 /* CarousellImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55833211EC08E180061E182 /* CarousellImagePickerController.swift */; }; B563515E1F06278E00B5A46D /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B563515D1F06278E00B5A46D /* UITests.swift */; }; B57BEA34216AAF6300A2C776 /* Pickle.h in Headers */ = {isa = PBXBuildFile; fileRef = B57BEA32216AAF6300A2C776 /* Pickle.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -92,6 +93,7 @@ 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 7D176E52E185B871CF8D97C4 /* Pods_PickleUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PickleUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPropertyView.swift; sourceTree = ""; }; B55833211EC08E180061E182 /* CarousellImagePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarousellImagePickerController.swift; sourceTree = ""; }; B563515B1F06278E00B5A46D /* PickleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PickleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B563515D1F06278E00B5A46D /* UITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITests.swift; sourceTree = ""; }; @@ -289,6 +291,7 @@ B57BEA61216AAFD700A2C776 /* UIColor+Palette.swift */, B57BEA4B216AAFD700A2C776 /* UIFont+Style.swift */, B57BEA4A216AAFD700A2C776 /* UINavigationController+ImagePickerConfigurable.swift */, + 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */, ); path = Classes; sourceTree = ""; @@ -538,6 +541,7 @@ B57BEA6F216AAFD700A2C776 /* PhotoDetailViewController.swift in Sources */, B57BEA70216AAFD700A2C776 /* PhotoGalleryCameraCell.swift in Sources */, B57BEA7A216AAFD700A2C776 /* PhotoGalleryCameraIconView.swift in Sources */, + 94F4BF192264609C00E7A672 /* VideoPropertyView.swift in Sources */, B57BEA73216AAFD700A2C776 /* PhotoGalleryCell.swift in Sources */, B57BEA6B216AAFD700A2C776 /* PhotoGalleryHintLabel.swift in Sources */, 20FC48032256FAC3004CCD1D /* CameraSessionHandler.swift in Sources */, diff --git a/Pickle/Classes/PhotoGalleryCell.swift b/Pickle/Classes/PhotoGalleryCell.swift index afb7d01..51cfd28 100644 --- a/Pickle/Classes/PhotoGalleryCell.swift +++ b/Pickle/Classes/PhotoGalleryCell.swift @@ -32,6 +32,8 @@ internal final class PhotoGalleryCell: UICollectionViewCell { return imageView }() + private let videoPropertyView = VideoPropertyView() + private let overlayView = UIView() private let tagLabel = PhotoGalleryTagLabel() @@ -41,9 +43,11 @@ internal final class PhotoGalleryCell: UICollectionViewCell { overlayView.isHidden = false tagLabel.text = text accessibilityIdentifier = text + videoPropertyView.setSelected(true) } else { overlayView.isHidden = true accessibilityIdentifier = nil + videoPropertyView.setSelected(false) } } } @@ -58,6 +62,7 @@ internal final class PhotoGalleryCell: UICollectionViewCell { imageRequestID = nil taggedText = nil imageView.image = nil + videoPropertyView.isHidden = true } // MARK: - @@ -83,6 +88,9 @@ internal final class PhotoGalleryCell: UICollectionViewCell { } } + videoPropertyView.isHidden = asset.mediaType != .video + videoPropertyView.configure(duration: asset.duration) + if let color = configuration?.selectedImageOverlayColor { overlayView.backgroundColor = color } @@ -113,6 +121,13 @@ internal final class PhotoGalleryCell: UICollectionViewCell { tagLabel.widthAnchor.constraint(equalTo: tagLabel.heightAnchor).isActive = true tagLabel.topAnchor.constraint(equalTo: overlayView.topAnchor, constant: 10).isActive = true tagLabel.trailingAnchor.constraint(equalTo: overlayView.trailingAnchor, constant: -10).isActive = true + + contentView.addSubview(videoPropertyView) + videoPropertyView.translatesAutoresizingMaskIntoConstraints = false + videoPropertyView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true + videoPropertyView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true + videoPropertyView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true + videoPropertyView.heightAnchor.constraint(equalToConstant: 24).isActive = true } } diff --git a/Pickle/Classes/UIColor+Palette.swift b/Pickle/Classes/UIColor+Palette.swift index 3956c2e..6aa02e7 100644 --- a/Pickle/Classes/UIColor+Palette.swift +++ b/Pickle/Classes/UIColor+Palette.swift @@ -18,6 +18,7 @@ internal extension UIColor { static let gray = UIColor(hex: 0x8F939C) static let darkGray = UIColor(hex: 0x8F939C) static let magnesium = UIColor(hex: 0xB2B2B2) + static let darkGrey = UIColor(hex: 0x4B4D52) } internal convenience init(hex: Int) { diff --git a/Pickle/Classes/VideoPropertyView.swift b/Pickle/Classes/VideoPropertyView.swift new file mode 100644 index 0000000..4a75928 --- /dev/null +++ b/Pickle/Classes/VideoPropertyView.swift @@ -0,0 +1,66 @@ +// +// VideoPropertyView.swift +// Pickle +// +// Created by Amelia on 15/4/19. +// Copyright © 2019 Carousell. All rights reserved. +// + +internal final class VideoPropertyView: UIView { + + private let videoIcon: UIImageView = { + let icon = UIImageView() + icon.tintColor = .white + icon.image = UIImage(named: "video-icon")?.withRenderingMode(.alwaysTemplate) + return icon + }() + + private let durationLabel: UILabel = { + let label = UILabel() + label.font = UIFont.boldSystemFont(ofSize: 12) + label.textAlignment = .right + label.textColor = .white + return label + }() + + func configure(duration: TimeInterval) { + let formatter = DateComponentsFormatter() + formatter.unitsStyle = .positional + formatter.allowedUnits = [.hour, .minute, .second] + formatter.zeroFormattingBehavior = [.pad] + durationLabel.text = formatter.string(from: duration) + } + + func setSelected(_ value: Bool) { + if value { + backgroundColor = UIColor.Palette.blue + } else { + backgroundColor = UIColor.Palette.darkGray.withAlphaComponent(0.2) + } + } + + override init(frame: CGRect) { + super.init(frame: frame) + setupViews() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupViews() { + backgroundColor = UIColor.Palette.darkGray.withAlphaComponent(0.2) + + addSubview(videoIcon) + videoIcon.translatesAutoresizingMaskIntoConstraints = false + videoIcon.heightAnchor.constraint(equalToConstant: 16).isActive = true + videoIcon.widthAnchor.constraint(equalToConstant: 16).isActive = true + videoIcon.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 4).isActive = true + videoIcon.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true + + addSubview(durationLabel) + durationLabel.translatesAutoresizingMaskIntoConstraints = false + durationLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -4).isActive = true + durationLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true + } +} From d78c367db5b776b8c08d13272bde59527e3d7abb Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Mon, 15 Apr 2019 15:50:09 +0800 Subject: [PATCH 03/10] Show hour unit only if necessary --- Pickle/Classes/VideoPropertyView.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Pickle/Classes/VideoPropertyView.swift b/Pickle/Classes/VideoPropertyView.swift index 4a75928..d19dc48 100644 --- a/Pickle/Classes/VideoPropertyView.swift +++ b/Pickle/Classes/VideoPropertyView.swift @@ -25,9 +25,14 @@ internal final class VideoPropertyView: UIView { func configure(duration: TimeInterval) { let formatter = DateComponentsFormatter() - formatter.unitsStyle = .positional - formatter.allowedUnits = [.hour, .minute, .second] - formatter.zeroFormattingBehavior = [.pad] + formatter.zeroFormattingBehavior = .pad + + if duration >= 3600 { + formatter.allowedUnits = [.hour, .minute, .second] + } else { + formatter.allowedUnits = [.minute, .second] + } + durationLabel.text = formatter.string(from: duration) } From 8d010d01a98476e1cd1d5d19c43a46fb199ee149 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Mon, 15 Apr 2019 18:04:58 +0800 Subject: [PATCH 04/10] Move icon to the right assets folder --- .../video-icon.imageset/Contents.json | 0 .../video-icon.imageset/video-icon.pdf | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename {Example => Pickle/Assets}/Images.xcassets/video-icon.imageset/Contents.json (100%) rename {Example => Pickle/Assets}/Images.xcassets/video-icon.imageset/video-icon.pdf (100%) diff --git a/Example/Images.xcassets/video-icon.imageset/Contents.json b/Pickle/Assets/Images.xcassets/video-icon.imageset/Contents.json similarity index 100% rename from Example/Images.xcassets/video-icon.imageset/Contents.json rename to Pickle/Assets/Images.xcassets/video-icon.imageset/Contents.json diff --git a/Example/Images.xcassets/video-icon.imageset/video-icon.pdf b/Pickle/Assets/Images.xcassets/video-icon.imageset/video-icon.pdf similarity index 100% rename from Example/Images.xcassets/video-icon.imageset/video-icon.pdf rename to Pickle/Assets/Images.xcassets/video-icon.imageset/video-icon.pdf From 97d1b62562b624d00f5850ebf812b8d07e72f5d9 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Thu, 18 Apr 2019 16:12:35 +0800 Subject: [PATCH 05/10] Update header file --- Pickle/Classes/VideoPropertyView.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Pickle/Classes/VideoPropertyView.swift b/Pickle/Classes/VideoPropertyView.swift index d19dc48..90dbd0e 100644 --- a/Pickle/Classes/VideoPropertyView.swift +++ b/Pickle/Classes/VideoPropertyView.swift @@ -1,9 +1,11 @@ // -// VideoPropertyView.swift -// Pickle +// This source file is part of the carousell/pickle open source project // -// Created by Amelia on 15/4/19. -// Copyright © 2019 Carousell. All rights reserved. +// Copyright © 2017 Carousell and the project authors +// Licensed under Apache License v2.0 +// +// See https://github.com/carousell/pickle/blob/master/LICENSE for license information +// See https://github.com/carousell/pickle/graphs/contributors for the list of project authors // internal final class VideoPropertyView: UIView { From 9906e51eb8ad9f5af29a92eba8f3fd6bd250b5b4 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Tue, 23 Apr 2019 16:28:38 +0800 Subject: [PATCH 06/10] Update colors --- Example/CarousellImagePickerController.swift | 2 +- Pickle/Classes/PhotoAlbumCell.swift | 2 +- Pickle/Classes/PhotoGalleryCameraIconView.swift | 2 +- Pickle/Classes/PhotoGalleryHintLabel.swift | 4 ++-- Pickle/Classes/UIColor+Palette.swift | 5 ++--- Pickle/Classes/VideoPropertyView.swift | 9 +++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Example/CarousellImagePickerController.swift b/Example/CarousellImagePickerController.swift index e53e0c4..19f7802 100644 --- a/Example/CarousellImagePickerController.swift +++ b/Example/CarousellImagePickerController.swift @@ -52,7 +52,7 @@ internal class CarousellImagePickerController: ImagePickerController { string: "You can choose up to \(selectionsLimit) photos for your listing.\n", attributes: [ .font: UIFont.systemFont(ofSize: 12), - .foregroundColor: UIColor.darkGray, + .foregroundColor: UIColor.gray, .backgroundColor: UIColor.white, .paragraphStyle: subtitleStyle ] diff --git a/Pickle/Classes/PhotoAlbumCell.swift b/Pickle/Classes/PhotoAlbumCell.swift index 4f9e07c..0ae9ec5 100644 --- a/Pickle/Classes/PhotoAlbumCell.swift +++ b/Pickle/Classes/PhotoAlbumCell.swift @@ -38,7 +38,7 @@ internal final class PhotoAlbumCell: UITableViewCell { private lazy var subtitleLabel: UILabel = { let label = UILabel() - label.textColor = UIColor.Palette.gray + label.textColor = UIColor.Palette.grey return label }() diff --git a/Pickle/Classes/PhotoGalleryCameraIconView.swift b/Pickle/Classes/PhotoGalleryCameraIconView.swift index 8175313..d02047a 100644 --- a/Pickle/Classes/PhotoGalleryCameraIconView.swift +++ b/Pickle/Classes/PhotoGalleryCameraIconView.swift @@ -31,7 +31,7 @@ internal final class PhotoGalleryCameraIconView: UIView { let label = UILabel() label.text = Bundle(for: type(of: self)).localizedString(forKey: "imagePicker.button.camera", value: "", table: nil).uppercased() label.font = UIFont.forCameraButton - label.textColor = UIColor.Palette.gray + label.textColor = UIColor.Palette.grey return label }() diff --git a/Pickle/Classes/PhotoGalleryHintLabel.swift b/Pickle/Classes/PhotoGalleryHintLabel.swift index 0e96577..58fd29f 100644 --- a/Pickle/Classes/PhotoGalleryHintLabel.swift +++ b/Pickle/Classes/PhotoGalleryHintLabel.swift @@ -64,7 +64,7 @@ internal final class PhotoGalleryHintLabel: UILabel { private lazy var borderLayer: CALayer = { let layer = CALayer() layer.borderWidth = 1 / UIScreen.main.scale - layer.borderColor = UIColor.Palette.lightGray.cgColor + layer.borderColor = UIColor.Palette.lightGrey.cgColor layer.rasterizationScale = UIScreen.main.scale layer.shouldRasterize = true return layer @@ -77,7 +77,7 @@ internal final class PhotoGalleryHintLabel: UILabel { numberOfLines = 0 textAlignment = .center font = UIFont.forHintLabel - textColor = UIColor.Palette.darkGray + textColor = UIColor.Palette.grey } } diff --git a/Pickle/Classes/UIColor+Palette.swift b/Pickle/Classes/UIColor+Palette.swift index 6aa02e7..d84be88 100644 --- a/Pickle/Classes/UIColor+Palette.swift +++ b/Pickle/Classes/UIColor+Palette.swift @@ -14,9 +14,8 @@ internal extension UIColor { internal enum Palette { static let blue = UIColor(hex: 0x2984C0) - static let lightGray = UIColor(hex: 0x8F939C) - static let gray = UIColor(hex: 0x8F939C) - static let darkGray = UIColor(hex: 0x8F939C) + static let lightGrey = UIColor(hex: 0x8F939C) + static let grey = UIColor(hex: 0x8F939C) static let magnesium = UIColor(hex: 0xB2B2B2) static let darkGrey = UIColor(hex: 0x4B4D52) } diff --git a/Pickle/Classes/VideoPropertyView.swift b/Pickle/Classes/VideoPropertyView.swift index 90dbd0e..c0d38e2 100644 --- a/Pickle/Classes/VideoPropertyView.swift +++ b/Pickle/Classes/VideoPropertyView.swift @@ -10,10 +10,11 @@ internal final class VideoPropertyView: UIView { - private let videoIcon: UIImageView = { + private lazy var videoIcon: UIImageView = { let icon = UIImageView() icon.tintColor = .white - icon.image = UIImage(named: "video-icon")?.withRenderingMode(.alwaysTemplate) + let image = UIImage(named: "video-icon", in: Bundle(for: type(of: self)), compatibleWith: nil) + icon.image = image?.withRenderingMode(.alwaysTemplate) return icon }() @@ -42,7 +43,7 @@ internal final class VideoPropertyView: UIView { if value { backgroundColor = UIColor.Palette.blue } else { - backgroundColor = UIColor.Palette.darkGray.withAlphaComponent(0.2) + backgroundColor = UIColor.Palette.grey.withAlphaComponent(0.2) } } @@ -56,7 +57,7 @@ internal final class VideoPropertyView: UIView { } private func setupViews() { - backgroundColor = UIColor.Palette.darkGray.withAlphaComponent(0.2) + backgroundColor = UIColor.Palette.grey.withAlphaComponent(0.2) addSubview(videoIcon) videoIcon.translatesAutoresizingMaskIntoConstraints = false From 362075d6d11770447bb755c29c121a2c0be36094 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Tue, 23 Apr 2019 16:29:01 +0800 Subject: [PATCH 07/10] Use OptionSet to define ImagePickerMediaType --- Example/CarousellImagePickerController.swift | 2 +- Pickle/Classes/ImagePickerConfigurable.swift | 18 ++++++++++++------ .../Classes/PhotoGalleryViewController.swift | 17 ++++++----------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Example/CarousellImagePickerController.swift b/Example/CarousellImagePickerController.swift index 19f7802..40b6248 100644 --- a/Example/CarousellImagePickerController.swift +++ b/Example/CarousellImagePickerController.swift @@ -110,5 +110,5 @@ private struct CarousellTheme: ImagePickerConfigurable { // MARK: Media Types - var mediaType: ImagePickerMediaType? = .unknown + var mediaType: ImagePickerMediaType? = .all } diff --git a/Pickle/Classes/ImagePickerConfigurable.swift b/Pickle/Classes/ImagePickerConfigurable.swift index 1b6b071..d4f4d59 100644 --- a/Pickle/Classes/ImagePickerConfigurable.swift +++ b/Pickle/Classes/ImagePickerConfigurable.swift @@ -87,17 +87,23 @@ public protocol ImagePickerConfigurable { var mediaType: ImagePickerMediaType? { get } } -/// An enum that represents media type selections in ImagePickerController -public enum ImagePickerMediaType { +// Options that represents media type selections in ImagePickerController +public struct ImagePickerMediaType: OptionSet { - /// Show images and videos in ImagePickerController - case unknown + public let rawValue: Int + + public init(rawValue: Int) { + self.rawValue = rawValue + } /// Only show images in ImagePickerController - case image + public static let image = ImagePickerMediaType(rawValue: 1 << 0) /// Only show videos in ImagePickerController - case video + public static let video = ImagePickerMediaType(rawValue: 1 << 1) + + /// Show images and videos in ImagePickerController + public static let all: ImagePickerMediaType = [.image, .video] } /// An enum that represents photo selections allowed in ImagePickerController. diff --git a/Pickle/Classes/PhotoGalleryViewController.swift b/Pickle/Classes/PhotoGalleryViewController.swift index 0c39a1c..0eca88f 100644 --- a/Pickle/Classes/PhotoGalleryViewController.swift +++ b/Pickle/Classes/PhotoGalleryViewController.swift @@ -82,20 +82,15 @@ internal final class PhotoGalleryViewController: UIViewController, let options = PHFetchOptions() options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] - guard let configuration = configuration, - let mediaType = configuration.mediaType - else { + switch configuration?.mediaType { + case .all?: + options.predicate = nil + case .image?: options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) - return PHAsset.fetchAssets(in: self.album, options: options) - } - - switch mediaType { - case .image: - options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) - case .video: + case .video?: options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.video.rawValue) default: - break + options.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) } return PHAsset.fetchAssets(in: self.album, options: options) From 7f7eeb014306a50ab692abc2d2e540029577717d Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Tue, 23 Apr 2019 17:07:21 +0800 Subject: [PATCH 08/10] Subclass GalleryPhotoCell to support video cell --- Pickle.xcodeproj/project.pbxproj | 14 +++-- ...lleryCell.swift => GalleryPhotoCell.swift} | 20 +------- Pickle/Classes/GalleryVideoCell.swift | 51 +++++++++++++++++++ .../Classes/PhotoGalleryViewController.swift | 20 ++++++-- 4 files changed, 77 insertions(+), 28 deletions(-) rename Pickle/Classes/{PhotoGalleryCell.swift => GalleryPhotoCell.swift} (79%) create mode 100644 Pickle/Classes/GalleryVideoCell.swift diff --git a/Pickle.xcodeproj/project.pbxproj b/Pickle.xcodeproj/project.pbxproj index 4b52ed0..51132a7 100644 --- a/Pickle.xcodeproj/project.pbxproj +++ b/Pickle.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; + 9402FADB226F057500C77100 /* GalleryVideoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9402FADA226F057500C77100 /* GalleryVideoCell.swift */; }; 94F4BF192264609C00E7A672 /* VideoPropertyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */; }; B55833221EC08E180061E182 /* CarousellImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55833211EC08E180061E182 /* CarousellImagePickerController.swift */; }; B563515E1F06278E00B5A46D /* UITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B563515D1F06278E00B5A46D /* UITests.swift */; }; @@ -36,7 +37,7 @@ B57BEA70216AAFD700A2C776 /* PhotoGalleryCameraCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA54216AAFD700A2C776 /* PhotoGalleryCameraCell.swift */; }; B57BEA71216AAFD700A2C776 /* SlideUpPresentation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA55216AAFD700A2C776 /* SlideUpPresentation.swift */; }; B57BEA72216AAFD700A2C776 /* ImagePickerControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA56216AAFD700A2C776 /* ImagePickerControllerDelegate.swift */; }; - B57BEA73216AAFD700A2C776 /* PhotoGalleryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA57216AAFD700A2C776 /* PhotoGalleryCell.swift */; }; + B57BEA73216AAFD700A2C776 /* GalleryPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA57216AAFD700A2C776 /* GalleryPhotoCell.swift */; }; B57BEA74216AAFD700A2C776 /* ImagePickerConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA58216AAFD700A2C776 /* ImagePickerConfigurable.swift */; }; B57BEA75216AAFD700A2C776 /* PhotoGalleryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA59216AAFD700A2C776 /* PhotoGalleryViewController.swift */; }; B57BEA76216AAFD700A2C776 /* PhotoAlbumTitleButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEA5A216AAFD700A2C776 /* PhotoAlbumTitleButton.swift */; }; @@ -93,6 +94,7 @@ 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 7D176E52E185B871CF8D97C4 /* Pods_PickleUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PickleUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 9402FADA226F057500C77100 /* GalleryVideoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryVideoCell.swift; sourceTree = ""; }; 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPropertyView.swift; sourceTree = ""; }; B55833211EC08E180061E182 /* CarousellImagePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarousellImagePickerController.swift; sourceTree = ""; }; B563515B1F06278E00B5A46D /* PickleUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PickleUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -122,7 +124,7 @@ B57BEA54216AAFD700A2C776 /* PhotoGalleryCameraCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoGalleryCameraCell.swift; sourceTree = ""; }; B57BEA55216AAFD700A2C776 /* SlideUpPresentation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideUpPresentation.swift; sourceTree = ""; }; B57BEA56216AAFD700A2C776 /* ImagePickerControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePickerControllerDelegate.swift; sourceTree = ""; }; - B57BEA57216AAFD700A2C776 /* PhotoGalleryCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoGalleryCell.swift; sourceTree = ""; }; + B57BEA57216AAFD700A2C776 /* GalleryPhotoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GalleryPhotoCell.swift; sourceTree = ""; }; B57BEA58216AAFD700A2C776 /* ImagePickerConfigurable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePickerConfigurable.swift; sourceTree = ""; }; B57BEA59216AAFD700A2C776 /* PhotoGalleryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoGalleryViewController.swift; sourceTree = ""; }; B57BEA5A216AAFD700A2C776 /* PhotoAlbumTitleButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoAlbumTitleButton.swift; sourceTree = ""; }; @@ -276,7 +278,9 @@ B57BEA53216AAFD700A2C776 /* PhotoDetailViewController.swift */, B57BEA54216AAFD700A2C776 /* PhotoGalleryCameraCell.swift */, B57BEA5E216AAFD700A2C776 /* PhotoGalleryCameraIconView.swift */, - B57BEA57216AAFD700A2C776 /* PhotoGalleryCell.swift */, + B57BEA57216AAFD700A2C776 /* GalleryPhotoCell.swift */, + 9402FADA226F057500C77100 /* GalleryVideoCell.swift */, + 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */, 20DB284D22560DB000037FEF /* LiveView.swift */, 20FC48022256FAC3004CCD1D /* CameraSessionHandler.swift */, 20DB284E22560DB000037FEF /* PhotoGalleryLiveViewCell.swift */, @@ -291,7 +295,6 @@ B57BEA61216AAFD700A2C776 /* UIColor+Palette.swift */, B57BEA4B216AAFD700A2C776 /* UIFont+Style.swift */, B57BEA4A216AAFD700A2C776 /* UINavigationController+ImagePickerConfigurable.swift */, - 94F4BF182264609C00E7A672 /* VideoPropertyView.swift */, ); path = Classes; sourceTree = ""; @@ -538,11 +541,12 @@ B57BEA6E216AAFD700A2C776 /* PhotoAlbumsTableView.swift in Sources */, B57BEA7C216AAFD700A2C776 /* PhotoAlbumsViewController.swift in Sources */, B57BEA76216AAFD700A2C776 /* PhotoAlbumTitleButton.swift in Sources */, + 9402FADB226F057500C77100 /* GalleryVideoCell.swift in Sources */, B57BEA6F216AAFD700A2C776 /* PhotoDetailViewController.swift in Sources */, B57BEA70216AAFD700A2C776 /* PhotoGalleryCameraCell.swift in Sources */, B57BEA7A216AAFD700A2C776 /* PhotoGalleryCameraIconView.swift in Sources */, 94F4BF192264609C00E7A672 /* VideoPropertyView.swift in Sources */, - B57BEA73216AAFD700A2C776 /* PhotoGalleryCell.swift in Sources */, + B57BEA73216AAFD700A2C776 /* GalleryPhotoCell.swift in Sources */, B57BEA6B216AAFD700A2C776 /* PhotoGalleryHintLabel.swift in Sources */, 20FC48032256FAC3004CCD1D /* CameraSessionHandler.swift in Sources */, B57BEA77216AAFD700A2C776 /* PhotoGalleryTagLabel.swift in Sources */, diff --git a/Pickle/Classes/PhotoGalleryCell.swift b/Pickle/Classes/GalleryPhotoCell.swift similarity index 79% rename from Pickle/Classes/PhotoGalleryCell.swift rename to Pickle/Classes/GalleryPhotoCell.swift index 51cfd28..567e382 100644 --- a/Pickle/Classes/PhotoGalleryCell.swift +++ b/Pickle/Classes/GalleryPhotoCell.swift @@ -11,7 +11,7 @@ import UIKit import Photos -internal final class PhotoGalleryCell: UICollectionViewCell { +internal class GalleryPhotoCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) @@ -32,8 +32,6 @@ internal final class PhotoGalleryCell: UICollectionViewCell { return imageView }() - private let videoPropertyView = VideoPropertyView() - private let overlayView = UIView() private let tagLabel = PhotoGalleryTagLabel() @@ -43,11 +41,9 @@ internal final class PhotoGalleryCell: UICollectionViewCell { overlayView.isHidden = false tagLabel.text = text accessibilityIdentifier = text - videoPropertyView.setSelected(true) } else { overlayView.isHidden = true accessibilityIdentifier = nil - videoPropertyView.setSelected(false) } } } @@ -62,7 +58,6 @@ internal final class PhotoGalleryCell: UICollectionViewCell { imageRequestID = nil taggedText = nil imageView.image = nil - videoPropertyView.isHidden = true } // MARK: - @@ -88,9 +83,6 @@ internal final class PhotoGalleryCell: UICollectionViewCell { } } - videoPropertyView.isHidden = asset.mediaType != .video - videoPropertyView.configure(duration: asset.duration) - if let color = configuration?.selectedImageOverlayColor { overlayView.backgroundColor = color } @@ -100,7 +92,7 @@ internal final class PhotoGalleryCell: UICollectionViewCell { self.taggedText = taggedText } - private func setUpSubviews() { + func setUpSubviews() { // Set the cell as the accessibility element for UI tests to work. isAccessibilityElement = true @@ -121,13 +113,5 @@ internal final class PhotoGalleryCell: UICollectionViewCell { tagLabel.widthAnchor.constraint(equalTo: tagLabel.heightAnchor).isActive = true tagLabel.topAnchor.constraint(equalTo: overlayView.topAnchor, constant: 10).isActive = true tagLabel.trailingAnchor.constraint(equalTo: overlayView.trailingAnchor, constant: -10).isActive = true - - contentView.addSubview(videoPropertyView) - videoPropertyView.translatesAutoresizingMaskIntoConstraints = false - videoPropertyView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true - videoPropertyView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true - videoPropertyView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true - videoPropertyView.heightAnchor.constraint(equalToConstant: 24).isActive = true } - } diff --git a/Pickle/Classes/GalleryVideoCell.swift b/Pickle/Classes/GalleryVideoCell.swift new file mode 100644 index 0000000..174083e --- /dev/null +++ b/Pickle/Classes/GalleryVideoCell.swift @@ -0,0 +1,51 @@ +// +// This source file is part of the carousell/pickle open source project +// +// Copyright © 2017 Carousell and the project authors +// Licensed under Apache License v2.0 +// +// See https://github.com/carousell/pickle/blob/master/LICENSE for license information +// See https://github.com/carousell/pickle/graphs/contributors for the list of project authors +// + +import UIKit +import Photos + +internal final class GalleryVideoCell: GalleryPhotoCell { + + private let videoPropertyView = VideoPropertyView() + + override func prepareForReuse() { + super.prepareForReuse() + } + + override func setUpSubviews() { + super.setUpSubviews() + + contentView.addSubview(videoPropertyView) + videoPropertyView.translatesAutoresizingMaskIntoConstraints = false + videoPropertyView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true + videoPropertyView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true + videoPropertyView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true + videoPropertyView.heightAnchor.constraint(equalToConstant: 24).isActive = true + } + + override func configure( + with asset: PHAsset, + taggedText: String? = nil, + configuration: ImagePickerConfigurable?) { + + super.configure( + with: asset, + taggedText: taggedText, + configuration: configuration) + + videoPropertyView.configure(duration: asset.duration) + + if taggedText != nil { + videoPropertyView.setSelected(true) + } else { + videoPropertyView.setSelected(false) + } + } +} diff --git a/Pickle/Classes/PhotoGalleryViewController.swift b/Pickle/Classes/PhotoGalleryViewController.swift index 0eca88f..e52eedb 100644 --- a/Pickle/Classes/PhotoGalleryViewController.swift +++ b/Pickle/Classes/PhotoGalleryViewController.swift @@ -119,7 +119,8 @@ internal final class PhotoGalleryViewController: UIViewController, collectionView.delegate = self collectionView.backgroundColor = UIColor.white collectionView.register(PhotoGalleryCameraCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryCameraCell.self)) - collectionView.register(PhotoGalleryCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryCell.self)) + collectionView.register(GalleryPhotoCell.self, forCellWithReuseIdentifier: String(describing: GalleryPhotoCell.self)) + collectionView.register(GalleryVideoCell.self, forCellWithReuseIdentifier: String(describing: GalleryVideoCell.self)) collectionView.register(PhotoGalleryLiveViewCell.self, forCellWithReuseIdentifier: String(describing: PhotoGalleryLiveViewCell.self)) collectionView.allowsMultipleSelection = true return collectionView @@ -175,15 +176,24 @@ internal final class PhotoGalleryViewController: UIViewController, } } - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PhotoGalleryCell.self), for: indexPath) let index = isCameraCompatible ? indexPath.row - 1 : indexPath.row let asset = fetchResult[index] - if let text = delegate?.photoGalleryViewController(self, taggedTextForPhoto: asset) { - (cell as? PhotoGalleryCell)?.configure(with: asset, taggedText: text, configuration: configuration) + let text = delegate?.photoGalleryViewController(self, taggedTextForPhoto: asset) + var cell: UICollectionViewCell + if asset.mediaType == .video { + cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryVideoCell.self), for: indexPath) + (cell as? GalleryVideoCell)?.configure(with: asset, taggedText: text, configuration: configuration) + collectionView.deselectItem(at: indexPath, animated: false) + } else { + cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryPhotoCell.self), for: indexPath) + (cell as? GalleryPhotoCell)?.configure(with: asset, taggedText: text, configuration: configuration) + collectionView.deselectItem(at: indexPath, animated: false) + } + + if text != nil { collectionView.selectItem(at: indexPath, animated: false, scrollPosition: []) } else { - (cell as? PhotoGalleryCell)?.configure(with: asset, configuration: configuration) collectionView.deselectItem(at: indexPath, animated: false) } From 7924ab7918d92e2c552af748a60cd756aef2fa65 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Wed, 24 Apr 2019 13:38:47 +0800 Subject: [PATCH 09/10] Minor code adjustments --- Pickle/Classes/GalleryVideoCell.swift | 11 +---------- Pickle/Classes/PhotoGalleryViewController.swift | 2 -- Pickle/Classes/VideoPropertyView.swift | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/Pickle/Classes/GalleryVideoCell.swift b/Pickle/Classes/GalleryVideoCell.swift index 174083e..b6782af 100644 --- a/Pickle/Classes/GalleryVideoCell.swift +++ b/Pickle/Classes/GalleryVideoCell.swift @@ -15,10 +15,6 @@ internal final class GalleryVideoCell: GalleryPhotoCell { private let videoPropertyView = VideoPropertyView() - override func prepareForReuse() { - super.prepareForReuse() - } - override func setUpSubviews() { super.setUpSubviews() @@ -41,11 +37,6 @@ internal final class GalleryVideoCell: GalleryPhotoCell { configuration: configuration) videoPropertyView.configure(duration: asset.duration) - - if taggedText != nil { - videoPropertyView.setSelected(true) - } else { - videoPropertyView.setSelected(false) - } + videoPropertyView.setSelected(taggedText != nil) } } diff --git a/Pickle/Classes/PhotoGalleryViewController.swift b/Pickle/Classes/PhotoGalleryViewController.swift index e52eedb..da7ee1d 100644 --- a/Pickle/Classes/PhotoGalleryViewController.swift +++ b/Pickle/Classes/PhotoGalleryViewController.swift @@ -184,11 +184,9 @@ internal final class PhotoGalleryViewController: UIViewController, if asset.mediaType == .video { cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryVideoCell.self), for: indexPath) (cell as? GalleryVideoCell)?.configure(with: asset, taggedText: text, configuration: configuration) - collectionView.deselectItem(at: indexPath, animated: false) } else { cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: GalleryPhotoCell.self), for: indexPath) (cell as? GalleryPhotoCell)?.configure(with: asset, taggedText: text, configuration: configuration) - collectionView.deselectItem(at: indexPath, animated: false) } if text != nil { diff --git a/Pickle/Classes/VideoPropertyView.swift b/Pickle/Classes/VideoPropertyView.swift index c0d38e2..0836792 100644 --- a/Pickle/Classes/VideoPropertyView.swift +++ b/Pickle/Classes/VideoPropertyView.swift @@ -39,8 +39,8 @@ internal final class VideoPropertyView: UIView { durationLabel.text = formatter.string(from: duration) } - func setSelected(_ value: Bool) { - if value { + func setSelected(_ isSelected: Bool) { + if isSelected { backgroundColor = UIColor.Palette.blue } else { backgroundColor = UIColor.Palette.grey.withAlphaComponent(0.2) From c4ee19a9f5f2cca5b55c4c8d1f965cc7caedff89 Mon Sep 17 00:00:00 2001 From: Anasthasia Amelia Date: Wed, 24 Apr 2019 13:40:05 +0800 Subject: [PATCH 10/10] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff4129a..7b65a6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## Next release + +* Add support for video selection [#44](https://github.com/carousell/pickle/pull/44) + ## v1.4.0 * Swift 4.2 [#32](https://github.com/carousell/pickle/pull/32)