-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatDemoViewController.m
executable file
·245 lines (170 loc) · 5.85 KB
/
ChatDemoViewController.m
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//
// ChatDemoViewController.m
// ChatDemo
//
// Created by Charlene Jiang on 10/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ChatDemoViewController.h"
#import "QuartzCore/QuartzCore.h"
#import "ExampleViewController.h"
#import "LoginViewController.h"
#import "ChatDemoAppDelegate.h"
#import "SBJSON.h"
//#import "ASIHTTPRequest.h"
@implementation ChatDemoViewController
@synthesize cell;
@synthesize slideButton;
@synthesize chatButton;
@synthesize photoButton;
@synthesize searchField;
@synthesize keyword;
@synthesize examplesButton;
@synthesize username;
NSString *placeholder;
NSString *placeholder2;
NSString *placeholder3;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
//sets up buttons
searchField.returnKeyType = UIReturnKeySearch;
slideButton.hidden = YES;
photoButton.hidden = YES;
[examplesButton setHighlighted:YES];
ChatDemoAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (FBSession.activeSession.isOpen)
{
NSLog(@"Session is still open");
}
//new way of getting pic and name
[self populateUserDetails];
//removes keyboard on touch up outside
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[tap setCancelsTouchesInView:NO];
[self.view addGestureRecognizer:tap];
}
-(void)dismissKeyboard
{
[searchField resignFirstResponder];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
///new way of getting usename and pic
- (void)populateUserDetails {
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
self.username.text = user.name;
// self.userProfileImage.profileID = [user objectForKey:@"id"];
}
}];
}
}
- (void)getUsername:(NSString*)log
{
placeholder = log;
NSLog(@"its youuu %@", placeholder);
}
- (void)getId:(NSString*)log
{
placeholder2 = log;
NSLog(@"its youuu2 %@", placeholder2);
}
- (void)getAccessKey:(NSString*)log
{
placeholder3 = log;
NSLog(@"its youuu3 %@", placeholder3);
}
- (IBAction)chatButtonAction:(id)sender
{
}
- (IBAction) search
{
//If you search for a keyword
NSString *keyword2 = [[NSString alloc] initWithString:searchField.text];
keyword = keyword2;
NSLog(@"The search term is %@", keyword);
if (FBSession.activeSession.isOpen) {
NSLog(@"Its still open!");
}
//publish to facebook///
[self postToWall];
//send it to the new chatview
[ChatTableViewController getString:keyword];
chatController = [[ChatTableViewController alloc] init];
//switch views
UIView *newView = chatController.view;
UIView *theWindow = [UIApplication sharedApplication].keyWindow;
[theWindow insertSubview:newView atIndex:0];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:[self.view superview] cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1];
[[self.view superview] exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[UIView commitAnimations];
}
- (void) postToWall
{
ChatDemoAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
//open a session
//Get the active session working first, then worry about publishing actions like this.
/*
//blab about namespace: action, object
if (appDelegate.session.isOpen)
{
// Get the object representing the blab
id<BlabTopic> topic = (id<BlabTopic>)[FBGraphObject graphObject];
topic.url = @"http://www.blabsay.com";
id<BlabAction> action = (id<BlabAction>)[FBGraphObject graphObject];
action.topic = topic;
//Publish Action
[FBRequestConnection startForPostWithGraphPath:@"me/blabbing:blab_about"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (!error)
{
NSLog(@"Published order action: %@", [result objectForKey:@"id"]);
}
}];
}
else
{
NSLog(@"Session is not open bitch");
}
*/
}
- (IBAction) examples
{
//view to switch too
ExampleViewController *example = [[ExampleViewController alloc] init];
[self presentViewController:example animated:YES completion:NULL];
[examplesButton setHighlighted:YES];
}
- (void)highlightButton:(UIButton *)b {
}
@end