-
Notifications
You must be signed in to change notification settings - Fork 677
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
Refactor #13
Changes from 66 commits
3265bbe
c62606e
d5e43e3
1c14032
cfbf8fb
bf514e0
d00b669
c231179
b0a252e
d26d087
c2be320
24bba2e
3af3d1e
24af5c8
094bdf9
4f0de9e
c64a720
7d1b645
622c719
ab44a32
070efcd
e512178
ff32539
ca040fa
a8ef893
75552f7
1afb0d3
62104dd
5ea7743
d9186a6
b2f2990
d1a5cc3
eb8f80c
35b09b1
aafbee9
3f2ad44
4707d74
6892ca7
9767f45
8f6743d
d0c175a
5492b09
65e7133
a576b4c
006457b
6b6d7c2
c4675a5
7411f83
b87bf7b
b800bc5
5356ec7
a14ecd5
3a3778b
623daf8
eea9fd9
d3688c2
50c624a
d7f5ca4
b95a87d
d1f4913
ca73037
8bde548
d403ff7
1148868
6490e0c
72955c7
4f80265
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,13 +25,7 @@ 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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, very important fix, as previous one. |
||
|
||
|
@@ -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.imageDidPushNotification, | ||
object: nil) | ||
|
||
NSNotificationCenter.defaultCenter().addObserver(self, | ||
selector: "recalculatePhotosCount:", | ||
name: ImageStack.Notifications.imageDidDropNotification, | ||
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 | ||
|
@@ -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() | ||
} | ||
|
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 imageDidPushNotification = "imageDidPush:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
public static let imageDidDropNotification = "imageDidDrop:" | ||
public static let stackDidReload = "stackDidReload:" | ||
public static let imageKey = "image" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange name of notification though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is |
||
} | ||
|
||
public var images: [UIImage] = [UIImage]() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
|
||
public func pushImage(image: UIImage) { | ||
images.append(image) | ||
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.imageDidPushNotification, object: self, userInfo: ["image" : image]) | ||
} | ||
|
||
public func dropImage(image: UIImage) { | ||
images = images.filter() {$0 != image} | ||
NSNotificationCenter.defaultCenter().postNotificationName(Notifications.imageDidDropNotification, 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) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a new line here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I've tried. Git does not want to see newline, so I wasn't able to commit. Plugins installation bug? |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have here two spaces, isn't it? Could you try to drop self?