-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebarViewController.m
executable file
·417 lines (282 loc) · 17.3 KB
/
SidebarViewController.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
//
// SidebarViewController.m
// SidebarDemo
//
// Created by Simon on 29/6/13.
// Copyright (c) 2013 Appcoda. All rights reserved.
//
#import "SidebarViewController.h"
#import "SWRevealViewController.h"
#import "MenuCell.h"
#import "ContactUs_ViewController.h"
#import "AboutUs_ViewController.h"
#import "SWRevealViewController.h"
#import "Featured_ViewController.h"
#import "Product_ViewController.h"
#import "SubscriptionController.h"
#import "Payment_ViewController.h"
#import "HistoryController.h"
#import "FAQ_ViewController.h"
#import "Login_ViewController.h"
#import "MBProgressHUD.h"
#import "DBManager.h"
#import "CreditController.h"
#import "MBProgressHUD.h"
#import "AppDelegate.h"
#import "StringConstants.h"
@interface SidebarViewController ()<MBProgressHUDDelegate>{
NSString *login_str,*userid;
NSMutableArray *menulist,*menuimg;
MBProgressHUD *HUD;
}
@property (nonatomic, strong) DBManager *dbManager;
@end
@implementation SidebarViewController {
NSArray *menuItems;
NSArray *menuItems1;
NSString *name;
NSString *fullname;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.dbManager = [[DBManager alloc] initWithDatabaseFilename:@"KRCS1.sqlite"];
[disbtn addTarget:self action:@selector(disbtn:) forControlEvents:UIControlEventTouchUpInside];
emailstr.text=[self get_shareddata:@"Login"];
namestr.text=[self get_shareddata:@"Name"];
menuvw.hidden=YES;
userid=[self get_shareddata:@"ID"];
menulist=[[NSMutableArray alloc]initWithObjects:@"Inicio",@"Entregas",@"Produtos",@"Carrinho",@"Histórico",@"FAQ",@"Contacte-nos",@"Sobre Nós",@"Sair",nil];
menuimg=[[NSMutableArray alloc]initWithObjects:@"icon_home.png",@"my_order.png",@"icon_product.png",@"icon_cart.png",@"order_history.png",@"icon_faq.png",@"icon_contact.png",@"icon_aboutUs.png",@"Logout Rounded Up-48.png", nil];
name=[self get_shareddata:@"Login"];
NSLog(@"nameeee %@",name);
emailstr.text=name;
fullname=[self get_shareddata:@"Name"];
NSLog(@"nameeee %@",fullname);
namestr.text=fullname;
menulist=[[NSMutableArray alloc]initWithObjects:@"Inicio",@"Entregas",@"Produtos",@"Carrinho",@"Histórico",@"Comprar crédito",@"FAQ",@"Contacte-nos",@"Sobre Nós",@"Sair",nil];
menuimg=[[NSMutableArray alloc]initWithObjects:@"icon_home.png",@"my_order.png",@"icon_product.png",@"icon_cart.png",@"order_history.png",@"ic_wallet.png",@"icon_faq.png",@"icon_contact.png",@"icon_aboutUs.png",@"Logout Rounded Up-48.png", nil];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
walletstr.text=[NSString stringWithFormat:@"Saldo : %@€",[self get_shareddata:@"wallet"]];
[self wallet];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
}
// get SHARED PREference
-(NSString *)get_shareddata:(NSString *)key{
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
NSString *currentLevelKey = key;
NSString *currentLevel=@"";
if ([preferences objectForKey:currentLevelKey] == nil)
{
// Doesn't exist.
// Doctor_ViewController *after_reg1= [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Doctor_ViewController"];
//
// // after_reg1.data=usr1;
// [self.navigationController pushViewController:after_reg1 animated:NO];
}
else
{
// Get current level
currentLevel = [preferences stringForKey:currentLevelKey];
}
return currentLevel;
}
- (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;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [menulist count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
menu.separatorStyle = UITableViewCellSeparatorStyleNone;
static NSString *identifier = @"MenuCell";
MenuCell *cell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.name.text=[menulist objectAtIndex:indexPath.row];
cell.img.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[menuimg objectAtIndex:indexPath.row]]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row== 0){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
Featured_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Featured_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row == 1){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SubscriptionController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"SubscriptionController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 2){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
Product_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Product_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 3){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
Payment_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Payment_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 4){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
HistoryController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"HistoryController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 5){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
CreditController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"CreditController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
// if(indexPath.row== 6){
// CreditController *event= [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CreditController"];
// [self.navigationController pushViewController:event animated:NO];
//
// }
if(indexPath.row== 6){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
FAQ_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"FAQ_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 7){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ContactUs_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ContactUs_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 8){
UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AboutUs_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"AboutUs_ViewController"];
SWRevealViewController *revealController = self.revealViewController;
[revealController setFrontViewController:view];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
if(indexPath.row== 9){
// [self.revealViewController performSelector:@selector(revealToggle:) withObject:nil];
[self delete];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
[[NSUserDefaults standardUserDefaults] synchronize];
// UIStoryboard* mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//
// Login_ViewController *view = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Login_ViewController"];
// SWRevealViewController *revealController = self.revealViewController;
//
// [revealController setFrontViewController:view];
// [self.revealViewController.navigationController pushViewController:view animated:YES];
[[AppDelegate sharedAppDelegate]login];
}
menuvw.hidden=YES;
}
-(void)delete{
NSString *query = [NSString stringWithFormat:@"delete from CardManager"];
[self.dbManager executeQuery:query];
}
-(void)wallet{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSString *path = [NSString stringWithFormat:@"%@get_wallet", BASE_URL];
NSLog(@"%@",path);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:path]];
[request setHTTPMethod:@"POST"];
NSLog(@"%@",request);
NSString *value = [NSString stringWithFormat:@"&userid=%@",[self get_shareddata:@"ID"]];
NSLog(@"value:%@",value);
value = [value stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
// value = [value stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
[request setHTTPBody:[value dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *dataTask =[defaultSession dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
[HUD hide:YES];
if (!connectionError || data.length > 0) {
NSLog(@"going to process");
NSArray* userdetails = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&connectionError];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"returnDictionary = %@", userdetails);
NSString *successs = [NSString stringWithFormat:@"%@",[userdetails valueForKey:@"status"]];
NSString *message = [NSString stringWithFormat:@"%@",[userdetails valueForKey:@"msg"]];
// [self.view makeToast:message duration:3.0 position:CSToastPositionBottom];
if([successs isEqualToString:@"1"]){
NSString *wall=[NSString stringWithFormat:@"%@",[userdetails valueForKey:@"total"]];
[self sharedata:@"wallet" :wall];
// walletstr.text=[NSString stringWithFormat:@"Saldo : %@€",[userdetails valueForKey:@"total"]];
}
});
[HUD hide:YES];
}
else if ([data length] == 0 && connectionError == nil){
NSLog(@"no data returned");
// [self.view makeToast:@"Verifique a conexão com a Internet" duration:3.0 position:CSToastPositionBottom];
//no data, but tried
}
else if (connectionError != nil)
{
NSLog(@"there was a download error");
// [self.view makeToast:@"Verifique a conexão com a Internet" duration:3.0 position:CSToastPositionBottom]; //couldn't download
}
}];
[dataTask resume];
}
-(void)sharedata:(NSString*)key :(NSString*)value{
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
NSString *currentLevelKey = key;
const NSString *currentLevel = value;
[preferences setValue:currentLevel forKey:currentLevelKey];
// Save to disk
const BOOL didSave = [preferences synchronize];
NSLog(@"key =====: %@", key);
NSLog(@"value =====: %@", value);
if (!didSave)
{
value=@"";
// Couldn't save (I've never seen this happen in real world testing)
}
}
@end