-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileViewController.swift
More file actions
175 lines (146 loc) · 6.72 KB
/
ProfileViewController.swift
File metadata and controls
175 lines (146 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// ProfileViewController.swift
// twitterApp
//
// Created by Deepak on 10/5/14.
// Copyright (c) 2014 Deepak. All rights reserved.
//
import UIKit
class ProfileViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, MentionsViewDelegate {
var tweets: [Tweet]?
var user = User.currentUser?
var current_user: User?
var newUser: User?
var refreshControl:UIRefreshControl!
var containerVC: ContainerViewController!
var mentionView: Bool?
@IBOutlet var profileImage: UIImageView!
@IBOutlet var profileName: UILabel!
@IBOutlet var profileScreenname: UILabel!
@IBOutlet var profilePageControl: UIPageControl!
@IBOutlet var profileHeaderView: UIView!
@IBOutlet var profileBGImage: UIImageView!
@IBOutlet var numTweets: UILabel!
@IBOutlet var numFollowing: UILabel!
@IBOutlet var numFollowers: UILabel!
@IBOutlet var TweetsView: UIView!
@IBOutlet var FollowingView: UIView!
@IBOutlet var FollowersView: UIView!
@IBOutlet var TweetsViewWidthConstraint: NSLayoutConstraint!
@IBOutlet var FollowingViewWidthConstraint: NSLayoutConstraint!
@IBOutlet var FollowersViewWidthConstraint: NSLayoutConstraint!
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 120.0
var storyboard = UIStoryboard(name: "Main", bundle: nil)
containerVC = storyboard.instantiateViewControllerWithIdentifier("ContainerViewController") as ContainerViewController
containerVC.delegate = self
self.navigationController?.navigationBar.barTintColor = UIColorFromRGB(0x55ACEE)
if (newUser != nil) {
current_user = self.newUser
} else {
current_user = User.currentUser
}
// Do any additional setup after loading the view.
profileName.text = current_user?.name
profileScreenname.text = "@\((current_user?.screenname)!)"
if let url = current_user?.profileImageUrl {
var request = NSURLRequest(URL: NSURL(string: url))
profileImage.setImageWithURLRequest(request, placeholderImage: nil ,
success: { (request, response, image) -> Void in
//println(response)
self.profileImage.image = image
var layer = self.profileImage.layer as CALayer
layer.cornerRadius = 8.0
layer.masksToBounds = true
}, failure: { (request, response, error) -> Void in
println(error)
})
}
if let BGurl = current_user?.profileBackgroundImageUrl {
profileBGImage.setImageWithURL(NSURL(string: BGurl))
}
numTweets.text = current_user?.numTweets?.stringValue
numFollowers.text = current_user?.numFollowers?.stringValue
numFollowing.text = current_user?.numFollowing?.stringValue
var boxWidth = profileHeaderView.frame.width/3
TweetsViewWidthConstraint.constant = boxWidth as CGFloat
FollowersViewWidthConstraint.constant = boxWidth as CGFloat
FollowingViewWidthConstraint.constant = boxWidth as CGFloat
TweetsView.backgroundColor = UIColorFromRGB(0xCCD6DD)
FollowingView.backgroundColor = UIColorFromRGB(0x8899A6)
FollowersView.backgroundColor = UIColorFromRGB(0x66757F)
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.labelText = "loading .."
hud.show(true)
// Do any additional setup after loading the view.
//var params = [ "include_rts" : true , "trim_user" : false]
var params: [String:String] = [String:String]()
params["screen_name"] = current_user?.screenname
if (self.mentionView == nil ) {
TwitterClient.sharedInstance.userTimeLineWithParams(params, completion: {(tweets, error) -> () in
self.tweets = tweets
self.tableView.reloadData()
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
})
} else {
println("calling mentionsWithParams")
TwitterClient.sharedInstance.mentionsWithParams(params, completion: {(tweets, error) -> () in
self.tweets = tweets
self.tableView.reloadData()
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
})
}
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refersh")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
}
@IBAction func onCancel(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tweets?.count ?? 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("TweetCell") as TweetCell
var tweet = self.tweets?[indexPath.row]
cell.tweet = tweet
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func refresh(refreshControl : UIRefreshControl)
{
var hud = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
hud.labelText = "loading .."
hud.show(true)
// Code to refresh table view
TwitterClient.sharedInstance.userTimeLineWithParams(nil, completion: {(tweets, error) -> () in
self.tweets = tweets
self.tableView.reloadData()
self.refreshControl.endRefreshing()
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
})
}
func MentionsViewRequested(value: Bool) -> Void {
println("Inside MentionsViewRequested delegate")
if(value == true) {
self.mentionView = true
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}