on master help sign in
Seem to be done for submission
commitecf9e9f66bb267eb57adc0a2ef9c4306c243bf87 authorilyakooo0 <ilyakooo0@gmail.com> dateMon 24 Jul 2017, 16:29 (9 years ago) parentbd01268
10 files changed+164−33
Melk.xcodeproj/project.pbxproj+1−1 Melk.xcodeproj/xcuserdata/ilya.xcuserdatad/xcschemes/Melk.xcscheme+3−3 Melk/CardView.swift+45−10 Melk/MainCoordinator.swift+8−2 Melk/MainViewController.swift+22−2 Melk/SecondaryCoordinator.swift+12 Melk/SecondaryViewController.swift+53−4 Melk/TableViewCells.swift+12−3 Melk/VKData.swift+7−7 Melk/VKServer.swift+1−1
Melk.xcodeproj/project.pbxproj+1−1
@@ -133,6 +133,7 @@
133133 children = (
134134 09BF420F1F0833C100AFAD57 /* MainCoordinator.swift */,
135135 09BF42551F08413000AFAD57 /* MainViewController.swift */,
136+ 09939A551F097DA90014719D /* TableViewCells.swift */,
136137 );
137138 name = Main;
138139 sourceTree = "<group>";
@@ -192,7 +193,6 @@
192193 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
193194 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
194195 09F03F351F1674ED000CE916 /* VKServer.swift */,
195− 09939A551F097DA90014719D /* TableViewCells.swift */,
196196 09BF420D1F0833A700AFAD57 /* LocalVKDataTypes.swift */,
197197 09BF42151F0834D400AFAD57 /* VKPublicCrap.swift */,
198198 09BF42171F08352E00AFAD57 /* VKData.swift */,
Melk.xcodeproj/xcuserdata/ilya.xcuserdatad/xcschemes/Melk.xcscheme+3−3
@@ -42,9 +42,9 @@
4242 </AdditionalOptions>
4343 </TestAction>
4444 <LaunchAction
45− buildConfiguration = "Debug"
46− selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47− selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
45+ buildConfiguration = "Release"
46+ selectedDebuggerIdentifier = ""
47+ selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
4848 launchStyle = "0"
4949 useCustomWorkingDirectory = "NO"
5050 ignoresPersistentStateOnLaunch = "NO"
Melk/CardView.swift+45−10
@@ -18,12 +18,12 @@ class CardView: UIView {
1818 }
1919 var minWidth: CGFloat = 300 {
2020 didSet {
21− update()
21+// update()
2222 }
2323 }
2424 var height: CGFloat = 400 {
2525 didSet {
26− update()
26+// update()
2727 }
2828 }
2929
@@ -31,17 +31,32 @@ class CardView: UIView {
3131 super.init(frame: frame)
3232 layer.masksToBounds = true
3333 layer.cornerRadius = 20
34− backgroundColor = #colorLiteral(red: 0.9638966278, green: 0.9734401588, blue: 0.9734401588, alpha: 1)
34+ gradient.colors = [#colorLiteral(red: 0.9841352105, green: 0.9841352105, blue: 0.9841352105, alpha: 1).cgColor, #colorLiteral(red: 0.9456828237, green: 0.9456828237, blue: 0.9456828237, alpha: 1).cgColor]
35+ gradient.startPoint = CGPoint(x: 0.5, y: 0)
36+ gradient.endPoint = CGPoint(x: 0.5, y: 1)
37+ layer.addSublayer(gradient)
38+// backgroundColor = #colorLiteral(red: 0.9638966278, green: 0.9734401588, blue: 0.9734401588, alpha: 1)
3539 }
3640
3741 required init?(coder aDecoder: NSCoder) {
3842 fatalError("init(coder:) has not been implemented")
3943 }
44+
45+ private let gradient = CAGradientLayer()
46+
4047
4148 private let padding = CGPoint(x: 32, y: 32)
4249 private let vPadding1: CGFloat = 16
4350 private let vPadding2: CGFloat = 16
44− private let minTextHeight: CGFloat = 50
51+ private var minTextHeight: CGFloat {
52+ return CGFloat(height * 0.2)
53+ }
54+ private let gradientRatio: CGFloat = 0.2
55+ private let minGradientAmount: CGFloat = 70
56+ private let hiddenByGradient: CGFloat = 10
57+ private var maxAttachmentDim: CGFloat {
58+ return minWidth / 2.3
59+ }
4560
4661// private let avatar = UIImage()
4762// private let name = UIImage()
@@ -54,10 +69,9 @@ class CardView: UIView {
5469 addSubview(largeStack)
5570
5671 let userView = StackView(axis: .horizontal, alignment: .center)
57−// userView.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
5872
5973
60− let avatarDim: CGFloat = 50
74+ let avatarDim: CGFloat = 64
6175 let avatar = UIImageView()
6276 post?.owner?.avatar?.load(into: avatar)
6377 avatar.layer.cornerRadius = avatarDim/2
@@ -74,6 +88,7 @@ class CardView: UIView {
7488 let lastName = post?.owner?.lastName ?? ""
7589 userName.text = "\(firstName) \(lastName)"
7690 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
91+ userName.textColor = UIColor.darkText
7792 userName.sizeToFit()
7893 userView.addArrangedSubview(.view(userName))
7994
@@ -93,7 +108,7 @@ class CardView: UIView {
93108 photoView.verticalPadding = 8
94109 photoView.padding = CGPoint.zero
95110 photoView.maxWidth = width
96− var maxPhotoDim: CGFloat = 150
111+ var maxPhotoDim: CGFloat = maxAttachmentDim
97112 if let attachments = post?.attachments {
98113 for attachment in attachments {
99114 if let v = attachment.value {
@@ -103,6 +118,7 @@ class CardView: UIView {
103118 var pHeight = photo.height.value >>> {CGFloat($0)} {
104119 let photoV = UIImageView()
105120 photoV.layer.minificationFilter = kCAFilterTrilinear
121+ photoV.contentMode = .scaleAspectFill
106122 photo.image?.load(into: photoV)
107123 var k: CGFloat!
108124 if pWidth > pHeight {
@@ -125,10 +141,10 @@ class CardView: UIView {
125141 photoView.layoutIfNeeded()
126142
127143 var textHeight = height
128− textHeight -= padding.y + vPadding1 + userView.frame.height
144+ textHeight -= padding.y * 2 + vPadding1 + userView.frame.height
129145 if let count = post?.attachments.count{
130146 if count > 0 {
131− textHeight -= vPadding2 + photoView.frame.height + padding.y
147+ textHeight -= vPadding2 + photoView.frame.height
132148 }
133149 }
134150 print(textHeight)
@@ -140,9 +156,25 @@ class CardView: UIView {
140156 let bodyWidth: Double = Double(width)
141157 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
142158 body.text = post?.body
159+ body.textColor = UIColor.darkText
143160 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
144− body.frame.size.height = min(size.height, textHeight)
145161 body.frame.size.width = size.width
162+ if size.height > textHeight {
163+ body.frame.size.height = textHeight
164+ let maskView = UIView()
165+ let maskLayer = CAGradientLayer()
166+ maskLayer.colors = [UIColor.black.cgColor, UIColor.clear.cgColor]
167+ maskLayer.endPoint = CGPoint(x: 0.5, y: 1 - (hiddenByGradient/textHeight))
168+ let minPoint = minGradientAmount / textHeight
169+ maskLayer.startPoint = CGPoint(x: 0.5, y: 1 - max(minPoint, gradientRatio))
170+ print(maskLayer.startPoint)
171+ maskLayer.frame = body.bounds
172+ maskView.frame = body.bounds
173+ maskView.layer.addSublayer(maskLayer)
174+ body.mask = maskView
175+ } else {
176+ body.frame.size.height = size.height
177+ }
146178
147179 largeStack.addArrangedSubview(.view(body))
148180
@@ -157,5 +189,8 @@ class CardView: UIView {
157189
158190 frame.size = CGSize(width: width + padding.x * 2, height: min(height, largeStack.frame.height))
159191
192+ gradient.frame = self.bounds
193+ gradient.endPoint = CGPoint(x: 0.5, y: bounds.height / height)
194+
160195 }
161196}
Melk/MainCoordinator.swift+8−2
@@ -27,6 +27,14 @@ class MainCoordinator {
2727 deleteRealmIfMigrationNeeded: true)
2828
2929 navC = UINavigationController(rootViewController: mainVC)
30+
31+ mainVC.present = { tags in
32+ if tags.count > 0 {
33+ self.secondaryCoord.present(tag: tags.first!)
34+ self.stream.rules = tags
35+ self.stream.connect()
36+ }
37+ }
3038 updateScreens()
3139 stream.handleResult = { result in
3240 self.secondaryCoord.add(result: result)
@@ -44,8 +52,6 @@ class MainCoordinator {
4452// }
4553 print("didAuthorize")
4654 window.rootViewController = navC
47− stream.rules = ["я", "а", "и"]
48− stream.connect()
4955 }
5056
5157 func updateScreens() {
Melk/MainViewController.swift+22−2
@@ -29,7 +29,9 @@ class MainViewController: UIViewController {
2929 }
3030
3131 @objc private func presentTags() {
32−
32+ present?(
33+ mainView.tags.flatMap({$0}).filter({$0 != ""})
34+ )
3335 }
3436}
3537
@@ -45,6 +47,8 @@ class MainView: UIView {
4547 tableView.rowHeight = UITableViewAutomaticDimension
4648 tableView.register(TitleTableViewCell.self, forCellReuseIdentifier: TitleTableViewCell.identifier)
4749 tableView.register(TagTableViewCell.self, forCellReuseIdentifier: TagTableViewCell.identifier)
50+ tableView.separatorStyle = .none
51+ tableView.allowsSelection = false
4852 setNeedsLayout()
4953 }
5054
@@ -52,6 +56,17 @@ class MainView: UIView {
5256 tableView.frame = bounds
5357 }
5458
59+ fileprivate var tags: [String?] = [nil] {
60+ didSet {
61+ if tags.last! != nil && tags.last! != "" {
62+ if tags.count < 10 {
63+ tags.append(nil)
64+ tableView.insertRows(at: [IndexPath.init(row: tags.count - 1, section: 0)], with: .automatic)
65+ }
66+ }
67+ }
68+ }
69+
5570 required init?(coder aDecoder: NSCoder) {
5671 fatalError("init(coder:) has not been implemented")
5772 }
@@ -62,13 +77,18 @@ extension MainView: UITableViewDataSource {
6277 if let cell = tableView.dequeueReusableCell(withIdentifier: TagTableViewCell.identifier) as? TagTableViewCell {
6378// cell.titleText = "Testing testing 1 2 3"
6479 cell.style = indexPath.item == 0 ? .large : .normal
80+ let index = indexPath.row
81+ cell.tagDidChange = { tag in
82+ self.tags[index] = tag
83+ }
84+ cell.tagString = tags[index]
6585 return cell
6686 }
6787 return UITableViewCell()
6888 }
6989
7090 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
71− return 3
91+ return tags.count
7292 }
7393
7494 func numberOfSections(in tableView: UITableView) -> Int {
Melk/SecondaryCoordinator.swift+12
@@ -12,12 +12,21 @@ class SecondaryCoordinator {
1212
1313 var windows: [UIWindow] = []
1414
15+ private var didStartPresenting = false
16+ private var tag: String = ""
17+
1518 func add(result: StreamingServiceResult) {
1619 for vc in VCs {
1720 vc.add(result: result)
1821 }
1922 }
2023
24+ func present(tag newTag: String) {
25+ didStartPresenting = true
26+ self.tag = newTag
27+ VCs.map({ $0.present(tag: newTag) })
28+ }
29+
2130 init() {
2231
2332 }
@@ -36,6 +45,9 @@ class SecondaryCoordinator {
3645 VCs.append(VC)
3746 window.rootViewController = VC
3847 windows.append(window)
48+ if didStartPresenting {
49+ VC.present(tag: tag)
50+ }
3951 }
4052 }
4153}
Melk/SecondaryViewController.swift+53−4
@@ -19,6 +19,10 @@ class SecondaryViewController: UIViewController {
1919 sView.add(result: result)
2020 }
2121
22+ func present(tag: String) {
23+ sView.present(tag: tag)
24+ }
25+
2226 required init?(coder aDecoder: NSCoder) {
2327 fatalError("init(coder:) has not been implemented")
2428 }
@@ -28,13 +32,38 @@ class SecondaryViewController: UIViewController {
2832
2933class SecondaryView: UIView {
3034
35+ var mainTag: String? {
36+ get {
37+ return tagLabel.text
38+ }
39+ set {
40+ tagLabel.text = newValue
41+
42+ }
43+ }
44+
3145
3246 private let spacer: CGFloat = 32
47+ private let bottomSpacer: CGFloat = 64
48+ private let tagSpacer: CGFloat = 32
49+ private let tagLabel = UILabel()
50+ private let melkLabel = UILabel()
51+
52+ func present(tag: String) {
53+ UIView.perform(.delete, on: [melkLabel], options: [], animations: nil) { (_) in
54+ self.melkLabel.removeFromSuperview()
55+ self.mainTag = tag
56+ self.tagLabel.sizeToFit()
57+ self.layoutIfNeeded(animated: true)
58+ }
59+ }
3360
3461 func add(result: StreamingServiceResult) {
3562 switch result {
3663 case .post(let post):
3764 let card = CardContainer()
65+ card.minWidth = min(bounds.width / 2.3, 550)
66+ card.height = cardHeight
3867 card.post = post
3968 cards.addArrangedSubview(.spacer(spacer))
4069 cards.addArrangedSubview(.view(card))
@@ -51,6 +80,15 @@ class SecondaryView: UIView {
5180 super.init(frame: frame)
5281 backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
5382 addSubview(cards)
83+
84+ melkLabel.text = "Melk"
85+ melkLabel.font = UIFont.systemFont(ofSize: 200, weight: UIFontWeightHeavy)
86+ melkLabel.textColor = #colorLiteral(red: 0.9601849914, green: 0.9601849914, blue: 0.9601849914, alpha: 1)
87+ addSubview(melkLabel)
88+
89+ tagLabel.font = UIFont.systemFont(ofSize: 69, weight: UIFontWeightBold)
90+ tagLabel.textColor = #colorLiteral(red: 0.3176470588, green: 0.3179988265, blue: 0.3179988265, alpha: 1)
91+ addSubview(tagLabel)
5492 }
5593
5694 func setNeedsLayout(animated: Bool) {
@@ -64,6 +102,7 @@ class SecondaryView: UIView {
64102 private var animate: Bool = false
65103
66104 private func cleanCards() {
105+ var offset = 0
67106 outLoop: for (i, element) in cards.arrangedSubviews.enumerated() {
68107 switch element {
69108 case .view(let card):
@@ -71,8 +110,9 @@ class SecondaryView: UIView {
71110 if cardFrame.intersects(bounds) {
72111 break outLoop
73112 } else {
74− cards.arrangedSubviews.remove(at: i-1)
75− cards.arrangedSubviews.remove(at: i-1)
113+ cards.arrangedSubviews.remove(at: i-1-offset)
114+ cards.arrangedSubviews.remove(at: i-1-offset)
115+ offset += 2
76116 }
77117 case .spacer(_):
78118 break
@@ -80,13 +120,21 @@ class SecondaryView: UIView {
80120 }
81121 }
82122
83− private let padding = CGPoint(x: 32, y: 32)
123+ private let padding = CGPoint(x: 32, y: 16)
124+ private var cardHeight: CGFloat = 400
84125
85126 override func layoutSubviews() {
86127 super.layoutSubviews()
128+
129+ melkLabel.sizeToFit()
130+ melkLabel.center = center
131+
87132 let updates = {
133+ self.tagLabel.sizeToFit()
134+ self.tagLabel.center.x = self.center.x
135+ self.tagLabel.frame.origin.y = self.tagSpacer
136+ self.cards.frame.origin.y = self.tagLabel.frame.maxY + self.padding.y
88137 self.cards.layoutIfNeeded()
89− self.cards.frame.origin.y = self.padding.y
90138 self.cards.frame.origin.x = self.frame.width - self.padding.x - self.cards.frame.width
91139 }
92140 if animate {
@@ -98,6 +146,7 @@ class SecondaryView: UIView {
98146 updates()
99147 self.cleanCards()
100148 }
149+ cardHeight = bounds.height - tagLabel.frame.height - padding.y - tagSpacer - bottomSpacer
101150 animate = false
102151 }
103152
Melk/TableViewCells.swift+12−3
@@ -57,6 +57,12 @@ class TagTableViewCell: UITableViewCell {
5757 }
5858 }
5959
60+ var tagDidChange: ((String?) -> ())?
61+
62+ @objc private func textDidChange() {
63+ tagDidChange?(tagString)
64+ }
65+
6066 var style: TagStyle = .normal {
6167 didSet {
6268 updateStyle()
@@ -70,6 +76,9 @@ class TagTableViewCell: UITableViewCell {
7076
7177 textField.borderStyle = .roundedRect
7278 textField.adjustsFontSizeToFitWidth = false
79+ textField.autocapitalizationType = .none
80+ textField.autocorrectionType = .no
81+ textField.addTarget(self, action: #selector(self.textDidChange), for: .editingChanged)
7382
7483 contentView.addSubview(textField)
7584// textField.delegate = self
@@ -92,7 +101,7 @@ class TagTableViewCell: UITableViewCell {
92101 CGRect.infinite, limitedToNumberOfLines: 1)
93102 .height + 2*2
94103
95− let frame = CGRect(x: 16, y: 8, width: bounds.width - 16*2, height: height)
104+ let frame = CGRect(x: 16, y: style == .large ? 32 : 4, width: bounds.width - 16*2, height: height)
96105 textField.frame = frame
97106 print(textField.frame)
98107 }
@@ -103,8 +112,8 @@ class TagTableViewCell: UITableViewCell {
103112
104113
105114 static let identifier = "io.Melk.tagTableViewCell"
106− static let largeHeight: CGFloat = 37.5 + 8*2
107− static let normalHeight: CGFloat = 28.0 + 8*2
115+ static let largeHeight: CGFloat = 37.5 + 16 + 32
116+ static let normalHeight: CGFloat = 28.0 + 4*2
108117}
109118
110119//extension TagTableViewCell: UITextFieldDelegate {
Melk/VKData.swift+7−7
@@ -289,13 +289,13 @@ class VKData {
289289 photo.width.value = json["width"].int
290290 photo.height.value = json["height"].int
291291 var surl: String?
292− if let imageSurl = json["photo_2560"].string {
293− surl = imageSurl
294− } else if let imageSurl = json["photo_1280"].string {
295− surl = imageSurl
296− } else if let imageSurl = json["photo_807"].string {
297− surl = imageSurl
298− } else if let imageSurl = json["photo_604"].string {
292+// if let imageSurl = json["photo_2560"].string {
293+// surl = imageSurl
294+// } else if let imageSurl = json["photo_1280"].string {
295+// surl = imageSurl
296+// } else if let imageSurl = json["photo_807"].string {
297+// surl = imageSurl
298+ /*} else*/ if let imageSurl = json["photo_604"].string {
299299 surl = imageSurl
300300 } else if let imageSurl = json["photo_130"].string {
301301 surl = imageSurl
Melk/VKServer.swift+1−1
@@ -118,6 +118,6 @@ class VKServer {
118118}
119119
120120fileprivate func url(`for` method: String) -> URL {
121− let surl = "https://api.vk.com/method/\(method)?access_token=\(accessKey)&v=\(vkAPIVersion)"
121+ let surl = "https://api.vk.com/method/\(method)?access_token=\(accessKey)&v=\(vkAPIVersion)&lang=0"
122122 return URL.init(string: surl)!
123123}