From 2f91499355fd0fbc441745621712b0953760a3b8 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 08:59:56 +0800 Subject: [PATCH 01/32] update pods --- Podfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 84adb222..636737e6 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -13,7 +13,7 @@ PODS: - FXBlurView (1.6.4) - JPush-iOS-SDK (1.8.8) - KeyboardMan (0.5.2) - - Kingfisher (1.9.0) + - Kingfisher (1.9.1) - MonkeyKing (0.0.2) - MZFayeClient (1.0.1): - Base64 (~> 1.0.1) @@ -67,7 +67,7 @@ SPEC CHECKSUMS: FXBlurView: db786c2561cb49a09ae98407f52460096ab8a44f JPush-iOS-SDK: d4c097d8abbdd0837e24d44b41aacf64a6feddfd KeyboardMan: b081c254c5c0adc794a49b4e97a86cb4ac917a66 - Kingfisher: 163bafc1af6ae14d707e76ecba256d8db99dc955 + Kingfisher: 98fedd5d44d982b331fc7303f9f6144b7d8ba289 MonkeyKing: 9be24307843a80f4cd3eca66adc12c67aefb83bb MZFayeClient: 65e7ef67e61fbe7a7a8b196130541c9f06bcb5d8 Navi: 24f5c81aeb46b89d27168ec1d459581230ae2675 From 680404a1f58405edfd3a4007d6b25a2b836efdde Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 09:33:36 +0800 Subject: [PATCH 02/32] add UploadingFeed Section in Feeds --- .../Feeds/FeedsViewController.swift | 132 ++++++++++++------ 1 file changed, 86 insertions(+), 46 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index f68e1e84..60d581f8 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -835,38 +835,50 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { private enum Section: Int { case SkillUsers + case UploadingFeed case Feed case LoadMore } func numberOfSectionsInTableView(tableView: UITableView) -> Int { - return 3 + return 4 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - switch section { - case Section.SkillUsers.rawValue: - return (skill == nil) ? 0 : 1 - case Section.Feed.rawValue: - return feeds.count - case Section.LoadMore.rawValue: - return feeds.isEmpty ? 0 : 1 - default: + guard let section = Section(rawValue: section) else { return 0 } + + switch section { + case .SkillUsers: + return (skill == nil) ? 0 : 1 + case .UploadingFeed: + return 1 + case .Feed: + return feeds.count + case .LoadMore: + return feeds.isEmpty ? 0 : 1 + } } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - switch indexPath.section { + guard let section = Section(rawValue: indexPath.section) else { + return UITableViewCell() + } - case Section.SkillUsers.rawValue: + switch section { + + case .SkillUsers: let cell = tableView.dequeueReusableCellWithIdentifier(feedSkillUsersCellID) as! FeedSkillUsersCell return cell - case Section.Feed.rawValue: + case .UploadingFeed: + return UITableViewCell() + + case .Feed: let feed = feeds[indexPath.row] switch feed.kind { @@ -910,20 +922,21 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return cell } - case Section.LoadMore.rawValue: + case .LoadMore: let cell = tableView.dequeueReusableCellWithIdentifier(loadMoreTableViewCellID) as! LoadMoreTableViewCell return cell - - default: - return UITableViewCell() } } func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { - switch indexPath.section { + guard let section = Section(rawValue: indexPath.section) else { + return + } - case Section.SkillUsers.rawValue: + switch section { + + case .SkillUsers: guard let cell = cell as? FeedSkillUsersCell else { break @@ -931,7 +944,10 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.configureWithFeeds(feeds) - case Section.Feed.rawValue: + case .UploadingFeed: + break + + case .Feed: let feed = feeds[indexPath.row] @@ -1191,7 +1207,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { break } - case Section.LoadMore.rawValue: + case .LoadMore: guard let cell = cell as? LoadMoreTableViewCell else { break @@ -1206,28 +1222,29 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { updateFeeds(mode: .LoadMore, finish: { [weak cell] in cell?.loadingActivityIndicator.stopAnimating() }) - - default: - break } } func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - switch indexPath.section { + guard let section = Section(rawValue: indexPath.section) else { + return 0 + } - case Section.SkillUsers.rawValue: + switch section { + + case .SkillUsers: return 70 - case Section.Feed.rawValue: + case .UploadingFeed: + return 100 + + case .Feed: let feed = feeds[indexPath.row] return FeedsViewController.layoutPool.heightOfFeed(feed) - case Section.LoadMore.rawValue: + case .LoadMore: return 60 - - default: - return 0 } } @@ -1241,15 +1258,22 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { tableView.deselectRowAtIndexPath(indexPath, animated: true) } - switch indexPath.section { + guard let section = Section(rawValue: indexPath.section) else { + return + } - case Section.SkillUsers.rawValue: + switch section { + + case .SkillUsers: performSegueWithIdentifier("showSkillHome", sender: nil) - case Section.Feed.rawValue: + case .UploadingFeed: + break + + case .Feed: performSegueWithIdentifier("showConversation", sender: indexPath) - default: + case .LoadMore: break } } @@ -1258,12 +1282,19 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { - switch indexPath.section { + guard let section = Section(rawValue: indexPath.section) else { + return false + } - case Section.SkillUsers.rawValue: + switch section { + + case .SkillUsers: return false - case Section.Feed.rawValue: + case .UploadingFeed: + return false + + case .Feed: let feed = feeds[indexPath.item] if feed.creator.id == YepUserDefaults.userID.value { return false @@ -1271,23 +1302,32 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return true } - default: + case .LoadMore: return false } } func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { - let reportAction = UITableViewRowAction(style: .Default, title: NSLocalizedString("Report", comment: "")) { [weak self] action, indexPath in - - if let feed = self?.feeds[indexPath.row] { - self?.report(.Feed(feed)) - } - - tableView.setEditing(false, animated: true) + guard let section = Section(rawValue: indexPath.section) else { + return nil } - return [reportAction] + if case .Feed = section { + + let reportAction = UITableViewRowAction(style: .Default, title: NSLocalizedString("Report", comment: "")) { [weak self] action, indexPath in + + if let feed = self?.feeds[indexPath.row] { + self?.report(.Feed(feed)) + } + + tableView.setEditing(false, animated: true) + } + + return [reportAction] + } + + return nil } func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { From 840c83910af64a06e7ec41855ee044ece8cf3fdf Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 10:41:21 +0800 Subject: [PATCH 03/32] add ModelTypes, maybe... --- Yep.xcodeproj/project.pbxproj | 12 +++++++++++ Yep/Protocols/ModelTypes.swift | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Yep/Protocols/ModelTypes.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index e6eccd71..4c3b2e3f 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -327,6 +327,7 @@ 50F5AF961BBBCDA30033C9BC /* FeedMediaAddCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */; }; 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; 50F5AF9A1BBBD02A0033C9BC /* FeedMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */; }; + 50F6D32A1C3B618200CB673C /* ModelTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F6D3291C3B618200CB673C /* ModelTypes.swift */; }; 50FA9A441B661698009BF2A0 /* UIViewController+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */; }; 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */; }; 50FD753F1C20FF8D0050A382 /* FeedMediaContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753E1C20FF8D0050A382 /* FeedMediaContainerView.swift */; }; @@ -696,6 +697,7 @@ 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaAddCell.xib; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.xib; sourceTree = ""; }; 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaCell.xib; path = Views/Cells/FeedMedia/FeedMediaCell.xib; sourceTree = ""; }; + 50F6D3291C3B618200CB673C /* ModelTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ModelTypes.swift; path = Protocols/ModelTypes.swift; sourceTree = ""; }; 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIViewController+Yep.swift"; path = "Extensions/UIViewController+Yep.swift"; sourceTree = ""; }; 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FPSLabel.swift; path = Views/Labels/FPSLabel.swift; sourceTree = ""; }; 50FD753E1C20FF8D0050A382 /* FeedMediaContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaContainerView.swift; path = Views/ContainerViews/FeedMediaContainerView.swift; sourceTree = ""; }; @@ -826,6 +828,7 @@ 0AD7EA581AC3EAF300617758 /* Yep-Bridging-Header.h */, 50AFBF4F1BB3A5A1007D19DA /* Sounds */, 50E114F51ABBF9D100F13000 /* Realm */, + 50F6D3281C3B5FDB00CB673C /* Protocols */, 502AE53B1AB871C5005BD199 /* Helpers */, 502AE52C1AB819B5005BD199 /* Configs */, 502AE5251AB72BE9005BD199 /* Services */, @@ -2198,6 +2201,14 @@ name = FeedMedia; sourceTree = ""; }; + 50F6D3281C3B5FDB00CB673C /* Protocols */ = { + isa = PBXGroup; + children = ( + 50F6D3291C3B618200CB673C /* ModelTypes.swift */, + ); + name = Protocols; + sourceTree = ""; + }; 50FD75401C20FF940050A382 /* ContainerViews */ = { isa = PBXGroup; children = ( @@ -2752,6 +2763,7 @@ 50E1CE8E1BE0BFF00025B933 /* MediaViewCell.swift in Sources */, 50DEE0311BE339B000015741 /* LoadMoreTableViewCell.swift in Sources */, 50DEE0361BE3720F00015741 /* LoadMoreCollectionViewCell.swift in Sources */, + 50F6D32A1C3B618200CB673C /* ModelTypes.swift in Sources */, 504F41251ACE2D1D00FBB19A /* SampleView.swift in Sources */, 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */, 50A640EC1B6F4E420050E4A3 /* DoNotDisturbPeriodViewController.swift in Sources */, diff --git a/Yep/Protocols/ModelTypes.swift b/Yep/Protocols/ModelTypes.swift new file mode 100644 index 00000000..5c93eb31 --- /dev/null +++ b/Yep/Protocols/ModelTypes.swift @@ -0,0 +1,39 @@ +// +// ModelTypes.swift +// Yep +// +// Created by nixzhu on 16/1/5. +// Copyright © 2016年 Catch Inc. All rights reserved. +// + +import Foundation + +protocol UserType { + + var userID: String { get } + var username: String? { get } + var nickname: String { get } + var introduction: String { get } + var avatarURLString: String { get } + var badge: String? { get } + + var createdUnixTime: NSTimeInterval { get } + var lastSignInUnixTime: NSTimeInterval { get } + + var longitude: Double { get } + var latitude: Double { get } + + +} + +protocol FeedType { + + var feedID: String { get } + var allowComment: Bool { get } + var kind: FeedKind? { get } + + var createdUnixTime: NSTimeInterval { get } + var updatedUnixTime: NSTimeInterval { get } + + var creator: UserType? { get } +} \ No newline at end of file From c4f7f7dd9f6d4cc8dd47ee0e2d03960dba016c65 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 11:08:06 +0800 Subject: [PATCH 04/32] uploadingFeeds in Feeds --- .../Feeds/FeedsViewController.swift | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 60d581f8..07d08b86 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -23,6 +23,7 @@ class FeedsViewController: BaseViewController { var hideRightBarItem: Bool = false + var uploadingFeeds = [DiscoveredFeed]() var feeds = [DiscoveredFeed]() @IBOutlet weak var feedsTableView: UITableView! @@ -855,7 +856,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { case .SkillUsers: return (skill == nil) ? 0 : 1 case .UploadingFeed: - return 1 + return uploadingFeeds.count case .Feed: return feeds.count case .LoadMore: @@ -869,17 +870,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return UITableViewCell() } - switch section { - - case .SkillUsers: - let cell = tableView.dequeueReusableCellWithIdentifier(feedSkillUsersCellID) as! FeedSkillUsersCell - return cell - - case .UploadingFeed: - return UITableViewCell() - - case .Feed: - let feed = feeds[indexPath.row] + func cellForFeed(feed: DiscoveredFeed) -> UITableViewCell { switch feed.kind { @@ -921,8 +912,27 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let cell = tableView.dequeueReusableCellWithIdentifier(feedBasicCellID) as! FeedBasicCell return cell } + } + + switch section { + + case .SkillUsers: + + let cell = tableView.dequeueReusableCellWithIdentifier(feedSkillUsersCellID) as! FeedSkillUsersCell + return cell + + case .UploadingFeed: + + let feed = uploadingFeeds[indexPath.row] + return cellForFeed(feed) + + case .Feed: + + let feed = feeds[indexPath.row] + return cellForFeed(feed) case .LoadMore: + let cell = tableView.dequeueReusableCellWithIdentifier(loadMoreTableViewCellID) as! LoadMoreTableViewCell return cell } @@ -934,25 +944,10 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return } - switch section { - - case .SkillUsers: - - guard let cell = cell as? FeedSkillUsersCell else { - break - } - - cell.configureWithFeeds(feeds) - - case .UploadingFeed: - break - - case .Feed: - - let feed = feeds[indexPath.row] + func configureFeedCell(cell: UITableViewCell, withFeed feed: DiscoveredFeed) { guard let cell = cell as? FeedBasicCell else { - break + return } cell.tapAvatarAction = { [weak self] cell in @@ -1206,6 +1201,27 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { default: break } + } + + switch section { + + case .SkillUsers: + + guard let cell = cell as? FeedSkillUsersCell else { + break + } + + cell.configureWithFeeds(feeds) + + case .UploadingFeed: + + let feed = uploadingFeeds[indexPath.row] + configureFeedCell(cell, withFeed: feed) + + case .Feed: + + let feed = feeds[indexPath.row] + configureFeedCell(cell, withFeed: feed) case .LoadMore: From 2fe398dbca2851988f05fdf91baf4b97520f9bdb Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 13:40:14 +0800 Subject: [PATCH 05/32] tryMakeUploadingFeed beforeUploadingFeedAction --- Yep/Services/YepService.swift | 5 ++ .../Feeds/FeedsViewController.swift | 15 ++++++ .../NewFeed/NewFeedViewController.swift | 47 +++++++++++++++++-- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 76e1ab7d..c90ebf16 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -1276,6 +1276,11 @@ struct DiscoveredUser: Hashable { return false } + + static func fromUser(user: User) -> DiscoveredUser { + + return DiscoveredUser(id: user.userID, username: user.username, nickname: user.nickname, introduction: user.introduction, avatarURLString: user.avatarURLString, badge: user.badge, createdUnixTime: user.createdUnixTime, lastSignInUnixTime: user.lastSignInUnixTime, longitude: user.longitude, latitude: user.latitude, distance: 0, masterSkills: [], learningSkills: [], socialAccountProviders: [], recently_updated_provider: nil) + } } func ==(lhs: DiscoveredUser, rhs: DiscoveredUser) -> Bool { diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 07d08b86..b64ba58b 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -631,6 +631,20 @@ class FeedsViewController: BaseViewController { return } + let beforeUploadingFeedAction: DiscoveredFeed -> Void = { [weak self] feed in + + dispatch_async(dispatch_get_main_queue()) { + + if let strongSelf = self { + + strongSelf.uploadingFeeds.insert(feed, atIndex: 0) + + let indexPath = NSIndexPath(forRow: 0, inSection: Section.UploadingFeed.rawValue) + strongSelf.feedsTableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) + } + } + } + let afterCreatedFeedAction: DiscoveredFeed -> Void = { [weak self] feed in dispatch_async(dispatch_get_main_queue()) { @@ -745,6 +759,7 @@ class FeedsViewController: BaseViewController { vc.preparedSkill = skill + vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction case "presentNewFeedVoiceRecord": diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 5cb0e38b..05c728e4 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -49,6 +49,7 @@ class NewFeedViewController: SegueViewController { var attachment: Attachment = .Default + var beforeUploadingFeedAction: ((feed: DiscoveredFeed) -> Void)? var afterCreatedFeedAction: ((feed: DiscoveredFeed) -> Void)? var preparedSkill: Skill? @@ -530,12 +531,42 @@ class NewFeedViewController: SegueViewController { self.dismissViewControllerAnimated(true, completion: nil) } - private struct UploadImageInfo { - - let s3UploadParams: S3UploadParams - let metaDataString: String? +// private struct UploadImageInfo { +// +// let s3UploadParams: S3UploadParams +// let metaDataString: String? +// } + + func tryMakeUploadingFeed() -> DiscoveredFeed? { + + guard let + myUserID = YepUserDefaults.userID.value, + realm = try? Realm(), + me = userWithUserID(myUserID, inRealm: realm) else { + return nil + } + + let creator = DiscoveredUser.fromUser(me) + + var kind: FeedKind = .Text + + let createdUnixTime = NSDate().timeIntervalSince1970 + let updatedUnixTime = createdUnixTime + + let message = messageTextView.text.trimming(.WhitespaceAndNewline) + + switch attachment { + case .Default: + if !mediaImages.isEmpty { + kind = .Image + } + default: + break + } + + return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: nil, distance: 0, skill: nil, groupID: "", messagesCount: 0) } - + @objc private func post(sender: UIBarButtonItem) { let messageLength = (messageTextView.text as NSString).length @@ -546,6 +577,12 @@ class NewFeedViewController: SegueViewController { return } + + if let feed = tryMakeUploadingFeed() { + beforeUploadingFeedAction?(feed: feed) + } + + dismissViewControllerAnimated(true, completion: nil) uploadState = .Uploading From 643ea2c0e5a14c89e6122ccc9b4aea0b364bd27a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 13:53:06 +0800 Subject: [PATCH 06/32] better afterCreatedFeedAction --- .../Feeds/FeedsViewController.swift | 17 +++++++++++++---- .../NewFeed/NewFeedViewController.swift | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index b64ba58b..91d18294 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -165,7 +165,7 @@ class FeedsViewController: BaseViewController { } } - private func updateFeedsTableViewOrInsertWithIndexPaths(indexPaths: [NSIndexPath]?) { + private func updateFeedsTableViewOrInsertWithIndexPaths(indexPaths: [NSIndexPath]?, animation: UITableViewRowAnimation? = nil) { // refresh skillUsers @@ -176,7 +176,7 @@ class FeedsViewController: BaseViewController { if let indexPaths = indexPaths where feeds.count > 1 { // insert - feedsTableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic) + feedsTableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: animation ?? .Automatic) } else { // or reload @@ -651,10 +651,19 @@ class FeedsViewController: BaseViewController { if let strongSelf = self { - strongSelf.feeds.insert(feed, atIndex: 0) + var animation: UITableViewRowAnimation = .Automatic + if !strongSelf.uploadingFeeds.isEmpty { + + strongSelf.uploadingFeeds = [] + strongSelf.feedsTableView.reloadSections(NSIndexSet(index: Section.UploadingFeed.rawValue), withRowAnimation: .None) + + animation = .None + } + + strongSelf.feeds.insert(feed, atIndex: 0) let indexPath = NSIndexPath(forRow: 0, inSection: Section.Feed.rawValue) - strongSelf.updateFeedsTableViewOrInsertWithIndexPaths([indexPath]) + strongSelf.updateFeedsTableViewOrInsertWithIndexPaths([indexPath], animation: animation) } } diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 05c728e4..e6c8c0e1 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -583,7 +583,7 @@ class NewFeedViewController: SegueViewController { } dismissViewControllerAnimated(true, completion: nil) - + uploadState = .Uploading let message = messageTextView.text.trimming(.WhitespaceAndNewline) @@ -621,7 +621,7 @@ class NewFeedViewController: SegueViewController { self?.afterCreatedFeedAction?(feed: feed) } - self?.dismissViewControllerAnimated(true, completion: nil) + //self?.dismissViewControllerAnimated(true, completion: nil) } syncGroupsAndDoFurtherAction {} From a2ed1756ede787af739620e230530c24b71a66bf Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 14:26:14 +0800 Subject: [PATCH 07/32] use beforeUploadingFeedAction holding newFeedViewController --- .../Feeds/FeedsViewController.swift | 8 ++++++- .../NewFeed/NewFeedViewController.swift | 22 ++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 91d18294..837200e8 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -625,13 +625,17 @@ class FeedsViewController: BaseViewController { // MARK: - Navigation + private var newFeedViewController: NewFeedViewController? + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { guard let identifier = segue.identifier else { return } - let beforeUploadingFeedAction: DiscoveredFeed -> Void = { [weak self] feed in + let beforeUploadingFeedAction: (DiscoveredFeed, NewFeedViewController) -> Void = { [weak self] feed, newFeedViewController in + + self?.newFeedViewController = newFeedViewController dispatch_async(dispatch_get_main_queue()) { @@ -647,6 +651,8 @@ class FeedsViewController: BaseViewController { let afterCreatedFeedAction: DiscoveredFeed -> Void = { [weak self] feed in + self?.newFeedViewController = nil + dispatch_async(dispatch_get_main_queue()) { if let strongSelf = self { diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index e6c8c0e1..94c8252a 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -49,7 +49,7 @@ class NewFeedViewController: SegueViewController { var attachment: Attachment = .Default - var beforeUploadingFeedAction: ((feed: DiscoveredFeed) -> Void)? + var beforeUploadingFeedAction: ((feed: DiscoveredFeed, newFeedViewController: NewFeedViewController) -> Void)? var afterCreatedFeedAction: ((feed: DiscoveredFeed) -> Void)? var preparedSkill: Skill? @@ -160,15 +160,15 @@ class NewFeedViewController: SegueViewController { case .Uploading: postButton.enabled = false messageTextView.resignFirstResponder() - YepHUD.showActivityIndicator() + //YepHUD.showActivityIndicator() case .Failed(let message): - YepHUD.hideActivityIndicator() + //YepHUD.hideActivityIndicator() postButton.enabled = true YepAlert.alertSorry(message: message, inViewController: self) case .Success: - YepHUD.hideActivityIndicator() + //YepHUD.hideActivityIndicator() messageTextView.text = nil } } @@ -578,11 +578,11 @@ class NewFeedViewController: SegueViewController { return } - if let feed = tryMakeUploadingFeed() { - beforeUploadingFeedAction?(feed: feed) - } + if let feed = tryMakeUploadingFeed() where feed.kind == .Image { + beforeUploadingFeedAction?(feed: feed, newFeedViewController: self) - dismissViewControllerAnimated(true, completion: nil) + dismissViewControllerAnimated(true, completion: nil) + } uploadState = .Uploading @@ -611,7 +611,7 @@ class NewFeedViewController: SegueViewController { } }, completion: { data in - println(data) + println("createFeedWithKind: \(data)") dispatch_async(dispatch_get_main_queue()) { [weak self] in @@ -621,7 +621,9 @@ class NewFeedViewController: SegueViewController { self?.afterCreatedFeedAction?(feed: feed) } - //self?.dismissViewControllerAnimated(true, completion: nil) + if kind == .Image { + self?.dismissViewControllerAnimated(true, completion: nil) + } } syncGroupsAndDoFurtherAction {} From 4742e4447f4bf3bb68c7dd19f6ffa40d7acc3344 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 14:31:14 +0800 Subject: [PATCH 08/32] height of uploadingFeeds --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 837200e8..65fb399f 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -1283,7 +1283,8 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { return 70 case .UploadingFeed: - return 100 + let feed = uploadingFeeds[indexPath.row] + return FeedsViewController.layoutPool.heightOfFeed(feed) case .Feed: let feed = feeds[indexPath.row] From 675cfb2b2cc131b1bd5ec57a0c51a09058361b4d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 15:03:50 +0800 Subject: [PATCH 09/32] DiscoveredAttachment's image --- Yep/Configs/YepConfig.swift | 3 ++ Yep/Services/YepService.swift | 13 +++++++- .../NewFeed/NewFeedViewController.swift | 33 +++++++++++++++++-- .../FeedConversationCell.swift | 2 +- Yep/Views/Feed/FeedView.swift | 2 +- 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Yep/Configs/YepConfig.swift b/Yep/Configs/YepConfig.swift index 3c564e5b..6bee23fd 100644 --- a/Yep/Configs/YepConfig.swift +++ b/Yep/Configs/YepConfig.swift @@ -266,6 +266,9 @@ class YepConfig { struct Media { static let imageWidth: CGFloat = 2048 static let imageHeight: CGFloat = 2048 + + static let miniImageWidth: CGFloat = 200 + static let miniImageHeight: CGFloat = 200 } struct Feedback { diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index c90ebf16..51ee2984 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2776,6 +2776,8 @@ struct DiscoveredAttachment { let metadata: String let URLString: String + var image: UIImage? + var thumbnailImage: UIImage? { guard (metadata as NSString).length > 0 else { @@ -2807,7 +2809,7 @@ struct DiscoveredAttachment { } //return DiscoveredAttachment(kind: kind, metadata: metadata, URLString: URLString) - return DiscoveredAttachment(metadata: metadata, URLString: URLString) + return DiscoveredAttachment(metadata: metadata, URLString: URLString, image: nil) } } @@ -3233,6 +3235,15 @@ enum FeedKind: String { default: return nil } } + + var needBackgroundUpload: Bool { + switch self { + case .Image: + return true + default: + return false + } + } } func createFeedWithKind(kind: FeedKind, message: String, attachments: [JSONDictionary]?, coordinate: CLLocationCoordinate2D?, skill: Skill?, allowComment: Bool, failureHandler: ((Reason, String?) -> Void)?, completion: JSONDictionary -> Void) { diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 94c8252a..d9d1f0d7 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -564,7 +564,34 @@ class NewFeedViewController: SegueViewController { break } - return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: nil, distance: 0, skill: nil, groupID: "", messagesCount: 0) + let imageAttachments: [DiscoveredAttachment] = mediaImages.map({ image in + + let imageWidth = image.size.width + let imageHeight = image.size.height + + let fixedImageWidth: CGFloat + let fixedImageHeight: CGFloat + + if imageWidth > imageHeight { + fixedImageWidth = min(imageWidth, YepConfig.Media.miniImageWidth) + fixedImageHeight = imageHeight * (fixedImageWidth / imageWidth) + } else { + fixedImageHeight = min(imageHeight, YepConfig.Media.miniImageHeight) + fixedImageWidth = imageWidth * (fixedImageHeight / imageHeight) + } + + let fixedSize = CGSize(width: fixedImageWidth, height: fixedImageHeight) + + // resize to smaller, not need fixRotation + + if let image = image.resizeToSize(fixedSize, withInterpolationQuality: .Medium) { + return DiscoveredAttachment(metadata: "", URLString: "", image: nil) + } else { + return nil + } + }).flatMap({ $0 }) + + return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: .Images(imageAttachments), distance: 0, skill: nil, groupID: "", messagesCount: 0) } @objc private func post(sender: UIBarButtonItem) { @@ -578,7 +605,7 @@ class NewFeedViewController: SegueViewController { return } - if let feed = tryMakeUploadingFeed() where feed.kind == .Image { + if let feed = tryMakeUploadingFeed() where feed.kind.needBackgroundUpload { beforeUploadingFeedAction?(feed: feed, newFeedViewController: self) dismissViewControllerAnimated(true, completion: nil) @@ -621,7 +648,7 @@ class NewFeedViewController: SegueViewController { self?.afterCreatedFeedAction?(feed: feed) } - if kind == .Image { + if !kind.needBackgroundUpload { self?.dismissViewControllerAnimated(true, completion: nil) } } diff --git a/Yep/Views/Cells/FeedConversation/FeedConversationCell.swift b/Yep/Views/Cells/FeedConversation/FeedConversationCell.swift index 75cc2d1b..12eee44a 100644 --- a/Yep/Views/Cells/FeedConversation/FeedConversationCell.swift +++ b/Yep/Views/Cells/FeedConversation/FeedConversationCell.swift @@ -64,7 +64,7 @@ class FeedConversationCell: UITableViewCell { let attachments = feed.attachments.map({ //DiscoveredAttachment(kind: AttachmentKind(rawValue: $0.kind)!, metadata: $0.metadata, URLString: $0.URLString) - DiscoveredAttachment( metadata: $0.metadata, URLString: $0.URLString) + DiscoveredAttachment(metadata: $0.metadata, URLString: $0.URLString, image: nil) }) mediaView.setImagesWithAttachments(attachments) diff --git a/Yep/Views/Feed/FeedView.swift b/Yep/Views/Feed/FeedView.swift index d5243a5b..84fedcd3 100644 --- a/Yep/Views/Feed/FeedView.swift +++ b/Yep/Views/Feed/FeedView.swift @@ -298,7 +298,7 @@ class FeedView: UIView { attachments = feed.attachments.map({ //DiscoveredAttachment(kind: AttachmentKind(rawValue: $0.kind)!, metadata: $0.metadata, URLString: $0.URLString) - DiscoveredAttachment(metadata: $0.metadata, URLString: $0.URLString) + DiscoveredAttachment(metadata: $0.metadata, URLString: $0.URLString, image: nil) }) messageLabelTrailingConstraint.constant = attachments.isEmpty ? 15 : 60 From 43f324405e1e1a974bb4b37fe55804151f6fe2b2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 15:13:42 +0800 Subject: [PATCH 10/32] show DiscoveredAttachment's image if it isTemporary --- Yep/Services/YepService.swift | 4 ++++ .../NewFeed/NewFeedViewController.swift | 2 +- Yep/Views/Cells/Feed/FeedBiggerImageCell.swift | 9 +++++++-- Yep/Views/Cells/Feed/FeedNormalImagesCell.swift | 10 ++++++++-- Yep/Views/Cells/FeedMedia/FeedMediaCell.swift | 11 ++++++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 51ee2984..454783de 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2778,6 +2778,10 @@ struct DiscoveredAttachment { var image: UIImage? + var isTemporary: Bool { + return image != nil + } + var thumbnailImage: UIImage? { guard (metadata as NSString).length > 0 else { diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index d9d1f0d7..501e9b2d 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -585,7 +585,7 @@ class NewFeedViewController: SegueViewController { // resize to smaller, not need fixRotation if let image = image.resizeToSize(fixedSize, withInterpolationQuality: .Medium) { - return DiscoveredAttachment(metadata: "", URLString: "", image: nil) + return DiscoveredAttachment(metadata: "", URLString: "", image: image) } else { return nil } diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index f0627b24..0cb4be0f 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -71,8 +71,13 @@ class FeedBiggerImageCell: FeedBasicCell { } if let onlyAttachment = feed.imageAttachments?.first { - biggerImageView.yep_showActivityIndicatorWhenLoading = true - biggerImageView.yep_setImageOfAttachment(onlyAttachment, withSize: YepConfig.FeedBiggerImageCell.imageSize) + if onlyAttachment.isTemporary { + biggerImageView.image = onlyAttachment.image + + } else { + biggerImageView.yep_showActivityIndicatorWhenLoading = true + biggerImageView.yep_setImageOfAttachment(onlyAttachment, withSize: YepConfig.FeedBiggerImageCell.imageSize) + } } if layoutCache.layout == nil { diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 29eec605..32c2ed51 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -112,8 +112,14 @@ class FeedNormalImagesCell: FeedBasicCell { for i in 0.. Date: Tue, 5 Jan 2016 15:27:19 +0800 Subject: [PATCH 11/32] guard !isTemporary to perform tapMediaAction --- Yep/ViewControllers/NewFeed/NewFeedViewController.swift | 4 ++++ Yep/Views/Cells/Feed/FeedAnyImagesCell.swift | 4 ++++ Yep/Views/Cells/Feed/FeedBiggerImageCell.swift | 4 ++++ Yep/Views/Cells/Feed/FeedNormalImagesCell.swift | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 501e9b2d..28b2e07a 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -201,6 +201,10 @@ class NewFeedViewController: SegueViewController { choosePromptLabel.hidden = (newValue != nil) } } + + deinit { + println("NewFeed deinit") + } override func viewDidLoad() { super.viewDidLoad() diff --git a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift index 5f569858..888f7edd 100644 --- a/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedAnyImagesCell.swift @@ -156,6 +156,10 @@ extension FeedAnyImagesCell: UICollectionViewDataSource, UICollectionViewDelegat func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { + guard let firstAttachment = attachments.first where !firstAttachment.isTemporary else { + return + } + let cell = collectionView.cellForItemAtIndexPath(indexPath) as! FeedMediaCell let transitionView = cell.imageView diff --git a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift index 0cb4be0f..992eb6a2 100644 --- a/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift +++ b/Yep/Views/Cells/Feed/FeedBiggerImageCell.swift @@ -93,6 +93,10 @@ class FeedBiggerImageCell: FeedBasicCell { @objc private func tap(sender: UITapGestureRecognizer) { + guard let firstAttachment = feed?.imageAttachments?.first where !firstAttachment.isTemporary else { + return + } + if let attachments = feed?.imageAttachments { tapMediaAction?(transitionView: biggerImageView, image: biggerImageView.image, attachments: attachments, index: 0) } diff --git a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift index 32c2ed51..16dead3d 100644 --- a/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift +++ b/Yep/Views/Cells/Feed/FeedNormalImagesCell.swift @@ -142,6 +142,10 @@ class FeedNormalImagesCell: FeedBasicCell { @objc private func tap(sender: UITapGestureRecognizer) { + guard let firstAttachment = feed?.imageAttachments?.first where !firstAttachment.isTemporary else { + return + } + if let imageView = sender.view as? UIImageView, index = imageViews.indexOf(imageView) { if let attachments = feed?.imageAttachments { From d2d273bfbeb9caccf2b86fdcce3396752d357113 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 16:03:22 +0800 Subject: [PATCH 12/32] new logic for showProfile & showFeedsWithSkill from Feeds --- .../Feeds/FeedsViewController.swift | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 65fb399f..6209c204 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -683,9 +683,20 @@ class FeedsViewController: BaseViewController { let vc = segue.destinationViewController as! ProfileViewController - if let indexPath = sender as? NSIndexPath { - let discoveredUser = feeds[indexPath.row].creator - vc.profileUser = ProfileUser.DiscoveredUserType(discoveredUser) + if let indexPath = sender as? NSIndexPath, section = Section(rawValue: indexPath.section) { + + switch section { + case .SkillUsers: + break + case .UploadingFeed: + let discoveredUser = uploadingFeeds[indexPath.row].creator + vc.profileUser = ProfileUser.DiscoveredUserType(discoveredUser) + case .Feed: + let discoveredUser = feeds[indexPath.row].creator + vc.profileUser = ProfileUser.DiscoveredUserType(discoveredUser) + case .LoadMore: + break + } } vc.fromType = .None @@ -707,8 +718,18 @@ class FeedsViewController: BaseViewController { let vc = segue.destinationViewController as! FeedsViewController - if let indexPath = sender as? NSIndexPath { - vc.skill = feeds[indexPath.row].skill + if let indexPath = sender as? NSIndexPath, section = Section(rawValue: indexPath.section) { + + switch section { + case .SkillUsers: + break + case .UploadingFeed: + vc.skill = uploadingFeeds[indexPath.row].skill + case .Feed: + vc.skill = feeds[indexPath.row].skill + case .LoadMore: + break + } } vc.hidesBottomBarWhenPushed = true @@ -982,6 +1003,7 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.tapAvatarAction = { [weak self] cell in if let indexPath = tableView.indexPathForCell(cell) { // 不直接捕捉 indexPath + println("tapAvatarAction indexPath: \(indexPath.section), \(indexPath.row)") self?.performSegueWithIdentifier("showProfile", sender: indexPath) } } From 6027b5a3cca39ce9b0ea08c4109b341f6953f798 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 17:41:31 +0800 Subject: [PATCH 13/32] Voice needBackgroundUpload --- Yep/Services/YepService.swift | 2 + .../NewFeed/NewFeedViewController.swift | 71 +++++++++++-------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 454783de..e6371d8f 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -3244,6 +3244,8 @@ enum FeedKind: String { switch self { case .Image: return true + case .Audio: + return true default: return false } diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 28b2e07a..ca62edf6 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -559,43 +559,58 @@ class NewFeedViewController: SegueViewController { let message = messageTextView.text.trimming(.WhitespaceAndNewline) + var feedAttachment: DiscoveredFeed.Attachment? + switch attachment { + case .Default: + if !mediaImages.isEmpty { kind = .Image + + let imageAttachments: [DiscoveredAttachment] = mediaImages.map({ image in + + let imageWidth = image.size.width + let imageHeight = image.size.height + + let fixedImageWidth: CGFloat + let fixedImageHeight: CGFloat + + if imageWidth > imageHeight { + fixedImageWidth = min(imageWidth, YepConfig.Media.miniImageWidth) + fixedImageHeight = imageHeight * (fixedImageWidth / imageWidth) + } else { + fixedImageHeight = min(imageHeight, YepConfig.Media.miniImageHeight) + fixedImageWidth = imageWidth * (fixedImageHeight / imageHeight) + } + + let fixedSize = CGSize(width: fixedImageWidth, height: fixedImageHeight) + + // resize to smaller, not need fixRotation + + if let image = image.resizeToSize(fixedSize, withInterpolationQuality: .Medium) { + return DiscoveredAttachment(metadata: "", URLString: "", image: image) + } else { + return nil + } + }).flatMap({ $0 }) + + feedAttachment = .Images(imageAttachments) } + + case .Voice: + + kind = .Audio + + let audioInfo = DiscoveredFeed.AudioInfo(feedID: "", URLString: "", metaData: NSData(), duration: 0, sampleValues: []) + + feedAttachment = .Audio(audioInfo) + default: break } - let imageAttachments: [DiscoveredAttachment] = mediaImages.map({ image in - - let imageWidth = image.size.width - let imageHeight = image.size.height - - let fixedImageWidth: CGFloat - let fixedImageHeight: CGFloat - - if imageWidth > imageHeight { - fixedImageWidth = min(imageWidth, YepConfig.Media.miniImageWidth) - fixedImageHeight = imageHeight * (fixedImageWidth / imageWidth) - } else { - fixedImageHeight = min(imageHeight, YepConfig.Media.miniImageHeight) - fixedImageWidth = imageWidth * (fixedImageHeight / imageHeight) - } - - let fixedSize = CGSize(width: fixedImageWidth, height: fixedImageHeight) - - // resize to smaller, not need fixRotation - - if let image = image.resizeToSize(fixedSize, withInterpolationQuality: .Medium) { - return DiscoveredAttachment(metadata: "", URLString: "", image: image) - } else { - return nil - } - }).flatMap({ $0 }) - - return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: .Images(imageAttachments), distance: 0, skill: nil, groupID: "", messagesCount: 0) + return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: feedAttachment, distance: 0, skill: nil, groupID: "", messagesCount: 0) } @objc private func post(sender: UIBarButtonItem) { From 0c83010a84670282a91cd2f006a9c286b18ccb59 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 17:53:50 +0800 Subject: [PATCH 14/32] beforeUploadingFeedAction for NewFeedVoiceRecordViewController --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 1 + .../NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 6209c204..b380e228 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -809,6 +809,7 @@ class FeedsViewController: BaseViewController { vc.preparedSkill = skill + vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction case "presentPickLocation": diff --git a/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift b/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift index 8391ff1b..c627bbdf 100644 --- a/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift +++ b/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift @@ -13,6 +13,7 @@ class NewFeedVoiceRecordViewController: SegueViewController { var preparedSkill: Skill? + var beforeUploadingFeedAction: ((feed: DiscoveredFeed, newFeedViewController: NewFeedViewController) -> Void)? var afterCreatedFeedAction: ((feed: DiscoveredFeed) -> Void)? @IBOutlet private weak var nextButton: UIBarButtonItem! @@ -429,6 +430,7 @@ class NewFeedVoiceRecordViewController: SegueViewController { vc.preparedSkill = preparedSkill + vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction } From bd802a0377fe409cf30451e1954f86b0578af189 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 17:55:57 +0800 Subject: [PATCH 15/32] make feedAttachment .Audio(audioInfo) --- .../NewFeed/NewFeedViewController.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index ca62edf6..9fbb3a48 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -598,11 +598,18 @@ class NewFeedViewController: SegueViewController { feedAttachment = .Images(imageAttachments) } - case .Voice: + case .Voice(let feedVoice): kind = .Audio - let audioInfo = DiscoveredFeed.AudioInfo(feedID: "", URLString: "", metaData: NSData(), duration: 0, sampleValues: []) + let audioAsset = AVURLAsset(URL: feedVoice.fileURL, options: nil) + let audioDuration = CMTimeGetSeconds(audioAsset.duration) as Double + + let audioMetaDataInfo = [YepConfig.MetaData.audioSamples: feedVoice.limitedSampleValues, YepConfig.MetaData.audioDuration: audioDuration] + + let audioMetaData = try! NSJSONSerialization.dataWithJSONObject(audioMetaDataInfo, options: []) + + let audioInfo = DiscoveredFeed.AudioInfo(feedID: "", URLString: "", metaData: audioMetaData, duration: audioDuration, sampleValues: feedVoice.limitedSampleValues) feedAttachment = .Audio(audioInfo) From c0f73e86ea62e4d7ad723314cc1a75154a340b7b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Tue, 5 Jan 2016 18:17:57 +0800 Subject: [PATCH 16/32] new alert logic for NewFeed when Failed --- .../NewFeed/NewFeedViewController.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 9fbb3a48..3ee7353c 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -54,6 +54,8 @@ class NewFeedViewController: SegueViewController { var preparedSkill: Skill? + weak var oldPresentingViewController: UIViewController? + @IBOutlet private weak var feedWhiteBGView: UIView! @@ -165,7 +167,14 @@ class NewFeedViewController: SegueViewController { case .Failed(let message): //YepHUD.hideActivityIndicator() postButton.enabled = true - YepAlert.alertSorry(message: message, inViewController: self) + + let vc: UIViewController? + if presentingViewController != nil { + vc = self + } else { + vc = oldPresentingViewController + } + YepAlert.alertSorry(message: message, inViewController: vc) case .Success: //YepHUD.hideActivityIndicator() @@ -221,6 +230,8 @@ class NewFeedViewController: SegueViewController { } view.sendSubviewToBack(feedWhiteBGView) + + oldPresentingViewController = self.presentingViewController isDirty = false From 1fe9b2f4d60a3b0bab288f50ee9fb414183db52b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 10:07:19 +0800 Subject: [PATCH 17/32] staging --- Yep.xcodeproj/project.pbxproj | 2 +- Yep/Services/YepService.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 4c3b2e3f..5e1ff61f 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -2955,7 +2955,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING_"; + OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index e6371d8f..611941e2 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -12,7 +12,7 @@ import CoreLocation import Alamofire #if STAGING -let yepBaseURL = NSURL(string: "https://park-staging.catchchatchina.com/api")! +let yepBaseURL = NSURL(string: "https://park-staging.catchchatchina.com")! let fayeBaseURL = NSURL(string: "wss://faye-staging.catchchatchina.com/faye")! #else let yepBaseURL = NSURL(string: "https://api.soyep.com")! From e9e205d8c9ad170a014721b6ff76ce007764dd3f Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 10:19:07 +0800 Subject: [PATCH 18/32] uploadingErrorMessage for DiscoveredFeed --- Yep/Services/YepService.swift | 4 +++- Yep/ViewControllers/NewFeed/NewFeedViewController.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 611941e2..f00aa1a3 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -2987,6 +2987,8 @@ struct DiscoveredFeed: Hashable { let groupID: String var messagesCount: Int + var uploadingErrorMessage: String? = nil + var timeAndDistanceString: String { let timeString = "\(NSDate(timeIntervalSince1970: createdUnixTime).timeAgo)" @@ -3092,7 +3094,7 @@ struct DiscoveredFeed: Hashable { skill = Skill.fromJSONDictionary(skillInfo) } - return DiscoveredFeed(id: id, allowComment: allowComment, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: body, attachment: attachment, distance: distance, skill: skill, groupID: groupID, messagesCount: messagesCount) + return DiscoveredFeed(id: id, allowComment: allowComment, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: body, attachment: attachment, distance: distance, skill: skill, groupID: groupID, messagesCount: messagesCount, uploadingErrorMessage: nil) } } diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 3ee7353c..404d3dc4 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -628,7 +628,7 @@ class NewFeedViewController: SegueViewController { break } - return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: feedAttachment, distance: 0, skill: nil, groupID: "", messagesCount: 0) + return DiscoveredFeed(id: "", allowComment: true, kind: kind, createdUnixTime: createdUnixTime, updatedUnixTime: updatedUnixTime, creator: creator, body: message, attachment: feedAttachment, distance: 0, skill: nil, groupID: "", messagesCount: 0, uploadingErrorMessage: nil) } @objc private func post(sender: UIBarButtonItem) { From 7e71102dbf27da3c87afb21d8ce56c01ad23137b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 11:03:03 +0800 Subject: [PATCH 19/32] getFeedsViewController; handleUploadingErrorMessage --- .../Feeds/FeedsViewController.swift | 14 ++++++++++++++ .../NewFeed/NewFeedViewController.swift | 12 ++++++------ .../NewFeedVoiceRecordViewController.swift | 2 ++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index b380e228..2c6ed4f5 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -24,6 +24,14 @@ class FeedsViewController: BaseViewController { var hideRightBarItem: Bool = false var uploadingFeeds = [DiscoveredFeed]() + func handleUploadingErrorMessage(message: String) { + if !uploadingFeeds.isEmpty { + uploadingFeeds[0].uploadingErrorMessage = message + feedsTableView.reloadSections(NSIndexSet(index: Section.UploadingFeed.rawValue), withRowAnimation: .None) + + println("handleUploadingErrorMessage: \(message)") + } + } var feeds = [DiscoveredFeed]() @IBOutlet weak var feedsTableView: UITableView! @@ -677,6 +685,10 @@ class FeedsViewController: BaseViewController { }) } + let getFeedsViewController: () -> FeedsViewController? = { [weak self] in + return self + } + switch identifier { case "showProfile": @@ -797,6 +809,7 @@ class FeedsViewController: BaseViewController { vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction + vc.getFeedsViewController = getFeedsViewController case "presentNewFeedVoiceRecord": @@ -811,6 +824,7 @@ class FeedsViewController: BaseViewController { vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction + vc.getFeedsViewController = getFeedsViewController case "presentPickLocation": diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index 404d3dc4..b7fb3dfb 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -54,7 +54,8 @@ class NewFeedViewController: SegueViewController { var preparedSkill: Skill? - weak var oldPresentingViewController: UIViewController? + weak var feedsViewController: FeedsViewController? + var getFeedsViewController: (() -> FeedsViewController?)? @IBOutlet private weak var feedWhiteBGView: UIView! @@ -168,13 +169,11 @@ class NewFeedViewController: SegueViewController { //YepHUD.hideActivityIndicator() postButton.enabled = true - let vc: UIViewController? if presentingViewController != nil { - vc = self + YepAlert.alertSorry(message: message, inViewController: self) } else { - vc = oldPresentingViewController + feedsViewController?.handleUploadingErrorMessage(message) } - YepAlert.alertSorry(message: message, inViewController: vc) case .Success: //YepHUD.hideActivityIndicator() @@ -231,7 +230,8 @@ class NewFeedViewController: SegueViewController { view.sendSubviewToBack(feedWhiteBGView) - oldPresentingViewController = self.presentingViewController + feedsViewController = getFeedsViewController?() + println("feedsViewController: \(feedsViewController)") isDirty = false diff --git a/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift b/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift index c627bbdf..6754dd36 100644 --- a/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift +++ b/Yep/ViewControllers/NewFeedVoiceRecord/NewFeedVoiceRecordViewController.swift @@ -15,6 +15,7 @@ class NewFeedVoiceRecordViewController: SegueViewController { var beforeUploadingFeedAction: ((feed: DiscoveredFeed, newFeedViewController: NewFeedViewController) -> Void)? var afterCreatedFeedAction: ((feed: DiscoveredFeed) -> Void)? + var getFeedsViewController: (() -> FeedsViewController?)? @IBOutlet private weak var nextButton: UIBarButtonItem! @@ -432,6 +433,7 @@ class NewFeedVoiceRecordViewController: SegueViewController { vc.beforeUploadingFeedAction = beforeUploadingFeedAction vc.afterCreatedFeedAction = afterCreatedFeedAction + vc.getFeedsViewController = getFeedsViewController } default: From 9918aabe757befff1205521ed33bcb03ed125651 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 11:30:25 +0800 Subject: [PATCH 20/32] add FeedUploadingErrorContainerView --- Yep.xcodeproj/project.pbxproj | 4 + .../FeedUploadingErrorContainerView.swift | 89 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 5e1ff61f..5f4d5411 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -328,6 +328,7 @@ 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; 50F5AF9A1BBBD02A0033C9BC /* FeedMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */; }; 50F6D32A1C3B618200CB673C /* ModelTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F6D3291C3B618200CB673C /* ModelTypes.swift */; }; + 50F6D32E1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F6D32D1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift */; }; 50FA9A441B661698009BF2A0 /* UIViewController+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */; }; 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */; }; 50FD753F1C20FF8D0050A382 /* FeedMediaContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753E1C20FF8D0050A382 /* FeedMediaContainerView.swift */; }; @@ -698,6 +699,7 @@ 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaCell.xib; path = Views/Cells/FeedMedia/FeedMediaCell.xib; sourceTree = ""; }; 50F6D3291C3B618200CB673C /* ModelTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ModelTypes.swift; path = Protocols/ModelTypes.swift; sourceTree = ""; }; + 50F6D32D1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedUploadingErrorContainerView.swift; path = Views/ContainerViews/FeedUploadingErrorContainerView.swift; sourceTree = ""; }; 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIViewController+Yep.swift"; path = "Extensions/UIViewController+Yep.swift"; sourceTree = ""; }; 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FPSLabel.swift; path = Views/Labels/FPSLabel.swift; sourceTree = ""; }; 50FD753E1C20FF8D0050A382 /* FeedMediaContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaContainerView.swift; path = Views/ContainerViews/FeedMediaContainerView.swift; sourceTree = ""; }; @@ -2217,6 +2219,7 @@ 505082321C21130100643CEB /* FeedGithubRepoContainerView.swift */, 505082341C212E9200643CEB /* FeedLocationContainerView.swift */, 505082361C21377E00643CEB /* FeedVoiceContainerView.swift */, + 50F6D32D1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift */, ); name = ContainerViews; sourceTree = ""; @@ -2748,6 +2751,7 @@ 6A56328E1BC90A4500397B53 /* DiscoverCardUserCell.swift in Sources */, 5016901C1BFB22180096C4F9 /* SocialWorkService.swift in Sources */, 0A0A11821AE389380008772C /* RegisterSkillsLayout.swift in Sources */, + 50F6D32E1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift in Sources */, 50C0909B1ADE234F00CC6389 /* RegisterPickSkillsViewController.swift in Sources */, 5076FC5A1AF9DF6B00D7381A /* ConversationMessagePreviewTransitionManager.swift in Sources */, 50F5AF951BBBCDA30033C9BC /* FeedMediaAddCell.swift in Sources */, diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift new file mode 100644 index 00000000..66544839 --- /dev/null +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -0,0 +1,89 @@ +// +// FeedUploadingErrorContainerView.swift +// Yep +// +// Created by nixzhu on 16/1/6. +// Copyright © 2016年 Catch Inc. All rights reserved. +// + +import UIKit + +class FeedUploadingErrorContainerView: UIView { + + lazy var leftContainerView: UIView = { + let view = UIView() + view.backgroundColor = UIColor(red: 1, green: 56/255.0, blue: 36/255.0, alpha: 0.1) + view.layer.cornerRadius = 5 + return view + }() + + lazy var iconImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "icon_topic_reddot")) + return imageView + }() + + lazy var errorMessageLabel: UILabel = { + let label = UILabel() + label.text = NSLocalizedString("Upload failed.", comment: "") + label.textColor = UIColor.redColor() + return label + }() + + lazy var retryButton: UIButton = { + let button = UIButton() + button.setTitle(NSLocalizedString("Retry", comment: ""), forState: .Normal) + return button + }() + + lazy var deleteButton: UIButton = { + let button = UIButton() + button.setTitle(NSLocalizedString("Delete", comment: ""), forState: .Normal) + return button + }() + + func makeUI() { + + do { + addSubview(leftContainerView) + addSubview(deleteButton) + + leftContainerView.translatesAutoresizingMaskIntoConstraints = false + deleteButton.translatesAutoresizingMaskIntoConstraints = false + + let views = [ + "leftContainerView": leftContainerView, + "deleteButton": deleteButton, + ] + + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[leftContainerView][deleteButton]|", options: [.AlignAllCenterY], metrics: nil, views: views) + let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|[leftContainerView]|", options: [], metrics: nil, views: views) + + NSLayoutConstraint.activateConstraints(constraintsH) + NSLayoutConstraint.activateConstraints(constraintsV) + } + + do { + leftContainerView.addSubview(iconImageView) + leftContainerView.addSubview(errorMessageLabel) + leftContainerView.addSubview(retryButton) + + iconImageView.translatesAutoresizingMaskIntoConstraints = false + errorMessageLabel.translatesAutoresizingMaskIntoConstraints = false + retryButton.translatesAutoresizingMaskIntoConstraints = false + + let views = [ + "iconImageView": iconImageView, + "errorMessageLabel": errorMessageLabel, + "retryButton": retryButton, + ] + + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[iconImageView][errorMessageLabel][retryButton]|", options: [.AlignAllCenterY], metrics: nil, views: views) + + let iconImageViewCenterY = NSLayoutConstraint(item: iconImageView, attribute: .CenterY, relatedBy: .Equal, toItem: leftContainerView, attribute: .CenterY, multiplier: 1.0, constant: 0) + + NSLayoutConstraint.activateConstraints(constraintsH) + NSLayoutConstraint.activateConstraints([iconImageViewCenterY]) + } + } +} + From 349b0f334a0abf7780b82045e1412966406ef389 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 13:22:52 +0800 Subject: [PATCH 21/32] layout detail --- .../FeedUploadingErrorContainerView.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift index 66544839..0cf00ec3 100644 --- a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -32,17 +32,27 @@ class FeedUploadingErrorContainerView: UIView { lazy var retryButton: UIButton = { let button = UIButton() button.setTitle(NSLocalizedString("Retry", comment: ""), forState: .Normal) + button.setTitleColor(UIColor.yepTintColor(), forState: .Normal) return button }() lazy var deleteButton: UIButton = { let button = UIButton() button.setTitle(NSLocalizedString("Delete", comment: ""), forState: .Normal) + button.setTitleColor(UIColor.redColor(), forState: .Normal) return button }() + override func didMoveToSuperview() { + super.didMoveToSuperview() + + makeUI() + } + func makeUI() { + backgroundColor = UIColor.whiteColor() + do { addSubview(leftContainerView) addSubview(deleteButton) @@ -55,7 +65,7 @@ class FeedUploadingErrorContainerView: UIView { "deleteButton": deleteButton, ] - let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[leftContainerView][deleteButton]|", options: [.AlignAllCenterY], metrics: nil, views: views) + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[leftContainerView]-15-[deleteButton]-15-|", options: [.AlignAllCenterY], metrics: nil, views: views) let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|[leftContainerView]|", options: [], metrics: nil, views: views) NSLayoutConstraint.activateConstraints(constraintsH) @@ -77,7 +87,10 @@ class FeedUploadingErrorContainerView: UIView { "retryButton": retryButton, ] - let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[iconImageView][errorMessageLabel][retryButton]|", options: [.AlignAllCenterY], metrics: nil, views: views) + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[iconImageView]-[errorMessageLabel]-[retryButton]-|", options: [.AlignAllCenterY], metrics: nil, views: views) + + iconImageView.setContentHuggingPriority(UILayoutPriorityRequired, forAxis: .Horizontal) + iconImageView.setContentCompressionResistancePriority(UILayoutPriorityRequired, forAxis: .Horizontal) let iconImageViewCenterY = NSLayoutConstraint(item: iconImageView, attribute: .CenterY, relatedBy: .Equal, toItem: leftContainerView, attribute: .CenterY, multiplier: 1.0, constant: 0) From 272770fe5f9bca56a845ddb837f190698b032db8 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 13:42:01 +0800 Subject: [PATCH 22/32] add uploadingErrorContainerView to FeedBasicCell --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 16 ++++++++++++++-- Yep/Views/Cells/Feed/FeedCellLayout.swift | 2 +- .../FeedUploadingErrorContainerView.swift | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index bba2c55b..5d53b2c4 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -124,6 +124,11 @@ class FeedBasicCell: UITableViewCell { return imageView }() + lazy var uploadingErrorContainerView: FeedUploadingErrorContainerView = { + let view = FeedUploadingErrorContainerView() + return view + }() + var feed: DiscoveredFeed? var tapAvatarAction: (UITableViewCell -> Void)? @@ -162,7 +167,7 @@ class FeedBasicCell: UITableViewCell { let rect = feed.body.boundingRectWithSize(CGSize(width: FeedBasicCell.messageTextViewMaxWidth, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.textAttributes, context: nil) - let height: CGFloat = ceil(rect.height) + 10 + 40 + 4 + 15 + 17 + 15 + let height: CGFloat = 10 + 40 + ceil(rect.height) + 4 + 15 + 17 + 15 return ceil(height) } @@ -250,7 +255,7 @@ class FeedBasicCell: UITableViewCell { discussionImageView.frame = basicLayout.discussionImageViewFrame } else { - leftBottomLabel.frame.origin.y = contentView.bounds.height - leftBottomLabel.frame.height - 10 + leftBottomLabel.frame.origin.y = contentView.bounds.height - leftBottomLabel.frame.height - 15 let rect = messagesCountString.boundingRectWithSize(CGSize(width: 320, height: CGFloat(FLT_MAX)), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: YepConfig.FeedBasicCell.bottomLabelsTextAttributes, context: nil) @@ -271,6 +276,13 @@ class FeedBasicCell: UITableViewCell { layoutCache.update(layout: newLayout) } + + //if let message = feed.uploadingErrorMessage { + let y = leftBottomLabel.frame.origin.y - (30 - leftBottomLabel.frame.height) * 0.5 + uploadingErrorContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65, height: 30) + contentView.addSubview(uploadingErrorContainerView) + //uploadingErrorContainerView.errorMessageLabel.text = message + //} } // MARK: Actions diff --git a/Yep/Views/Cells/Feed/FeedCellLayout.swift b/Yep/Views/Cells/Feed/FeedCellLayout.swift index 4adce52a..ea061310 100644 --- a/Yep/Views/Cells/Feed/FeedCellLayout.swift +++ b/Yep/Views/Cells/Feed/FeedCellLayout.swift @@ -183,7 +183,7 @@ struct FeedCellLayout { let messageTextViewHeight = ceil(_rect1.height) let messageTextViewFrame = CGRect(x: 65, y: 54, width: screenWidth - 65 - 15, height: messageTextViewHeight) - let leftBottomLabelOriginY = height - 17 - 10 + let leftBottomLabelOriginY = height - 17 - 15 let leftBottomLabelFrame = CGRect(x: 65, y: leftBottomLabelOriginY, width: 200, height: 17) let messagesCountString = "\(feed.messagesCount)" diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift index 0cf00ec3..5357b4b1 100644 --- a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -51,7 +51,7 @@ class FeedUploadingErrorContainerView: UIView { func makeUI() { - backgroundColor = UIColor.whiteColor() + //backgroundColor = UIColor.whiteColor() do { addSubview(leftContainerView) From cc030b893b393f2d8ef0e00da7be7171e2e6e5a8 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 13:55:35 +0800 Subject: [PATCH 23/32] show / hide uploadingErrorContainerView --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 26 ++++++++++++++----- .../FeedUploadingErrorContainerView.swift | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 5d53b2c4..b00d672b 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -152,6 +152,9 @@ class FeedBasicCell: UITableViewCell { contentView.addSubview(leftBottomLabel) contentView.addSubview(messageCountLabel) contentView.addSubview(discussionImageView) + + contentView.addSubview(uploadingErrorContainerView) + uploadingErrorContainerView.hidden = true } required init?(coder aDecoder: NSCoder) { @@ -277,12 +280,23 @@ class FeedBasicCell: UITableViewCell { layoutCache.update(layout: newLayout) } - //if let message = feed.uploadingErrorMessage { - let y = leftBottomLabel.frame.origin.y - (30 - leftBottomLabel.frame.height) * 0.5 - uploadingErrorContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65, height: 30) - contentView.addSubview(uploadingErrorContainerView) - //uploadingErrorContainerView.errorMessageLabel.text = message - //} + do { + var hasUploadingErrorMessage = false + + if let message = feed.uploadingErrorMessage { + let y = leftBottomLabel.frame.origin.y - (30 - leftBottomLabel.frame.height) * 0.5 + uploadingErrorContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65, height: 30) + uploadingErrorContainerView.errorMessageLabel.text = message + + hasUploadingErrorMessage = true + } + + uploadingErrorContainerView.hidden = !hasUploadingErrorMessage + + leftBottomLabel.hidden = hasUploadingErrorMessage + messageCountLabel.hidden = hasUploadingErrorMessage + discussionImageView.hidden = hasUploadingErrorMessage + } } // MARK: Actions diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift index 5357b4b1..3186c8cd 100644 --- a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -24,7 +24,7 @@ class FeedUploadingErrorContainerView: UIView { lazy var errorMessageLabel: UILabel = { let label = UILabel() - label.text = NSLocalizedString("Upload failed.", comment: "") + label.text = NSLocalizedString("Upload failed!", comment: "") label.textColor = UIColor.redColor() return label }() From b5eead7d6db03f4f0737037968761b568afcd663 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 13:59:00 +0800 Subject: [PATCH 24/32] trans --- Yep/zh-Hans.lproj/Localizable.strings | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/zh-Hans.lproj/Localizable.strings b/Yep/zh-Hans.lproj/Localizable.strings index e1fc8f76..97e56efe 100644 --- a/Yep/zh-Hans.lproj/Localizable.strings +++ b/Yep/zh-Hans.lproj/Localizable.strings @@ -728,3 +728,5 @@ "Recalled by creator." = "消息已被撤回。"; +"Retry" = "重试"; + From 6ef7f86e0b153c0b54ee0f2ae08ab4fe990ef12b Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 14:22:27 +0800 Subject: [PATCH 25/32] retryUploadingFeedAction --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 6 ++++++ .../NewFeed/NewFeedViewController.swift | 12 +++++++++--- Yep/Views/Cells/Feed/FeedBasicCell.swift | 8 +++++++- .../FeedUploadingErrorContainerView.swift | 7 +++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index 2c6ed4f5..a9321c5a 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -1285,6 +1285,12 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { let feed = uploadingFeeds[indexPath.row] configureFeedCell(cell, withFeed: feed) + if let cell = cell as? FeedBasicCell { + cell.retryUploadingFeedAction = { [weak self] in + self?.newFeedViewController?.post(again: true) + } + } + case .Feed: let feed = feeds[indexPath.row] diff --git a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift index b7fb3dfb..70495a18 100644 --- a/Yep/ViewControllers/NewFeed/NewFeedViewController.swift +++ b/Yep/ViewControllers/NewFeed/NewFeedViewController.swift @@ -632,6 +632,10 @@ class NewFeedViewController: SegueViewController { } @objc private func post(sender: UIBarButtonItem) { + post(again: false) + } + + func post(again again: Bool) { let messageLength = (messageTextView.text as NSString).length @@ -642,10 +646,12 @@ class NewFeedViewController: SegueViewController { return } - if let feed = tryMakeUploadingFeed() where feed.kind.needBackgroundUpload { - beforeUploadingFeedAction?(feed: feed, newFeedViewController: self) + if !again { + if let feed = tryMakeUploadingFeed() where feed.kind.needBackgroundUpload { + beforeUploadingFeedAction?(feed: feed, newFeedViewController: self) - dismissViewControllerAnimated(true, completion: nil) + dismissViewControllerAnimated(true, completion: nil) + } } uploadState = .Uploading diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index b00d672b..7fb695dc 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -138,6 +138,8 @@ class FeedBasicCell: UITableViewCell { var touchesEndedAction: (UITableViewCell -> Void)? var touchesCancelledAction: (UITableViewCell -> Void)? + var retryUploadingFeedAction: (() -> Void)? + override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -284,11 +286,15 @@ class FeedBasicCell: UITableViewCell { var hasUploadingErrorMessage = false if let message = feed.uploadingErrorMessage { + hasUploadingErrorMessage = true + let y = leftBottomLabel.frame.origin.y - (30 - leftBottomLabel.frame.height) * 0.5 uploadingErrorContainerView.frame = CGRect(x: 65, y: y, width: screenWidth - 65, height: 30) uploadingErrorContainerView.errorMessageLabel.text = message - hasUploadingErrorMessage = true + uploadingErrorContainerView.retryAction = { [weak self] in + self?.retryUploadingFeedAction?() + } } uploadingErrorContainerView.hidden = !hasUploadingErrorMessage diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift index 3186c8cd..58ed426e 100644 --- a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -10,6 +10,8 @@ import UIKit class FeedUploadingErrorContainerView: UIView { + var retryAction: (() -> Void)? + lazy var leftContainerView: UIView = { let view = UIView() view.backgroundColor = UIColor(red: 1, green: 56/255.0, blue: 36/255.0, alpha: 0.1) @@ -33,6 +35,7 @@ class FeedUploadingErrorContainerView: UIView { let button = UIButton() button.setTitle(NSLocalizedString("Retry", comment: ""), forState: .Normal) button.setTitleColor(UIColor.yepTintColor(), forState: .Normal) + button.addTarget(self, action: "retry:", forControlEvents: .TouchUpInside) return button }() @@ -98,5 +101,9 @@ class FeedUploadingErrorContainerView: UIView { NSLayoutConstraint.activateConstraints([iconImageViewCenterY]) } } + + @objc private func retry(sender: UIButton) { + retryAction?() + } } From c04610fbc109c9caf8567f2969f528ff80e9597f Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 14:31:31 +0800 Subject: [PATCH 26/32] update UI when do retryUploadingFeedAction --- .../Feeds/FeedsViewController.swift | 7 +++++- Yep/Views/Cells/Feed/FeedBasicCell.swift | 22 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index a9321c5a..f78279b0 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -1286,8 +1286,13 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { configureFeedCell(cell, withFeed: feed) if let cell = cell as? FeedBasicCell { - cell.retryUploadingFeedAction = { [weak self] in + cell.retryUploadingFeedAction = { [weak self] cell in self?.newFeedViewController?.post(again: true) + + if let indexPath = self?.feedsTableView.indexPathForCell(cell) { + self?.uploadingFeeds[indexPath.row].uploadingErrorMessage = nil + cell.hasUploadingErrorMessage = false + } } } diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 7fb695dc..8e31be9f 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -128,6 +128,15 @@ class FeedBasicCell: UITableViewCell { let view = FeedUploadingErrorContainerView() return view }() + var hasUploadingErrorMessage = false { + didSet { + uploadingErrorContainerView.hidden = !hasUploadingErrorMessage + + leftBottomLabel.hidden = hasUploadingErrorMessage + messageCountLabel.hidden = hasUploadingErrorMessage + discussionImageView.hidden = hasUploadingErrorMessage + } + } var feed: DiscoveredFeed? @@ -138,7 +147,7 @@ class FeedBasicCell: UITableViewCell { var touchesEndedAction: (UITableViewCell -> Void)? var touchesCancelledAction: (UITableViewCell -> Void)? - var retryUploadingFeedAction: (() -> Void)? + var retryUploadingFeedAction: ((cell: FeedBasicCell) -> Void)? override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -283,7 +292,6 @@ class FeedBasicCell: UITableViewCell { } do { - var hasUploadingErrorMessage = false if let message = feed.uploadingErrorMessage { hasUploadingErrorMessage = true @@ -293,15 +301,11 @@ class FeedBasicCell: UITableViewCell { uploadingErrorContainerView.errorMessageLabel.text = message uploadingErrorContainerView.retryAction = { [weak self] in - self?.retryUploadingFeedAction?() + if let strongSelf = self { + strongSelf.retryUploadingFeedAction?(cell: strongSelf) + } } } - - uploadingErrorContainerView.hidden = !hasUploadingErrorMessage - - leftBottomLabel.hidden = hasUploadingErrorMessage - messageCountLabel.hidden = hasUploadingErrorMessage - discussionImageView.hidden = hasUploadingErrorMessage } } From 8afb2dcae98d5620a5b96f9c27de6453d6348ff2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 14:38:11 +0800 Subject: [PATCH 27/32] add init frame for uploadingErrorContainerView, make auto layout happy --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 8e31be9f..369ac4ab 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -125,7 +125,7 @@ class FeedBasicCell: UITableViewCell { }() lazy var uploadingErrorContainerView: FeedUploadingErrorContainerView = { - let view = FeedUploadingErrorContainerView() + let view = FeedUploadingErrorContainerView(frame: CGRect(x: 0, y: 0, width: 200, height: 30)) return view }() var hasUploadingErrorMessage = false { From 4f968464e7234156794538753d8c7bac40993ec3 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 14:44:25 +0800 Subject: [PATCH 28/32] better logic for addSubview uploadingErrorContainerView --- Yep/Views/Cells/Feed/FeedBasicCell.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 369ac4ab..1cd1bec8 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -163,9 +163,6 @@ class FeedBasicCell: UITableViewCell { contentView.addSubview(leftBottomLabel) contentView.addSubview(messageCountLabel) contentView.addSubview(discussionImageView) - - contentView.addSubview(uploadingErrorContainerView) - uploadingErrorContainerView.hidden = true } required init?(coder aDecoder: NSCoder) { @@ -292,7 +289,6 @@ class FeedBasicCell: UITableViewCell { } do { - if let message = feed.uploadingErrorMessage { hasUploadingErrorMessage = true @@ -305,6 +301,11 @@ class FeedBasicCell: UITableViewCell { strongSelf.retryUploadingFeedAction?(cell: strongSelf) } } + + contentView.addSubview(uploadingErrorContainerView) + + } else { + hasUploadingErrorMessage = false } } } From 3c659e5335a91ce6cf6deeacd48b596d2ab7df85 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 14:52:28 +0800 Subject: [PATCH 29/32] better feedsTableView update when afterCreatedFeedAction --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index f78279b0..bad73bf6 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -665,6 +665,8 @@ class FeedsViewController: BaseViewController { if let strongSelf = self { + strongSelf.feedsTableView.beginUpdates() + var animation: UITableViewRowAnimation = .Automatic if !strongSelf.uploadingFeeds.isEmpty { @@ -678,6 +680,8 @@ class FeedsViewController: BaseViewController { strongSelf.feeds.insert(feed, atIndex: 0) let indexPath = NSIndexPath(forRow: 0, inSection: Section.Feed.rawValue) strongSelf.updateFeedsTableViewOrInsertWithIndexPaths([indexPath], animation: animation) + + strongSelf.feedsTableView.endUpdates() } } From 024066d178506a5732faeff1e82c661eb5eabec8 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 15:00:41 +0800 Subject: [PATCH 30/32] deleteUploadingFeedAction --- Yep/ViewControllers/Feeds/FeedsViewController.swift | 12 ++++++++++++ Yep/Views/Cells/Feed/FeedBasicCell.swift | 7 +++++++ .../FeedUploadingErrorContainerView.swift | 10 ++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Yep/ViewControllers/Feeds/FeedsViewController.swift b/Yep/ViewControllers/Feeds/FeedsViewController.swift index bad73bf6..ccc8fb57 100644 --- a/Yep/ViewControllers/Feeds/FeedsViewController.swift +++ b/Yep/ViewControllers/Feeds/FeedsViewController.swift @@ -1290,7 +1290,9 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { configureFeedCell(cell, withFeed: feed) if let cell = cell as? FeedBasicCell { + cell.retryUploadingFeedAction = { [weak self] cell in + self?.newFeedViewController?.post(again: true) if let indexPath = self?.feedsTableView.indexPathForCell(cell) { @@ -1298,6 +1300,16 @@ extension FeedsViewController: UITableViewDataSource, UITableViewDelegate { cell.hasUploadingErrorMessage = false } } + + cell.deleteUploadingFeedAction = { [weak self] cell in + + if let indexPath = self?.feedsTableView.indexPathForCell(cell) { + self?.uploadingFeeds.removeAtIndex(indexPath.row) + self?.feedsTableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) + + self?.newFeedViewController = nil + } + } } case .Feed: diff --git a/Yep/Views/Cells/Feed/FeedBasicCell.swift b/Yep/Views/Cells/Feed/FeedBasicCell.swift index 1cd1bec8..532e4a95 100644 --- a/Yep/Views/Cells/Feed/FeedBasicCell.swift +++ b/Yep/Views/Cells/Feed/FeedBasicCell.swift @@ -148,6 +148,7 @@ class FeedBasicCell: UITableViewCell { var touchesCancelledAction: (UITableViewCell -> Void)? var retryUploadingFeedAction: ((cell: FeedBasicCell) -> Void)? + var deleteUploadingFeedAction: ((cell: FeedBasicCell) -> Void)? override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -302,6 +303,12 @@ class FeedBasicCell: UITableViewCell { } } + uploadingErrorContainerView.deleteAction = { [weak self] in + if let strongSelf = self { + strongSelf.deleteUploadingFeedAction?(cell: strongSelf) + } + } + contentView.addSubview(uploadingErrorContainerView) } else { diff --git a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift index 58ed426e..4f8c1b5a 100644 --- a/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift +++ b/Yep/Views/ContainerViews/FeedUploadingErrorContainerView.swift @@ -11,6 +11,7 @@ import UIKit class FeedUploadingErrorContainerView: UIView { var retryAction: (() -> Void)? + var deleteAction: (() -> Void)? lazy var leftContainerView: UIView = { let view = UIView() @@ -35,7 +36,7 @@ class FeedUploadingErrorContainerView: UIView { let button = UIButton() button.setTitle(NSLocalizedString("Retry", comment: ""), forState: .Normal) button.setTitleColor(UIColor.yepTintColor(), forState: .Normal) - button.addTarget(self, action: "retry:", forControlEvents: .TouchUpInside) + button.addTarget(self, action: "retryUploadingFeed:", forControlEvents: .TouchUpInside) return button }() @@ -43,6 +44,7 @@ class FeedUploadingErrorContainerView: UIView { let button = UIButton() button.setTitle(NSLocalizedString("Delete", comment: ""), forState: .Normal) button.setTitleColor(UIColor.redColor(), forState: .Normal) + button.addTarget(self, action: "deleteUploadingFeed:", forControlEvents: .TouchUpInside) return button }() @@ -102,8 +104,12 @@ class FeedUploadingErrorContainerView: UIView { } } - @objc private func retry(sender: UIButton) { + @objc private func retryUploadingFeed(sender: UIButton) { retryAction?() } + + @objc private func deleteUploadingFeed(sender: UIButton) { + deleteAction?() + } } From 63ac808ef74a52277685b51399d16ae64ca36aae Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 15:05:58 +0800 Subject: [PATCH 31/32] disable staging --- Yep.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 5f4d5411..4c11e42b 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -2959,7 +2959,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING"; + OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING_"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; From 8cd506b98bcb519cf14e71379d98daaf10a15ca2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 6 Jan 2016 15:14:52 +0800 Subject: [PATCH 32/32] remove ModelTypes --- Yep.xcodeproj/project.pbxproj | 12 ----------- Yep/Protocols/ModelTypes.swift | 39 ---------------------------------- 2 files changed, 51 deletions(-) delete mode 100644 Yep/Protocols/ModelTypes.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 4c11e42b..32899474 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -327,7 +327,6 @@ 50F5AF961BBBCDA30033C9BC /* FeedMediaAddCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */; }; 50F5AF991BBBD02A0033C9BC /* FeedMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */; }; 50F5AF9A1BBBD02A0033C9BC /* FeedMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */; }; - 50F6D32A1C3B618200CB673C /* ModelTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F6D3291C3B618200CB673C /* ModelTypes.swift */; }; 50F6D32E1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F6D32D1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift */; }; 50FA9A441B661698009BF2A0 /* UIViewController+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */; }; 50FD753D1C1FB4AC0050A382 /* FPSLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */; }; @@ -698,7 +697,6 @@ 50F5AF941BBBCDA30033C9BC /* FeedMediaAddCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaAddCell.xib; path = Views/Cells/FeedMediaAdd/FeedMediaAddCell.xib; sourceTree = ""; }; 50F5AF971BBBD02A0033C9BC /* FeedMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedMediaCell.swift; path = Views/Cells/FeedMedia/FeedMediaCell.swift; sourceTree = ""; }; 50F5AF981BBBD02A0033C9BC /* FeedMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedMediaCell.xib; path = Views/Cells/FeedMedia/FeedMediaCell.xib; sourceTree = ""; }; - 50F6D3291C3B618200CB673C /* ModelTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ModelTypes.swift; path = Protocols/ModelTypes.swift; sourceTree = ""; }; 50F6D32D1C3CBE0000CB673C /* FeedUploadingErrorContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedUploadingErrorContainerView.swift; path = Views/ContainerViews/FeedUploadingErrorContainerView.swift; sourceTree = ""; }; 50FA9A431B661698009BF2A0 /* UIViewController+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIViewController+Yep.swift"; path = "Extensions/UIViewController+Yep.swift"; sourceTree = ""; }; 50FD753C1C1FB4AC0050A382 /* FPSLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FPSLabel.swift; path = Views/Labels/FPSLabel.swift; sourceTree = ""; }; @@ -830,7 +828,6 @@ 0AD7EA581AC3EAF300617758 /* Yep-Bridging-Header.h */, 50AFBF4F1BB3A5A1007D19DA /* Sounds */, 50E114F51ABBF9D100F13000 /* Realm */, - 50F6D3281C3B5FDB00CB673C /* Protocols */, 502AE53B1AB871C5005BD199 /* Helpers */, 502AE52C1AB819B5005BD199 /* Configs */, 502AE5251AB72BE9005BD199 /* Services */, @@ -2203,14 +2200,6 @@ name = FeedMedia; sourceTree = ""; }; - 50F6D3281C3B5FDB00CB673C /* Protocols */ = { - isa = PBXGroup; - children = ( - 50F6D3291C3B618200CB673C /* ModelTypes.swift */, - ); - name = Protocols; - sourceTree = ""; - }; 50FD75401C20FF940050A382 /* ContainerViews */ = { isa = PBXGroup; children = ( @@ -2767,7 +2756,6 @@ 50E1CE8E1BE0BFF00025B933 /* MediaViewCell.swift in Sources */, 50DEE0311BE339B000015741 /* LoadMoreTableViewCell.swift in Sources */, 50DEE0361BE3720F00015741 /* LoadMoreCollectionViewCell.swift in Sources */, - 50F6D32A1C3B618200CB673C /* ModelTypes.swift in Sources */, 504F41251ACE2D1D00FBB19A /* SampleView.swift in Sources */, 50E392C01C22B30300C0CECB /* FeedGithubRepoCell.swift in Sources */, 50A640EC1B6F4E420050E4A3 /* DoNotDisturbPeriodViewController.swift in Sources */, diff --git a/Yep/Protocols/ModelTypes.swift b/Yep/Protocols/ModelTypes.swift deleted file mode 100644 index 5c93eb31..00000000 --- a/Yep/Protocols/ModelTypes.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// ModelTypes.swift -// Yep -// -// Created by nixzhu on 16/1/5. -// Copyright © 2016年 Catch Inc. All rights reserved. -// - -import Foundation - -protocol UserType { - - var userID: String { get } - var username: String? { get } - var nickname: String { get } - var introduction: String { get } - var avatarURLString: String { get } - var badge: String? { get } - - var createdUnixTime: NSTimeInterval { get } - var lastSignInUnixTime: NSTimeInterval { get } - - var longitude: Double { get } - var latitude: Double { get } - - -} - -protocol FeedType { - - var feedID: String { get } - var allowComment: Bool { get } - var kind: FeedKind? { get } - - var createdUnixTime: NSTimeInterval { get } - var updatedUnixTime: NSTimeInterval { get } - - var creator: UserType? { get } -} \ No newline at end of file