Skip to content

Commit

Permalink
Merge pull request #59 from hyperoslo/feature/configuration
Browse files Browse the repository at this point in the history
Refactor configuration to be static instead of a singleton
  • Loading branch information
zenangst committed Nov 19, 2015
2 parents 55ef852 + 3c4d342 commit 764a875
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 56 deletions.
12 changes: 5 additions & 7 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class BottomContainerView: UIView {

public lazy var doneButton: UIButton = { [unowned self] in
let button = UIButton()
button.setTitle(self.pickerConfiguration.cancelButtonTitle, forState: .Normal)
button.titleLabel?.font = self.pickerConfiguration.doneButton
button.setTitle(Configuration.cancelButtonTitle, forState: .Normal)
button.titleLabel?.font = Configuration.doneButton
button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside)

return button
Expand All @@ -44,7 +44,7 @@ public class BottomContainerView: UIView {

lazy var topSeparator: UIView = { [unowned self] in
let view = UIView()
view.backgroundColor = self.pickerConfiguration.backgroundColor
view.backgroundColor = Configuration.backgroundColor

return view
}()
Expand All @@ -56,8 +56,6 @@ public class BottomContainerView: UIView {
return gesture
}()

lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

weak var delegate: BottomContainerViewDelegate?
var pastCount = 0

Expand All @@ -71,7 +69,7 @@ public class BottomContainerView: UIView {
$0.translatesAutoresizingMaskIntoConstraints = false
}

backgroundColor = pickerConfiguration.backgroundColor
backgroundColor = Configuration.backgroundColor
stackView.addGestureRecognizer(tapGestureRecognizer)

setupConstraints()
Expand All @@ -84,7 +82,7 @@ public class BottomContainerView: UIView {
// MARK: - Action methods

func doneButtonDidPress(button: UIButton) {
if button.currentTitle == pickerConfiguration.cancelButtonTitle {
if button.currentTitle == Configuration.cancelButtonTitle {
delegate?.cancelButtonDidPress()
} else {
delegate?.doneButtonDidPress()
Expand Down
4 changes: 1 addition & 3 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ class ButtonPicker: UIButton {
lazy var numberLabel: UILabel = { [unowned self] in
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = self.pickerConfiguration.numberLabelFont
label.font = Configuration.numberLabelFont

return label
}()

lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

weak var delegate: ButtonPickerDelegate?

// MARK: - Initializers
Expand Down
18 changes: 8 additions & 10 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ protocol CameraViewDelegate: class {

class CameraView: UIViewController {

lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

lazy var blurView: UIVisualEffectView = { [unowned self] in
let effect = UIBlurEffect(style: .Dark)
let blurView = UIVisualEffectView(effect: effect)
Expand Down Expand Up @@ -49,20 +47,20 @@ class CameraView: UIViewController {

lazy var noCameraLabel: UILabel = { [unowned self] in
let label = UILabel()
label.font = self.pickerConfiguration.noCameraFont
label.textColor = self.pickerConfiguration.noCameraColor
label.text = self.pickerConfiguration.noCameraTitle
label.font = Configuration.noCameraFont
label.textColor = Configuration.noCameraColor
label.text = Configuration.noCameraTitle
label.sizeToFit()

return label
}()

lazy var noCameraButton: UIButton = { [unowned self] in
let button = UIButton(type: .System)
let title = NSAttributedString(string: self.pickerConfiguration.settingsTitle,
let title = NSAttributedString(string: Configuration.settingsTitle,
attributes: [
NSFontAttributeName : self.pickerConfiguration.settingsFont,
NSForegroundColorAttributeName : self.pickerConfiguration.settingsColor,
NSFontAttributeName : Configuration.settingsFont,
NSForegroundColorAttributeName : Configuration.settingsColor,
])

button.setAttributedTitle(title, forState: .Normal)
Expand Down Expand Up @@ -93,8 +91,8 @@ class CameraView: UIViewController {

initializeCamera()

view.backgroundColor = self.pickerConfiguration.mainColor
previewLayer?.backgroundColor = self.pickerConfiguration.mainColor.CGColor
view.backgroundColor = Configuration.mainColor
previewLayer?.backgroundColor = Configuration.mainColor.CGColor
}

// MARK: - Layout
Expand Down
38 changes: 17 additions & 21 deletions Source/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@ import UIKit

public struct Configuration {

static let sharedInstance = Configuration()

public init() { }

// MARK: Colors

public var backgroundColor = UIColor(red:0.15, green:0.19, blue:0.24, alpha:1)
public var mainColor = UIColor(red:0.09, green:0.11, blue:0.13, alpha:1)
public var noImagesColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1)
public var noCameraColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1)
public var settingsColor = UIColor.whiteColor()
public static var backgroundColor = UIColor(red:0.15, green:0.19, blue:0.24, alpha:1)
public static var mainColor = UIColor(red:0.09, green:0.11, blue:0.13, alpha:1)
public static var noImagesColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1)
public static var noCameraColor = UIColor(red:0.86, green:0.86, blue:0.86, alpha:1)
public static var settingsColor = UIColor.whiteColor()

// MARK: Fonts

public var numberLabelFont = UIFont(name: "HelveticaNeue-Bold", size: 19)!
public var doneButton = UIFont(name: "HelveticaNeue-Medium", size: 19)!
public var flashButton = UIFont(name: "HelveticaNeue-Medium", size: 12)!
public var noImagesFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!
public var noCameraFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!
public var settingsFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!
public static var numberLabelFont = UIFont(name: "HelveticaNeue-Bold", size: 19)!
public static var doneButton = UIFont(name: "HelveticaNeue-Medium", size: 19)!
public static var flashButton = UIFont(name: "HelveticaNeue-Medium", size: 12)!
public static var noImagesFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!
public static var noCameraFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!
public static var settingsFont = UIFont(name: "HelveticaNeue-Medium", size: 18)!

// MARK: Titles

public var cancelButtonTitle = "Cancel"
public var doneButtonTitle = "Done"
public var noImagesTitle = "No images available"
public var noCameraTitle = "Camera is not available"
public var settingsTitle = "Settings"
public static var cancelButtonTitle = "Cancel"
public static var doneButtonTitle = "Done"
public static var noImagesTitle = "No images available"
public static var noCameraTitle = "Camera is not available"
public static var settingsTitle = "Settings"

// MARK: Dimensions

public var cellSpacing: CGFloat = 2
public static var cellSpacing: CGFloat = 2
}
14 changes: 6 additions & 8 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ImageGalleryView: UIView {
let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0),
collectionViewLayout: self.collectionViewLayout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = self.pickerConfiguration.mainColor
collectionView.backgroundColor = Configuration.mainColor
collectionView.showsHorizontalScrollIndicator = false

return collectionView
Expand All @@ -34,7 +34,7 @@ public class ImageGalleryView: UIView {
lazy var collectionViewLayout: UICollectionViewLayout = { [unowned self] in
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .Horizontal
layout.minimumInteritemSpacing = self.pickerConfiguration.cellSpacing
layout.minimumInteritemSpacing = Configuration.cellSpacing
layout.minimumLineSpacing = 2
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)

Expand Down Expand Up @@ -70,13 +70,11 @@ public class ImageGalleryView: UIView {

lazy var assets = [PHAsset]()

lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

public lazy var noImagesLabel: UILabel = { [unowned self] in
let label = UILabel()
label.font = self.pickerConfiguration.noImagesFont
label.textColor = self.pickerConfiguration.noImagesColor
label.text = self.pickerConfiguration.noImagesTitle
label.font = Configuration.noImagesFont
label.textColor = Configuration.noImagesColor
label.text = Configuration.noImagesTitle
label.alpha = 0
label.sizeToFit()
self.addSubview(label)
Expand All @@ -96,7 +94,7 @@ public class ImageGalleryView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = pickerConfiguration.mainColor
backgroundColor = Configuration.mainColor

collectionView.registerClass(ImageGalleryViewCell.self,
forCellWithReuseIdentifier: CollectionView.reusableIdentifier)
Expand Down
6 changes: 2 additions & 4 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public class ImagePickerController: UIViewController {
return gesture
}()

public lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

public weak var delegate: ImagePickerDelegate?
public var stack = ImageStack()
let totalHeight = UIScreen.mainScreen().bounds.size.height
Expand Down Expand Up @@ -87,7 +85,7 @@ public class ImagePickerController: UIViewController {
}

view.backgroundColor = .whiteColor()
view.backgroundColor = pickerConfiguration.mainColor
view.backgroundColor = Configuration.mainColor
cameraController.view.addGestureRecognizer(panGestureRecognizer)

subscribe()
Expand Down Expand Up @@ -142,7 +140,7 @@ public class ImagePickerController: UIViewController {
guard let sender = notification.object as? ImageStack else { return }

let title = !sender.assets.isEmpty ?
pickerConfiguration.doneButtonTitle : pickerConfiguration.cancelButtonTitle
Configuration.doneButtonTitle : Configuration.cancelButtonTitle
bottomContainer.doneButton.setTitle(title, forState: .Normal)
}

Expand Down
4 changes: 1 addition & 3 deletions Source/TopView/TopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TopView: UIView {
button.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0)
button.setTitleColor(.whiteColor(), forState: .Normal)
button.setTitleColor(.whiteColor(), forState: .Highlighted)
button.titleLabel?.font = self.pickerConfiguration.flashButton
button.titleLabel?.font = Configuration.flashButton
button.addTarget(self, action: "flashButtonDidPress:", forControlEvents: .TouchUpInside)
button.contentHorizontalAlignment = .Left

Expand All @@ -40,8 +40,6 @@ class TopView: UIView {
return button
}()

lazy var pickerConfiguration: Configuration = Configuration.sharedInstance

weak var delegate: TopViewDelegate?

// MARK: - Initializers
Expand Down

0 comments on commit 764a875

Please sign in to comment.