Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #13

Merged
merged 67 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
3265bbe
Add interface
richardtop Aug 10, 2015
c62606e
Add console outputs
richardtop Aug 10, 2015
d5e43e3
Add image storage array
richardtop Aug 10, 2015
1c14032
Add array of views
richardtop Aug 10, 2015
cfbf8fb
Merge pull request #1 from richardoti/refactor
richardtop Aug 10, 2015
bf514e0
Fix affine transform bug
richardtop Aug 10, 2015
d00b669
Make ImageStack a singleton
richardtop Aug 10, 2015
c231179
Add stub for view generation
richardtop Aug 10, 2015
b0a252e
Make scheme shared
richardtop Aug 10, 2015
d26d087
Separate model (ImageStack) and View (StackView(
richardtop Aug 10, 2015
c2be320
MVP
richardtop Aug 11, 2015
24bba2e
Add PUSH to stack
richardtop Aug 11, 2015
3af3d1e
Drop Wrapper to the floor
richardtop Aug 11, 2015
24af5c8
Merge pull request #2 from richardoti/refactor
richardtop Aug 11, 2015
094bdf9
Refactor ImageStack
richardtop Aug 11, 2015
4f0de9e
Refactor StackView
richardtop Aug 11, 2015
c64a720
Comment-out temporarily unused functions
richardtop Aug 11, 2015
7d1b645
Merge pull request #3 from richardoti/refactor
richardtop Aug 11, 2015
622c719
Show images in correct order
richardtop Aug 11, 2015
ab44a32
Delegate method to map
richardtop Aug 11, 2015
070efcd
Add array of views and gesture recognizer
richardtop Aug 11, 2015
e512178
Refactor delegate methods
richardtop Aug 11, 2015
ff32539
Refactor StackView
richardtop Aug 11, 2015
ca040fa
Refactor stack view
richardtop Aug 11, 2015
a8ef893
Remove debugging code from ImageStack
richardtop Aug 11, 2015
75552f7
Fully remove ImageWrapper
richardtop Aug 11, 2015
1afb0d3
Refactor variable names to StackView
richardtop Aug 11, 2015
62104dd
Fully refactor remains of Wrapper
richardtop Aug 11, 2015
5ea7743
Remove shared scheme
richardtop Aug 11, 2015
d9186a6
Merge branch 'master' of https://github.com/hyperoslo/ImagePicker
richardtop Aug 14, 2015
b2f2990
Merge pull request #12 from richardoti/master
richardtop Aug 14, 2015
d1a5cc3
Make stack to work like real stack (append to head)
richardtop Aug 17, 2015
eb8f80c
Fix correct ordering of pictures
richardtop Aug 17, 2015
35b09b1
Add TODO
richardtop Aug 17, 2015
aafbee9
Revert previous behavior (append to the end)
richardtop Aug 18, 2015
3f2ad44
Add animations
richardtop Aug 18, 2015
4707d74
Merge pull request #14 from hyperoslo/improve/imageStack
richardtop Aug 18, 2015
6892ca7
No println's are allowed
richardtop Aug 18, 2015
9767f45
Correct layout to match original
richardtop Aug 24, 2015
8f6743d
Change NSMutableArray to array of images
richardtop Aug 24, 2015
d0c175a
Replace delegate with notifications
richardtop Aug 24, 2015
5492b09
Bind photo button label to notifications
richardtop Aug 24, 2015
65e7133
Subscribe at correct place
richardtop Aug 24, 2015
a576b4c
Re-indent
richardtop Aug 24, 2015
006457b
Remove extra pushes to stack
richardtop Aug 24, 2015
6b6d7c2
ImageStack - make class, send sender with notifications
richardtop Aug 24, 2015
c4675a5
Stackview - remove shared instance
richardtop Aug 24, 2015
7411f83
Remove shared instance from Picker shutter button
richardtop Aug 24, 2015
b87bf7b
Remove shared instance from datasource
richardtop Aug 24, 2015
b800bc5
Remove shared instance from controller
richardtop Aug 24, 2015
5356ec7
Remove shared instance / delegate methods from gallery
richardtop Aug 24, 2015
a14ecd5
Fully remove shared stack
richardtop Aug 24, 2015
3a3778b
Merge pull request #16 from hyperoslo/remove-shared-instance
richardtop Aug 24, 2015
623daf8
Remove shared stack from the controller
richardtop Aug 24, 2015
eea9fd9
Remove commented code
richardtop Aug 24, 2015
d3688c2
Fix gesture recognizers and make interface compatible
richardtop Aug 24, 2015
50c624a
Make vars and methods public
richardtop Aug 24, 2015
d7f5ca4
Change button title at one point only
richardtop Aug 25, 2015
b95a87d
Add stack-reload notification
richardtop Aug 25, 2015
d1f4913
Fix improper view rendering
richardtop Aug 25, 2015
ca73037
Reload collectionview automatically on source change
richardtop Aug 25, 2015
8bde548
Revert "Reload collectionview automatically on source change"
richardtop Aug 25, 2015
d403ff7
Add public method to reset images in stack
richardtop Aug 25, 2015
1148868
Make only one placeholder visible at a time
richardtop Aug 25, 2015
6490e0c
Refactor according to the suggestions
richardtop Aug 25, 2015
72955c7
Refactor according to the suggestions
richardtop Aug 26, 2015
4f80265
Refactor according to the suggestions
richardtop Aug 26, 2015
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
74 changes: 14 additions & 60 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ protocol BottomContainerViewDelegate {
func pickerButtonDidPress()
func doneButtonDidPress()
func cancelButtonDidPress()
func imageWrapperDidPress()
func imageStackViewDidPress()
}

class BottomContainerView: UIView {
Expand Down Expand Up @@ -40,13 +40,12 @@ class BottomContainerView: UIView {
return button
}()

lazy var imageWrapper: ImageWrapper = {
let view = ImageWrapper()
lazy var stackView: ImageStackView = {
let view = ImageStackView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
view.setTranslatesAutoresizingMaskIntoConstraints(false)

return view
}()

lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
Expand Down Expand Up @@ -75,9 +74,9 @@ class BottomContainerView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)

[borderPickerButton, pickerButton, doneButton, imageWrapper, topSeparator].map { self.addSubview($0) }
backgroundColor = self.configuration.backgroundColor
imageWrapper.addGestureRecognizer(self.tapGestureRecognizer)
[borderPickerButton, pickerButton, doneButton, stackView, topSeparator].map { self.addSubview($0) }
backgroundColor = configuration.backgroundColor
stackView.addGestureRecognizer(tapGestureRecognizer)

setupConstraints()
}
Expand Down Expand Up @@ -128,19 +127,19 @@ class BottomContainerView: UIView {
relatedBy: .Equal, toItem: self, attribute: .Right,
multiplier: 1, constant: -(UIScreen.mainScreen().bounds.width - (ButtonPicker.Dimensions.buttonBorderSize + UIScreen.mainScreen().bounds.width)/2)/2))

addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .Width,
addConstraint(NSLayoutConstraint(item: stackView, attribute: .Width,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ImageWrapper.Dimensions.imageSize))
multiplier: 1, constant: ImageStackView.Dimensions.imageSize))

addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .Height,
addConstraint(NSLayoutConstraint(item: stackView, attribute: .Height,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ImageWrapper.Dimensions.imageSize))
multiplier: 1, constant: ImageStackView.Dimensions.imageSize))

addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .CenterY,
addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterY,
relatedBy: .Equal, toItem: self, attribute: .CenterY,
multiplier: 1, constant: 0))

addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .CenterX,
addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterX,
relatedBy: .Equal, toItem: self, attribute: .Left,
multiplier: 1, constant: UIScreen.mainScreen().bounds.width/4 - ButtonPicker.Dimensions.buttonBorderSize/4))

Expand All @@ -165,53 +164,8 @@ class BottomContainerView: UIView {
}
}

func handleTapGestureRecognizer(gesture: UITapGestureRecognizer) {
delegate?.imageWrapperDidPress()
}

// MARK: - Wrapper methods

func updateWrapperImages(array: NSMutableArray) {
switch array.count {
case 1:
imageWrapper.firstImageView.image = array.firstObject as? UIImage
imageWrapper.secondImageView.image = nil
imageWrapper.secondImageView.alpha = 0
if pastCount < 1 {
animateImageView(imageWrapper.firstImageView)
}
case 0:
imageWrapper.firstImageView.image = nil
case 2:
imageWrapper.firstImageView.image = array[1] as? UIImage
imageWrapper.secondImageView.image = array.firstObject as? UIImage
imageWrapper.secondImageView.alpha = 1
imageWrapper.thirdImageView.alpha = 0
if pastCount < 2 {
animateImageView(imageWrapper.secondImageView)
}
case 3:
imageWrapper.firstImageView.image = array[2] as? UIImage
imageWrapper.secondImageView.image = array[1] as? UIImage
imageWrapper.thirdImageView.image = array.firstObject as? UIImage
imageWrapper.thirdImageView.alpha = 1
imageWrapper.fourthImageView.alpha = 0
if pastCount < 3 {
animateImageView(imageWrapper.thirdImageView)
}
default:
imageWrapper.fourthImageView.alpha = 1
imageWrapper.firstImageView.image = array.lastObject as? UIImage
imageWrapper.secondImageView.image = array[array.count - 2] as? UIImage
imageWrapper.thirdImageView.image = array[array.count - 3] as? UIImage
imageWrapper.fourthImageView.image = array[array.count - 4] as? UIImage
if pastCount < array.count {
animateImageView(imageWrapper.fourthImageView)
}
}

pastCount = array.count
pickerButton.photoNumber = array.count
func handleTapGestureRecognizer(recognizer: UITapGestureRecognizer) {
delegate?.imageStackViewDidPress()
}

private func animateImageView(imageView: UIImageView) {
Expand Down
43 changes: 32 additions & 11 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

protocol ButtonPickerDelegate {
protocol ButtonPickerDelegate: class {

func buttonDidPress()
}
Expand All @@ -25,15 +25,9 @@ class ButtonPicker: UIButton {
lazy var configuration: PickerConfiguration = {
let configuration = PickerConfiguration()
return configuration
}()

internal var photoNumber: Int = 0 {
didSet {
numberLabel.text = photoNumber == 0 ? "" : "\(photoNumber)"
}
}
}()

var delegate: ButtonPickerDelegate?
weak var delegate: ButtonPickerDelegate?

// MARK: - Initializers

Expand All @@ -42,12 +36,34 @@ class ButtonPicker: UIButton {

[numberLabel].map { self.addSubview($0) }

subscribe()
setupButton()
setupConstraints()
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}

func subscribe() {
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "recalculatePhotosCount:",
name: ImageStack.Notifications.imageDidPush,
object: nil)

NSNotificationCenter.defaultCenter().addObserver(self,
selector: "recalculatePhotosCount:",
name: ImageStack.Notifications.imageDidDrop,
object: nil)

NSNotificationCenter.defaultCenter().addObserver(self,
selector: "recalculatePhotosCount:",
name: ImageStack.Notifications.stackDidReload,
object: nil)
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
fatalError("init(coder:) has not been implemented")
}

// MARK: - Configuration
Expand All @@ -73,10 +89,15 @@ class ButtonPicker: UIButton {

// MARK: - Actions

func recalculatePhotosCount(notification: NSNotification) {
if let sender = notification.object as? ImageStack {
numberLabel.text = sender.images.isEmpty ? "" : String(sender.images.count)
}
}

func pickerButtonDidPress(button: UIButton) {
backgroundColor = .whiteColor()
numberLabel.textColor = .blackColor()
photoNumber = photoNumber + 1
numberLabel.sizeToFit()
delegate?.buttonDidPress()
}
Expand Down
32 changes: 32 additions & 0 deletions Source/BottomView/ImageStack.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import UIKit

public class ImageStack {

public struct Notifications {
public static let imageDidPush = "imageDidPush:"
public static let imageDidDrop = "imageDidDrop:"
public static let stackDidReload = "stackDidReload:"
public static let imageKey = "image"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange name of notification though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is key for UIImage in Dictionary. Decided to keep in notifications as it is the only place its being used.

}

public var images = [UIImage]()

public func pushImage(image: UIImage) {
images.append(image)
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.imageDidPush, object: self, userInfo: ["image" : image])
}

public func dropImage(image: UIImage) {
images = images.filter() {$0 != image}
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.imageDidDrop, object: self, userInfo: ["image" : image])
}

public func resetImages(newImages: [UIImage]) {
images = newImages
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.stackDidReload, object: self, userInfo: nil)
}

public func containsImage(image: UIImage) -> Bool {
return contains(images, image)
}
}
105 changes: 0 additions & 105 deletions Source/BottomView/ImageWrapper.swift

This file was deleted.

Loading