Skip to content

Commit

Permalink
Merge branch 'feature/meet_geniuses2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Jul 1, 2016
2 parents 1e2014a + 710f152 commit 64be4c0
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 25 deletions.
13 changes: 11 additions & 2 deletions Yep/ViewControllers/Discover/Discover.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,23 @@
<viewControllerPlaceholder storyboardName="Profile" referencedIdentifier="ProfileViewController" id="Mso-uB-5h2" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="2y7-Gv-1UV" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1015" y="379"/>
<point key="canvasLocation" x="1015" y="397"/>
</scene>
<!--GeniusInterviewViewController-->
<scene sceneID="rFU-Ru-Gmf">
<objects>
<viewControllerPlaceholder storyboardName="GeniusInterview" referencedIdentifier="GeniusInterviewViewController" id="mSt-h3-goH" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="et6-lG-1Em" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1044.5" y="299"/>
<point key="canvasLocation" x="1044.5" y="287"/>
</scene>
<!--ConversationViewController-->
<scene sceneID="dCv-9T-haP">
<objects>
<viewControllerPlaceholder storyboardName="Conversation" referencedIdentifier="ConversationViewController" id="HA2-lz-fqY" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="LRr-ry-DWX" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1105" y="342"/>
</scene>
<!--Discover Container View Controller-->
<scene sceneID="O2C-is-rbL">
Expand Down Expand Up @@ -159,6 +167,7 @@
<outlet property="segmentedControl" destination="pIA-g9-MZ7" id="3w9-pT-zy3"/>
<segue destination="Mso-uB-5h2" kind="show" identifier="showProfile" id="xMr-kL-ECd"/>
<segue destination="mSt-h3-goH" kind="show" identifier="showGeniusInterview" id="4mo-zj-Hna"/>
<segue destination="HA2-lz-fqY" kind="show" identifier="showConversation" id="cnD-K9-H6x"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="T4l-ea-p2b" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
64 changes: 58 additions & 6 deletions Yep/ViewControllers/Discover/DiscoverContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import YepKit
import RealmSwift

class DiscoverContainerViewController: UIViewController {

Expand Down Expand Up @@ -92,7 +93,7 @@ class DiscoverContainerViewController: UIViewController {
geniusesContainerView.hidden = true
discoveredUsersContainerView.hidden = false

navigationItem.leftBarButtonItem = discoveredUsersLayoutModeButtonItem
//navigationItem.leftBarButtonItem = discoveredUsersLayoutModeButtonItem
navigationItem.rightBarButtonItem = discoveredUsersFilterButtonItem
}
}
Expand All @@ -101,10 +102,10 @@ class DiscoverContainerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

navigationItem.titleView = nil
navigationItem.title = NSLocalizedString("Discover", comment: "")
//navigationItem.titleView = nil
//navigationItem.title = NSLocalizedString("Discover", comment: "")

currentOption = .FindAll
currentOption = .MeetGenius

