This repository has been archived by the owner on Aug 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSupportersVC.m
163 lines (141 loc) · 5.26 KB
/
SupportersVC.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
//
// SupportersVC.m
// CancerLife
//
// Created by Constantin Lungu on 11/7/13.
// Copyright (c) 2013 FusionWorks. All rights reserved.
//
#import "SupportersVC.h"
#import "AFHTTPRequestOperationManager.h"
#import "SupporterCell.h"
#import "AppDelegate.h"
#import "MBProgressHUD.h"
#import "InviteSupporterVC.h"
#import "Defines.h"
@interface SupportersVC ()
{
AppDelegate* _appDel;
NSArray* _supporters;
}
- (void) setupView;
- (void) setupNavigationButtons;
@end
@implementation SupportersVC
#pragma mark -
#pragma mark - View Controller's Lifecycle
- (MFSideMenuContainerViewController*) menuContainerViewController
{
return (MFSideMenuContainerViewController*)_appDel.window.rootViewController;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_appDel = (AppDelegate*) [UIApplication sharedApplication].delegate;
[self setupView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark - Private API
- (void) setupView
{
[self setupNavigationButtons];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestSerializer* serializer = [AFHTTPRequestSerializer serializer];
[serializer setValue:_appDel.authToken forHTTPHeaderField:@"token"];
[manager setRequestSerializer:serializer];
[manager GET:API_GET_SUPPORTERS parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
_supporters = [responseObject valueForKey:@"supporters"];
self.supportersTableView.delegate = self;
self.supportersTableView.dataSource = self;
NSLog(@"sup %@", _supporters);
[self.supportersTableView reloadData];
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}];
}
- (void) setupNavigationButtons
{
UIButton *toggleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[toggleButton setImage:[UIImage imageNamed:@"sideMenuButton"] forState:UIControlStateNormal];
[toggleButton setFrame:CGRectMake(0, 0, 32, 22)];
[toggleButton addTarget:self action:@selector(togglePressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *toggle = [[UIBarButtonItem alloc] initWithCustomView:toggleButton];
self.navigationItem.leftBarButtonItem = toggle;
}
- (void) togglePressed
{
[self.menuContainerViewController toggleLeftSideMenuCompletion:^{}];
}
#pragma mark -
#pragma mark - Table View Delegate / Data Source
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == _supportersTableView) {
return 1;
}
return 0;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == _supportersTableView) {
return _supporters.count;
}
return 0;
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _supportersTableView) {
NSString* CellIdentifier = @"SupporterCell";
SupporterCell *cell = (SupporterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SupporterCell" owner:nil options:nil];
cell = (SupporterCell*)[nib objectAtIndex:0];
}
NSDictionary* supporter = [_supporters objectAtIndex:indexPath.row];
if ([[supporter valueForKey:@"public_image"] length] > 0) {
cell.avatarImageView.image = [UIImage imageWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",API_MAIN,[supporter valueForKey:@"public_image"]]]]];
} else {
cell.avatarImageView.image = [UIImage imageNamed:@"noPhoto.png"];
}
#warning add last cell to be the refresh button!
cell.nameLabel.text = [supporter valueForKey:@"name"];
NSLog(@"Should return cell with namelabel = %@",[supporter valueForKey:@"name"]);
cell.emailLabel.text = [supporter valueForKey:@"email"];
return cell;
}
return nil;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _supportersTableView) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
- (float) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _supportersTableView) {
return 60.0;
}
return 0.0;
}
- (IBAction)newInviteButtonPressed:(id)sender
{
InviteSupporterVC* isvc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"InviteSupporterVC"];
UINavigationController* contr = [[UINavigationController alloc] initWithRootViewController:isvc];
[self presentViewController:contr animated:YES completion:nil];
}
@end