forked from LabPLC/DejateCaer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuViewController.m
372 lines (302 loc) · 13.5 KB
/
MenuViewController.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
//
// MenuViewController.m
// DejateCaer
//
// Created by Carlos Castellanos on 19/03/14.
// Copyright (c) 2014 Carlos Castellanos. All rights reserved.
//
#import "MenuViewController.h"
#import "SWRevealViewController.h"
#import "AppDelegate.h"
@interface MenuViewController ()
@property (nonatomic, strong)IBOutlet UITableView *tabla;
@property (nonatomic, strong) IBOutlet UIImageView *foto_perfil;
@property (nonatomic, strong) IBOutlet FBProfilePictureView *foto_perfil1;
@property (nonatomic, assign) BOOL tw;
@end
@implementation MenuViewController
{
NSArray *menuItems;
AppDelegate *delegate;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
delegate= (AppDelegate *) [[UIApplication sharedApplication] delegate];
_tw=FALSE;
/*
_tabla= [[UITableView alloc] init];
_tabla.delegate = self;
_tabla.dataSource = self;
[_tabla registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
_tabla.frame = self.view.bounds;
//añadimos el menu a la vista actual
CGRect frame;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
frame.origin.x=0;
frame.origin.y=150;
_tabla.frame=frame;
_tabla.scrollEnabled = NO;
// CGRectMake(0, 150,self.view.frame.size.width , self.view.frame.size.height)];
[self.view addSubview:_tabla]; */
_tabla.backgroundColor=[UIColor redColor];
_tabla.scrollEnabled = NO;
menuItems = @[@"Eventos", @"Mis Eventos", @"Agregar Evento", @"Configuraciones"];
[super viewDidLoad];
//Añadimos boton de fb
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate = self;
loginView.readPermissions = @[@"basic_info", @"email", @"user_likes"];
// Align the button in the center horizontally
CGRect frame_fb;
frame_fb.size.height=35;//self.view.frame.size.height;
frame_fb.size.width=213;
frame_fb.origin.x=20;
frame_fb.origin.y=411;
loginView.frame=frame_fb;
[self.view addSubview:loginView];
//
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
/*UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [menuItems objectAtIndex:indexPath.row]];
cell.textLabel.text = menuItems[indexPath.row];
*/
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [_tabla indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];
// Set the photo if it navigates to the PhotoView
/*if ([segue.identifier isEqualToString:@"showPhoto"]) {
PhotoViewController *photoController = (PhotoViewController*)segue.destinationViewController;
NSString *photoFilename = [NSString stringWithFormat:@"%@_photo.jpg", [menuItems objectAtIndex:indexPath.row]];
photoController.photoFilename = photoFilename;
} */
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
/*-(IBAction)twitter:(id)sender{
menuItems = @[@"Eventos", @"Configuraciones"];
[_tabla reloadData];
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=88;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
}*/
-(IBAction)fb:(id)sender{
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
menuItems = @[@"Eventos", @"Mis Eventos", @"Agregar Evento", @"Configuraciones"];
[_tabla reloadData];
}
//metodos de FB
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[FBLoginView class];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
self.foto_perfil1.profileID = user.id;
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
menuItems = @[@"Eventos", @"Mis Eventos", @"Agregar Evento", @"Configuraciones"];
[_tabla reloadData];
[self performSelector:@selector(getImage) withObject:nil afterDelay:3];
NSLog(@"%@", user.name);
}
-(void)getImage{
UIImage *image2 = nil;
for (NSObject *obj in [self.foto_perfil1 subviews]) {
if ([obj isMemberOfClass:[UIImageView class]]) {
UIImageView *objImg = (UIImageView *)obj;
image2 = objImg.image;
break;
}
}
self.foto_perfil.image=image2;
self.foto_perfil.layer.cornerRadius = image2.size.width / 2;
//self.foto_perfil.layer.cornerRadius = 2000;
UIGraphicsBeginImageContextWithOptions( self.foto_perfil.bounds.size, NO, [UIScreen mainScreen].scale);
// Add a clip before drawing anything, in the shape of an rounded rect
[[UIBezierPath bezierPathWithRoundedRect: self.foto_perfil.bounds
cornerRadius:50.0] addClip];
// Draw your image
[image2 drawInRect: self.foto_perfil.bounds];
// Get the image, here setting the UIImageView image
self.foto_perfil.image = UIGraphicsGetImageFromCurrentImageContext();
// Lets forget about that we were drawing
UIGraphicsEndImageContext();
}
// Logged-out user experience
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
self.foto_perfil1.profileID=nil;//[UIImage imageNamed:@"sin_perfil.jpg"];
[self performSelector:@selector(getImage) withObject:nil afterDelay:1];
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
menuItems = @[@"Eventos", @"Configuraciones"];
[_tabla reloadData]; // self.nameLabel.text = @"";
//self.statusLabel.text= @"You're not logged in!";
}
// twitter
-(IBAction)twitter:(id)sender
{
if (_tw) {
self.foto_perfil1.profileID=nil;//[UIImage imageNamed:@"sin_perfil.jpg"];
[self performSelector:@selector(getImage) withObject:nil afterDelay:1];
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
menuItems = @[@"Eventos", @"Configuraciones"];
[_tabla reloadData];
_tw=FALSE;
}
else{
_tw=TRUE;
// Request access to the Twitter accounts
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
// Check if the users has setup at least one Twitter account
if (accounts.count > 0)
{
ACAccount *twitterAccount = [accounts objectAtIndex:0];
// Creating a request to get the info about a user on Twitter
NSString *d=twitterAccount.username;
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"] parameters:[NSDictionary dictionaryWithObject:@"rockarloz" forKey:@"screen_name"]];
[twitterInfoRequest setAccount:twitterAccount];
// Making the request
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the reate limit
if ([urlResponse statusCode] == 429) {
NSLog(@"Rate limit reached");
return;
}
// Check if there was an error
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
// Check if there is some response data
if (responseData) {
NSError *error = nil;
NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
NSString *profileImageStringURL = [(NSDictionary *)TWData objectForKey:@"profile_image_url_https"];
// Get the profile image in the original resolution
profileImageStringURL = [profileImageStringURL stringByReplacingOccurrencesOfString:@"_normal" withString:@""];
[self getProfileImageForURLString:profileImageStringURL];
}
});
}];
}
} else {
NSLog(@"No access granted");
}
}];
}
}
- (void) getProfileImageForURLString:(NSString *)urlString;
{
CGRect frame;
frame.origin.x=0;
frame.origin.y=150;
frame.size.height=176;//self.view.frame.size.height;
frame.size.width=self.view.frame.size.width;
_tabla.frame=frame;
menuItems = @[@"Eventos", @"Mis Eventos", @"Agregar Evento", @"Configuraciones"];
[_tabla reloadData];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
self.foto_perfil.image = [UIImage imageWithData:data];
/*self.foto_perfil.layer.cornerRadius = self.foto_perfil.image .size.width / 2;
UIGraphicsBeginImageContextWithOptions( self.foto_perfil.bounds.size, NO, [UIScreen mainScreen].scale);
[[UIBezierPath bezierPathWithRoundedRect: self.foto_perfil.bounds
cornerRadius:50.0] addClip];
[self.foto_perfil.image drawInRect: self.foto_perfil.bounds];
self.foto_perfil.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();*/
}
- (IBAction) slideRadioChangee:(UISlider *)sender {
int radio = [[NSString stringWithFormat:@" %.1f", [sender value]] doubleValue]*10000;
delegate.user_radio=[NSString stringWithFormat:@"%i",radio];
if (radio==0) {
radio=500;
}
if (radio>=1000) {
radio=radio/1000;
_radiolbl.text= [NSString stringWithFormat:@"%i kms.",radio];
}
else{
_radiolbl.text= [NSString stringWithFormat:@"%i mts.",radio];
}
NSLog(@"%i",radio );
}
@end