segmentedControl.selectedSegmentIndex = currentOption.rawValue
segmentedControl.addTarget(self, action: #selector(DiscoverContainerViewController.chooseOption(_:)), forControlEvents: .ValueChanged)
Expand Down Expand Up @@ -158,9 +159,13 @@ class DiscoverContainerViewController: UIViewController {
case "embedMeetGenius":
let vc = segue.destinationViewController as! MeetGeniusViewController

vc.showGeniusInterviewAction = {
vc.tapBannerAction = { [weak self] url in
self?.yep_openURL(url)
}

vc.showGeniusInterviewAction = { geniusInterview in
SafeDispatch.async { [weak self] in
self?.performSegueWithIdentifier("showGeniusInterview", sender: nil)
self?.performSegueWithIdentifier("showGeniusInterview", sender: Box<GeniusInterview>(geniusInterview))
}
}

Expand Down Expand Up @@ -190,6 +195,53 @@ class DiscoverContainerViewController: UIViewController {
let discoveredUser = (sender as! Box<DiscoveredUser>).value
prepareProfileViewController(vc, withDiscoveredUser: discoveredUser)

case "showGeniusInterview":

let vc = segue.destinationViewController as! GeniusInterviewViewController

let geniusInterview = (sender as! Box<GeniusInterview>).value
vc.geniusInterview = geniusInterview

vc.tapAvatarAction = { user in

SafeDispatch.async { [weak self] in
self?.performSegueWithIdentifier("showProfile", sender: Box<DiscoveredUser>(user))
}
}

vc.sayHiAction = {user in

SafeDispatch.async { [weak self] in

guard let realm = try? Realm() else {
return
}

realm.beginWrite()
let conversation = conversationWithDiscoveredUser(user, inRealm: realm)
_ = try? realm.commitWrite()

if let conversation = conversation {
self?.performSegueWithIdentifier("showConversation", sender: conversation)

NSNotificationCenter.defaultCenter().postNotificationName(Config.Notification.changedConversation, object: nil)
}
}
}

vc.shareAction = { url in

SafeDispatch.async { [weak self] in
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self?.presentViewController(activityViewController, animated: true, completion: nil)
}
}

case "showConversation":

let vc = segue.destinationViewController as! ConversationViewController
vc.conversation = sender as! Conversation

default:
break
}
Expand Down
117 changes: 112 additions & 5 deletions Yep/ViewControllers/Discover/MeetGeniusViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@

import UIKit
import YepKit
import YepNetworking

class MeetGeniusViewController: UIViewController {

var showGeniusInterviewAction: (() -> Void)?
var tapBannerAction: ((url: NSURL) -> Void)?
var showGeniusInterviewAction: ((geniusInterview: GeniusInterview) -> Void)?

@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.tableHeaderView = MeetGeniusShowView(frame: CGRect(x: 0, y: 0, width: 100, height: 180))
let view = MeetGeniusShowView(frame: CGRect(x: 0, y: 0, width: 100, height: 180))
view.tapAction = { [weak self] url in
self?.tapBannerAction?(url: url)
}

tableView.tableHeaderView = view
tableView.tableFooterView = UIView()

tableView.rowHeight = 90
Expand All @@ -28,13 +35,108 @@ class MeetGeniusViewController: UIViewController {
var geniusInterviews: [GeniusInterview] = []

private var canLoadMore: Bool = false
private var isFetchingGeniusInterviews: Bool = false

override func viewDidLoad() {
super.viewDidLoad()

println("tableView.tableHeaderView: \(tableView.tableHeaderView)")

updateGeniusInterviews()
}

private enum UpdateGeniusInterviewsMode {
case Top
case LoadMore
}

private func updateGeniusInterviews(mode mode: UpdateGeniusInterviewsMode = .Top, finish: (() -> Void)? = nil) {

if isFetchingGeniusInterviews {
finish?()
return
}

isFetchingGeniusInterviews = true

let maxNumber: Int?
switch mode {
case .Top:
canLoadMore = true
maxNumber = nil
case .LoadMore:
maxNumber = geniusInterviews.last?.number
}

let failureHandler: FailureHandler = { reason, errorMessage in

SafeDispatch.async { [weak self] in

self?.isFetchingGeniusInterviews = false

finish?()
}

defaultFailureHandler(reason: reason, errorMessage: errorMessage)
}

let count = 5
geniusInterviewsWithCount(count, afterNumber: maxNumber, failureHandler: failureHandler, completion: { [weak self] geniusInterviews in

SafeDispatch.async { [weak self] in

guard let strongSelf = self else {
return
}

strongSelf.canLoadMore = (geniusInterviews.count == count)

let newGeniusInterviews = geniusInterviews
let oldGeniusInterviews = strongSelf.geniusInterviews

var wayToUpdate: UITableView.WayToUpdate = .None

if oldGeniusInterviews.isEmpty {
wayToUpdate = .ReloadData
}

switch mode {

case .Top:
strongSelf.geniusInterviews = newGeniusInterviews

wayToUpdate = .ReloadData

case .LoadMore:
let oldGeniusInterviewsCount = oldGeniusInterviews.count

let oldGeniusInterviewNumberSet = Set<Int>(oldGeniusInterviews.map({ $0.number }))
var realNewGeniusInterviews = [GeniusInterview]()
for geniusInterview in newGeniusInterviews {
if !oldGeniusInterviewNumberSet.contains(geniusInterview.number) {
realNewGeniusInterviews.append(geniusInterview)
}
}
strongSelf.geniusInterviews += realNewGeniusInterviews

let newGeniusInterviewsCount = strongSelf.geniusInterviews.count

let indexPaths = Array(oldGeniusInterviewsCount..<newGeniusInterviewsCount).map({ NSIndexPath(forRow: $0, inSection: Section.GeniusInterview.rawValue) })
if !indexPaths.isEmpty {
wayToUpdate = .Insert(indexPaths)
}
}

wayToUpdate.performWithTableView(strongSelf.tableView)

self?.isFetchingGeniusInterviews = false

finish?()
}
})
}


/*
// MARK: - Navigation

Expand Down Expand Up @@ -72,7 +174,7 @@ extension MeetGeniusViewController: UITableViewDataSource, UITableViewDelegate {
return geniusInterviews.count

case .LoadMore:
return 1
return geniusInterviews.isEmpty ? 0 : 1
}
}

Expand Down Expand Up @@ -124,7 +226,11 @@ extension MeetGeniusViewController: UITableViewDataSource, UITableViewDelegate {
cell.isLoading = true
}

// TODO
updateGeniusInterviews(mode: .LoadMore, finish: {
delay(0.5) { [weak cell] in
cell?.isLoading = false
}
})
}
}

Expand All @@ -141,7 +247,8 @@ extension MeetGeniusViewController: UITableViewDataSource, UITableViewDelegate {
switch section {

case .GeniusInterview:
showGeniusInterviewAction?()
let geniusInterview = geniusInterviews[indexPath.row]
showGeniusInterviewAction?(geniusInterview: geniusInterview)

case .LoadMore:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@

import UIKit
import WebKit
import YepKit

class GeniusInterviewViewController: UIViewController {

var geniusInterview: GeniusInterview!

var tapAvatarAction: ((user: DiscoveredUser) -> Void)?
var sayHiAction: ((user: DiscoveredUser) -> Void)?
var shareAction: ((url: NSURL) -> Void)?

lazy var webView: WKWebView = {

let view = WKWebView()
Expand All @@ -20,9 +27,6 @@ class GeniusInterviewViewController: UIViewController {
view.scrollView.contentInset.bottom = 50
view.scrollView.delegate = self

let request = NSURLRequest(URL: NSURL(string: "https://soyep.com")!)
view.loadRequest(request)

return view
}()

Expand All @@ -38,15 +42,24 @@ class GeniusInterviewViewController: UIViewController {

let view = GeniusInterviewActionView()

view.tapAvatarAction = {
view.tapAvatarAction = { [weak self] in
if let user = self?.geniusInterview.user {
self?.tapAvatarAction?(user: user)
}
println("tapAvatarAction")
}

view.sayHiAction = {
view.sayHiAction = { [weak self] in
if let user = self?.geniusInterview.user {
self?.sayHiAction?(user: user)
}
println("sayHiAction")
}

view.shareAction = {
view.shareAction = { [weak self] in
if let url = self?.geniusInterview.url {
self?.shareAction?(url: url)
}
println("shareAction")
}

Expand Down Expand Up @@ -91,6 +104,16 @@ class GeniusInterviewViewController: UIViewController {
let height = actionView.heightAnchor.constraintEqualToConstant(50)
NSLayoutConstraint.activateConstraints([leading, trailing, top, height])
}

do {
let request = NSURLRequest(URL: geniusInterview.url)
webView.loadRequest(request)
}

do {
let avatar = PlainAvatar(avatarURLString: geniusInterview.user.avatarURLString, avatarStyle: miniAvatarStyle)
actionView.avatarImageView.navi_setAvatar(avatar, withFadeTransitionDuration: avatarFadeTransitionDuration)
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion Yep/Views/Cells/GeniusInterview/GeniusInterviewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class GeniusInterviewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()

numberLabel.font = UIFont.systemFontOfSize(16)
numberLabel.textColor = UIColor.yepTintColor()

titleLabel.font = UIFont.systemFontOfSize(16)
titleLabel.textColor = UIColor.blackColor()

detailLabel.font = UIFont.systemFontOfSize(13)
detailLabel.textColor = UIColor(red: 142/255.0, green: 142/255.0, blue: 147/255.0, alpha: 1)

accessoryImageView.tintColor = UIColor.yepCellAccessoryImageViewTintColor()
}

Expand All @@ -35,7 +44,7 @@ class GeniusInterviewCell: UITableViewCell {
let avatar = PlainAvatar(avatarURLString: geniusInterview.user.avatarURLString, avatarStyle: miniAvatarStyle)
avatarImageView.navi_setAvatar(avatar, withFadeTransitionDuration: avatarFadeTransitionDuration)

numberLabel.text = String(format: "#%03d", geniusInterview.number)
numberLabel.text = String(format: "#%02d", geniusInterview.number)
titleLabel.text = geniusInterview.title
detailLabel.text = geniusInterview.detail
}
Expand Down
Loading

0 comments on commit 64be4c0

Please sign in to comment.