From 6307c3119fa0228a9a3b7012a9f199be4a6529fb Mon Sep 17 00:00:00 2001 From: Anton Terehov Date: Thu, 11 Aug 2016 16:58:43 +0100 Subject: [PATCH 1/3] Adds possibility to configure colour of LiveCameraCell, also providing default option. --- .../Source/Input/Photos/LiveCameraCell.swift | 6 ++++++ .../Source/Input/Photos/PhotosChatInputItem.swift | 13 +++++++++++-- .../Source/Input/Photos/PhotosInputView.swift | 12 +++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift index 203f6db..1614c37 100644 --- a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift +++ b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift @@ -37,6 +37,12 @@ class LiveCameraCell: UICollectionViewCell { private var iconImageView: UIImageView! + override var backgroundColor: UIColor? { + didSet { + self.contentView.backgroundColor = backgroundColor + } + } + override init(frame: CGRect) { super.init(frame: frame) self.commonInit() diff --git a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift index 294f62a..db8b702 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift @@ -33,9 +33,13 @@ public class PhotosChatInputItem: ChatInputItemProtocol { public weak var presentingController: UIViewController? let buttonAppearance: TabInputButtonAppearance - public init(presentingController: UIViewController?, tabInputButtonAppearance: TabInputButtonAppearance = Class.createDefaultButtonAppearance()) { + let inputViewAppearance: PhotosInputViewAppearance + public init(presentingController: UIViewController?, + tabInputButtonAppearance: TabInputButtonAppearance = Class.createDefaultButtonAppearance(), + inputViewAppearance: PhotosInputViewAppearance = Class.createDefaultCameraAppearance()) { self.presentingController = presentingController self.buttonAppearance = tabInputButtonAppearance + self.inputViewAppearance = inputViewAppearance } public class func createDefaultButtonAppearance() -> TabInputButtonAppearance { @@ -47,12 +51,17 @@ public class PhotosChatInputItem: ChatInputItemProtocol { return TabInputButtonAppearance(images: images, size: nil) } + public class func createDefaultCameraAppearance() -> PhotosInputViewAppearance { + let defaultColor = UIColor(red: 24.0/255.0, green: 101.0/255.0, blue: 245.0/255.0, alpha: 1) + return PhotosInputViewAppearance(color: defaultColor) + } + lazy private var internalTabView: UIButton = { return TabInputButton.makeInputButton(withAppearance: self.buttonAppearance) }() lazy var photosInputView: PhotosInputViewProtocol = { - let photosInputView = PhotosInputView(presentingController: self.presentingController) + let photosInputView = PhotosInputView(presentingController: self.presentingController, appearance: self.inputViewAppearance) photosInputView.delegate = self return photosInputView }() diff --git a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift index ff17ffc..2324b24 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift @@ -26,6 +26,13 @@ import UIKit import Photos import Chatto +public struct PhotosInputViewAppearance { + public var color: UIColor + public init(color: UIColor) { + self.color = color + } +} + protocol PhotosInputViewProtocol { weak var delegate: PhotosInputViewDelegate? { get set } weak var presentingController: UIViewController? { get } @@ -70,9 +77,11 @@ class PhotosInputView: UIView, PhotosInputViewProtocol { } weak var presentingController: UIViewController? - init(presentingController: UIViewController?) { + var appearance: PhotosInputViewAppearance? + init(presentingController: UIViewController?, appearance: PhotosInputViewAppearance) { super.init(frame: CGRect.zero) self.presentingController = presentingController + self.appearance = appearance self.commonInit() } @@ -189,6 +198,7 @@ extension PhotosInputView: UICollectionViewDataSource { var cell: UICollectionViewCell if indexPath.item == Constants.liveCameraItemIndex { let liveCameraCell = collectionView.dequeueReusableCellWithReuseIdentifier("LiveCameraCell", forIndexPath: indexPath) as! LiveCameraCell + liveCameraCell.backgroundColor = self.appearance?.color self.liveCameraPresenter.cameraAuthorizationStatus = self.cameraAuthorizationStatus cell = liveCameraCell } else { From 9c3b40df1d653760cca4feef1c54f0e5ab970245 Mon Sep 17 00:00:00 2001 From: Anton Terehov Date: Thu, 11 Aug 2016 17:03:44 +0100 Subject: [PATCH 2/3] Refactors method name --- ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift index db8b702..6dd8059 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift @@ -36,7 +36,7 @@ public class PhotosChatInputItem: ChatInputItemProtocol { let inputViewAppearance: PhotosInputViewAppearance public init(presentingController: UIViewController?, tabInputButtonAppearance: TabInputButtonAppearance = Class.createDefaultButtonAppearance(), - inputViewAppearance: PhotosInputViewAppearance = Class.createDefaultCameraAppearance()) { + inputViewAppearance: PhotosInputViewAppearance = Class.createDefaultInputViewAppearance()) { self.presentingController = presentingController self.buttonAppearance = tabInputButtonAppearance self.inputViewAppearance = inputViewAppearance @@ -51,7 +51,7 @@ public class PhotosChatInputItem: ChatInputItemProtocol { return TabInputButtonAppearance(images: images, size: nil) } - public class func createDefaultCameraAppearance() -> PhotosInputViewAppearance { + public class func createDefaultInputViewAppearance() -> PhotosInputViewAppearance { let defaultColor = UIColor(red: 24.0/255.0, green: 101.0/255.0, blue: 245.0/255.0, alpha: 1) return PhotosInputViewAppearance(color: defaultColor) } From ed76fe6336f1c560b0cd45a93bd6cb5e951f85ad Mon Sep 17 00:00:00 2001 From: Anton Terehov Date: Fri, 12 Aug 2016 12:00:32 +0100 Subject: [PATCH 3/3] Code review comments --- .../Source/Input/Photos/LiveCameraCell.swift | 10 +++++++--- .../Source/Input/Photos/PhotosChatInputItem.swift | 3 ++- .../Source/Input/Photos/PhotosInputView.swift | 9 ++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift index 1614c37..1b9497a 100644 --- a/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift +++ b/ChattoAdditions/Source/Input/Photos/LiveCameraCell.swift @@ -27,6 +27,10 @@ import Foundation import UIKit import Chatto +public struct LiveCameraCellAppearance { + public var backgroundColor: UIColor +} + class LiveCameraCell: UICollectionViewCell { private struct Constants { @@ -37,9 +41,9 @@ class LiveCameraCell: UICollectionViewCell { private var iconImageView: UIImageView! - override var backgroundColor: UIColor? { + var appearance: LiveCameraCellAppearance = LiveCameraCellAppearance(backgroundColor: Constants.backgroundColor) { didSet { - self.contentView.backgroundColor = backgroundColor + self.contentView.backgroundColor = self.appearance.backgroundColor } } @@ -55,7 +59,7 @@ class LiveCameraCell: UICollectionViewCell { private func commonInit() { self.configureIcon() - self.contentView.backgroundColor = Constants.backgroundColor + self.contentView.backgroundColor = self.appearance.backgroundColor } var captureLayer: CALayer? { diff --git a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift index 6dd8059..a4a1404 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift @@ -53,7 +53,8 @@ public class PhotosChatInputItem: ChatInputItemProtocol { public class func createDefaultInputViewAppearance() -> PhotosInputViewAppearance { let defaultColor = UIColor(red: 24.0/255.0, green: 101.0/255.0, blue: 245.0/255.0, alpha: 1) - return PhotosInputViewAppearance(color: defaultColor) + let liveCameraCellAppearence = LiveCameraCellAppearance(backgroundColor: defaultColor) + return PhotosInputViewAppearance(liveCameraCellAppearence: liveCameraCellAppearence) } lazy private var internalTabView: UIButton = { diff --git a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift index 2324b24..c7cee75 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosInputView.swift @@ -27,10 +27,7 @@ import Photos import Chatto public struct PhotosInputViewAppearance { - public var color: UIColor - public init(color: UIColor) { - self.color = color - } + public var liveCameraCellAppearence: LiveCameraCellAppearance } protocol PhotosInputViewProtocol { @@ -198,7 +195,9 @@ extension PhotosInputView: UICollectionViewDataSource { var cell: UICollectionViewCell if indexPath.item == Constants.liveCameraItemIndex { let liveCameraCell = collectionView.dequeueReusableCellWithReuseIdentifier("LiveCameraCell", forIndexPath: indexPath) as! LiveCameraCell - liveCameraCell.backgroundColor = self.appearance?.color + if let liveCameraCellAppearence = self.appearance?.liveCameraCellAppearence { + liveCameraCell.appearance = liveCameraCellAppearence + } self.liveCameraPresenter.cameraAuthorizationStatus = self.cameraAuthorizationStatus cell = liveCameraCell } else {