on bd01268 help sign in
11 files changed+33−181
since splitsnapshots
unifiedsplit
Melk.xcodeproj/project.pbxproj+1−1 Melk.xcodeproj/xcuserdata/ilya.xcuserdatad/xcschemes/Melk.xcscheme+3−3 Melk/CardView.swift+10−45 Melk/MainCoordinator.swift+2−8 Melk/MainViewController.swift+2−22 Melk/SecondaryCoordinator.swift−12 Melk/SecondaryViewController.swift+4−53 Melk/TableViewCells.swift+3−12 Melk/VKData.swift+7−7 Melk/VKServer.swift+1−1 README.md−17
Melk.xcodeproj/project.pbxproj+1−1
@@ -133,7 +133,6 @@
133133 children = (
134134 09BF420F1F0833C100AFAD57 /* MainCoordinator.swift */,
135135 09BF42551F08413000AFAD57 /* MainViewController.swift */,
136− 09939A551F097DA90014719D /* TableViewCells.swift */,
137136 );
138137 name = Main;
139138 sourceTree = "<group>";
@@ -193,6 +192,7 @@
193192 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
194193 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
195194 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 = "Release"
46− selectedDebuggerIdentifier = ""
47− selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
45+ buildConfiguration = "Debug"
46+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4848 launchStyle = "0"
4949 useCustomWorkingDirectory = "NO"
5050 ignoresPersistentStateOnLaunch = "NO"
Melk/CardView.swift+10−45
@@ -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,32 +31,17 @@ class CardView: UIView {
3131 super.init(frame: frame)
3232 layer.masksToBounds = true
3333 layer.cornerRadius = 20
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)
34+ backgroundColor = #colorLiteral(red: 0.9638966278, green: 0.9734401588, blue: 0.9734401588, alpha: 1)
3935 }
4036
4137 required init?(coder aDecoder: NSCoder) {
4238 fatalError("init(coder:) has not been implemented")
4339 }
44−
45− private let gradient = CAGradientLayer()
46−
4740
4841 private let padding = CGPoint(x: 32, y: 32)
4942 private let vPadding1: CGFloat = 16
5043 private let vPadding2: CGFloat = 16
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− }
44+ private let minTextHeight: CGFloat = 50
6045
6146// private let avatar = UIImage()
6247// private let name = UIImage()
@@ -69,9 +54,10 @@ class CardView: UIView {
6954 addSubview(largeStack)
7055
7156 let userView = StackView(axis: .horizontal, alignment: .center)
57+// userView.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
7258
7359
74− let avatarDim: CGFloat = 64
60+ let avatarDim: CGFloat = 50
7561 let avatar = UIImageView()
7662 post?.owner?.avatar?.load(into: avatar)
7763 avatar.layer.cornerRadius = avatarDim/2
@@ -88,7 +74,6 @@ class CardView: UIView {
8874 let lastName = post?.owner?.lastName ?? ""
8975 userName.text = "\(firstName) \(lastName)"
9076 userName.font = UIFont.systemFont(ofSize: 28, weight: UIFontWeightHeavy)
91− userName.textColor = UIColor.darkText
9277 userName.sizeToFit()
9378 userView.addArrangedSubview(.view(userName))
9479
@@ -108,7 +93,7 @@ class CardView: UIView {
10893 photoView.verticalPadding = 8
10994 photoView.padding = CGPoint.zero
11095 photoView.maxWidth = width
111− var maxPhotoDim: CGFloat = maxAttachmentDim
96+ var maxPhotoDim: CGFloat = 150
11297 if let attachments = post?.attachments {
11398 for attachment in attachments {
11499 if let v = attachment.value {
@@ -118,7 +103,6 @@ class CardView: UIView {
118103 var pHeight = photo.height.value >>> {CGFloat($0)} {
119104 let photoV = UIImageView()
120105 photoV.layer.minificationFilter = kCAFilterTrilinear
121− photoV.contentMode = .scaleAspectFill
122106 photo.image?.load(into: photoV)
123107 var k: CGFloat!
124108 if pWidth > pHeight {
@@ -141,10 +125,10 @@ class CardView: UIView {
141125 photoView.layoutIfNeeded()
142126
143127 var textHeight = height
144− textHeight -= padding.y * 2 + vPadding1 + userView.frame.height
128+ textHeight -= padding.y + vPadding1 + userView.frame.height
145129 if let count = post?.attachments.count{
146130 if count > 0 {
147− textHeight -= vPadding2 + photoView.frame.height
131+ textHeight -= vPadding2 + photoView.frame.height + padding.y
148132 }
149133 }
150134 print(textHeight)
@@ -156,25 +140,9 @@ class CardView: UIView {
156140 let bodyWidth: Double = Double(width)
157141 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
158142 body.text = post?.body
159− body.textColor = UIColor.darkText
160143 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)
161145 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− }
178146
179147 largeStack.addArrangedSubview(.view(body))
180148
@@ -189,8 +157,5 @@ class CardView: UIView {
189157
190158 frame.size = CGSize(width: width + padding.x * 2, height: min(height, largeStack.frame.height))
191159
192− gradient.frame = self.bounds
193− gradient.endPoint = CGPoint(x: 0.5, y: bounds.height / height)
194−
195160 }
196161}
Melk/MainCoordinator.swift+2−8
@@ -27,14 +27,6 @@ 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− }
3830 updateScreens()
3931 stream.handleResult = { result in
4032 self.secondaryCoord.add(result: result)
@@ -52,6 +44,8 @@ class MainCoordinator {
5244// }
5345 print("didAuthorize")
5446 window.rootViewController = navC
47+ stream.rules = ["я", "а", "и"]
48+ stream.connect()
5549 }
5650
5751 func updateScreens() {
Melk/MainViewController.swift+2−22
@@ -29,9 +29,7 @@ class MainViewController: UIViewController {
2929 }
3030
3131 @objc private func presentTags() {
32− present?(
33− mainView.tags.flatMap({$0}).filter({$0 != ""})
34− )
32+
3533 }
3634}
3735
@@ -47,8 +45,6 @@ class MainView: UIView {
4745 tableView.rowHeight = UITableViewAutomaticDimension
4846 tableView.register(TitleTableViewCell.self, forCellReuseIdentifier: TitleTableViewCell.identifier)
4947 tableView.register(TagTableViewCell.self, forCellReuseIdentifier: TagTableViewCell.identifier)
50− tableView.separatorStyle = .none
51− tableView.allowsSelection = false
5248 setNeedsLayout()
5349 }
5450
@@ -56,17 +52,6 @@ class MainView: UIView {
5652 tableView.frame = bounds
5753 }
5854
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−
7055 required init?(coder aDecoder: NSCoder) {
7156 fatalError("init(coder:) has not been implemented")
7257 }
@@ -77,18 +62,13 @@ extension MainView: UITableViewDataSource {
7762 if let cell = tableView.dequeueReusableCell(withIdentifier: TagTableViewCell.identifier) as? TagTableViewCell {
7863// cell.titleText = "Testing testing 1 2 3"
7964 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]
8565 return cell
8666 }
8767 return UITableViewCell()
8868 }
8969
9070 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
91− return tags.count
71+ return 3
9272 }
9373
9474 func numberOfSections(in tableView: UITableView) -> Int {
Melk/SecondaryCoordinator.swift−12
@@ -12,21 +12,12 @@ class SecondaryCoordinator {
1212
1313 var windows: [UIWindow] = []
1414
15− private var didStartPresenting = false
16− private var tag: String = ""
17−
1815 func add(result: StreamingServiceResult) {
1916 for vc in VCs {
2017 vc.add(result: result)
2118 }
2219 }
2320
24− func present(tag newTag: String) {
25− didStartPresenting = true
26− self.tag = newTag
27− VCs.map({ $0.present(tag: newTag) })
28− }
29−
3021 init() {
3122
3223 }
@@ -45,9 +36,6 @@ class SecondaryCoordinator {
4536 VCs.append(VC)
4637 window.rootViewController = VC
4738 windows.append(window)
48− if didStartPresenting {
49− VC.present(tag: tag)
50− }
5139 }
5240 }
5341}
Melk/SecondaryViewController.swift+4−53
@@ -19,10 +19,6 @@ class SecondaryViewController: UIViewController {
1919 sView.add(result: result)
2020 }
2121
22− func present(tag: String) {
23− sView.present(tag: tag)
24− }
25−
2622 required init?(coder aDecoder: NSCoder) {
2723 fatalError("init(coder:) has not been implemented")
2824 }
@@ -32,38 +28,13 @@ class SecondaryViewController: UIViewController {
3228
3329class SecondaryView: UIView {
3430
35− var mainTag: String? {
36− get {
37− return tagLabel.text
38− }
39− set {
40− tagLabel.text = newValue
41−
42− }
43− }
44−
4531
4632 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− }
6033
6134 func add(result: StreamingServiceResult) {
6235 switch result {
6336 case .post(let post):
6437 let card = CardContainer()
65− card.minWidth = min(bounds.width / 2.3, 550)
66− card.height = cardHeight
6738 card.post = post
6839 cards.addArrangedSubview(.spacer(spacer))
6940 cards.addArrangedSubview(.view(card))
@@ -80,15 +51,6 @@ class SecondaryView: UIView {
8051 super.init(frame: frame)
8152 backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
8253 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)
9254 }
9355
9456 func setNeedsLayout(animated: Bool) {
@@ -102,7 +64,6 @@ class SecondaryView: UIView {
10264 private var animate: Bool = false
10365
10466 private func cleanCards() {
105− var offset = 0
10667 outLoop: for (i, element) in cards.arrangedSubviews.enumerated() {
10768 switch element {
10869 case .view(let card):
@@ -110,9 +71,8 @@ class SecondaryView: UIView {
11071 if cardFrame.intersects(bounds) {
11172 break outLoop
11273 } else {
113− cards.arrangedSubviews.remove(at: i-1-offset)
114− cards.arrangedSubviews.remove(at: i-1-offset)
115− offset += 2
74+ cards.arrangedSubviews.remove(at: i-1)
75+ cards.arrangedSubviews.remove(at: i-1)
11676 }
11777 case .spacer(_):
11878 break
@@ -120,21 +80,13 @@ class SecondaryView: UIView {
12080 }
12181 }
12282
123− private let padding = CGPoint(x: 32, y: 16)
124− private var cardHeight: CGFloat = 400
83+ private let padding = CGPoint(x: 32, y: 32)
12584
12685 override func layoutSubviews() {
12786 super.layoutSubviews()
128−
129− melkLabel.sizeToFit()
130− melkLabel.center = center
131−
13287 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
13788 self.cards.layoutIfNeeded()
89+ self.cards.frame.origin.y = self.padding.y
13890 self.cards.frame.origin.x = self.frame.width - self.padding.x - self.cards.frame.width
13991 }
14092 if animate {
@@ -146,7 +98,6 @@ class SecondaryView: UIView {
14698 updates()
14799 self.cleanCards()
148100 }
149− cardHeight = bounds.height - tagLabel.frame.height - padding.y - tagSpacer - bottomSpacer
150101 animate = false
151102 }
152103
Melk/TableViewCells.swift+3−12
@@ -57,12 +57,6 @@ class TagTableViewCell: UITableViewCell {
5757 }
5858 }
5959
60− var tagDidChange: ((String?) -> ())?
61−
62− @objc private func textDidChange() {
63− tagDidChange?(tagString)
64− }
65−
6660 var style: TagStyle = .normal {
6761 didSet {
6862 updateStyle()
@@ -76,9 +70,6 @@ class TagTableViewCell: UITableViewCell {
7670
7771 textField.borderStyle = .roundedRect
7872 textField.adjustsFontSizeToFitWidth = false
79− textField.autocapitalizationType = .none
80− textField.autocorrectionType = .no
81− textField.addTarget(self, action: #selector(self.textDidChange), for: .editingChanged)
8273
8374 contentView.addSubview(textField)
8475// textField.delegate = self
@@ -101,7 +92,7 @@ class TagTableViewCell: UITableViewCell {
10192 CGRect.infinite, limitedToNumberOfLines: 1)
10293 .height + 2*2
10394
104− let frame = CGRect(x: 16, y: style == .large ? 32 : 4, width: bounds.width - 16*2, height: height)
95+ let frame = CGRect(x: 16, y: 8, width: bounds.width - 16*2, height: height)
10596 textField.frame = frame
10697 print(textField.frame)
10798 }
@@ -112,8 +103,8 @@ class TagTableViewCell: UITableViewCell {
112103
113104
114105 static let identifier = "io.Melk.tagTableViewCell"
115− static let largeHeight: CGFloat = 37.5 + 16 + 32
116− static let normalHeight: CGFloat = 28.0 + 4*2
106+ static let largeHeight: CGFloat = 37.5 + 8*2
107+ static let normalHeight: CGFloat = 28.0 + 8*2
117108}
118109
119110//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)&lang=0"
121+ let surl = "https://api.vk.com/method/\(method)?access_token=\(accessKey)&v=\(vkAPIVersion)"
122122 return URL.init(string: surl)!
123123}
README.mddeleted−17
@@ -1,17 +0,0 @@
1−# Melk
2−
3−_Might not work properly with new streaming API. This project was developed while the API was in beta._
4−
5−[![Melk demo](http://img.youtube.com/vi/9SNc0bLDCL0/0.jpg)](http://www.youtube.com/watch?v=9SNc0bLDCL0)
6−
7−При проведении различных мероприятий организаторы довольно часто призывают людей, посещающих эти мероприятия, выложить у себя в соц сети что-нибудь об этом мероприятии, чаще всего под мероприятие даже выделяется отдельный хештег.
8−
9−Для привлечения внимания к хештегу и поощрения его использования можно выводить некоторые из выложенных с хештегом записей туда, где все смогут это увидеть.
10−
11−При проведении больших мероприятий желательно использовать большое количество независимых систем, чтобы если летит что-то одно, все остальное продолжало работать.
12−
13−Полноценный десктопный компьютер для данной цели не нужен, поэтому приложение работает просто на телефоне или планшете.
14−
15−Самый первый хештег или ключевое слово будет крупно показано вместе со всеми записями.
16−
17−После того, как будет нажата кнопка “Present”, записи с основным хештегом будут выводиться на любые подключенные к устройству экраны.