-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendListViewController.m
235 lines (169 loc) · 8.39 KB
/
FriendListViewController.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
//
// FriendListViewController.m
// SocialSaver
//
// Created by Mitchell Kelman on 3/18/15.
// Copyright (c) 2015 Mitchell Kelman. All rights reserved.
//
#import "FriendListViewController.h"
#import "Friends.h"
#import "FriendDetail.h"
@interface FriendListViewController (){
//the following strings will be populated depending on what the user choose on the row
NSString *name, *email, *rating, *Report, *objectid;
PFFile *friendphoto;
}
@end
@implementation FriendListViewController
@synthesize infoTable;// stateOfCollege,collegeName,classType,sortBy,infoTable,imageme,Temail;
UIActivityIndicatorView *activityIndicator;
NSInteger totalObject;
- (void)viewDidLoad{
[super viewDidLoad];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
NSInteger sizeheight = self.view.frame.size.height / 2.0;
activityIndicator.center = CGPointMake(self.view.frame.size.width / 2.0, sizeheight-30);
[self.view addSubview: activityIndicator];
[activityIndicator startAnimating];
[self performSelector:@selector(retrieveFromParse)];
self.infoTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //removes unsued lines from table view
}
-(void)retrieveFromParse{
PFQuery *astutor = [PFQuery queryWithClassName:@"Friends"];
PFQuery *asstudent = [PFQuery queryWithClassName:@"Friends"];
NSString *useremail = [[PFUser currentUser] objectForKey:@"username"];
[astutor whereKey:@"friendOne" equalTo:useremail ];
[asstudent whereKey:@"friendTwo" equalTo:useremail];
// [astutor orderByDescending:@"updatedAt"];
PFQuery *query = [PFQuery orQueryWithSubqueries:@[asstudent,astutor]];
[query orderByDescending:@"updatedAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(objects.count == 0){
UILabel *label = [[UILabel alloc] init];
CGRect frame = CGRectMake(0.0, 200.0, 320.0, 80.0); //x,y,width,hight
label.frame = frame;
label.numberOfLines = 5;
label.text = @"You dont have any friends yet.";
[self.infoTable addSubview:label];
[activityIndicator stopAnimating];
} else {
uname = [[NSArray alloc]initWithArray:objects];
uemail = [[NSArray alloc]initWithArray:objects];
ureport = [[NSArray alloc]initWithArray:objects];
urating = [[NSArray alloc]initWithArray:objects];
ufriendphoto = [[NSArray alloc]initWithArray:objects];
}
[infoTable reloadData];
}];
}
- (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 uname.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PFObject *nameObject = [uname objectAtIndex:indexPath.row];
PFObject *friendPhotoObject = [ufriendphoto objectAtIndex:indexPath.row];
NSString *asFriendOne = [nameObject objectForKey:@"friendOne"];
NSString *asFriendTwo = [nameObject objectForKey:@"friendTwo"];
NSString *userInfo = [[PFUser currentUser]objectForKey:@"username"];
if ([asFriendOne isEqualToString:userInfo]) {
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:asFriendTwo]; // find all the women
NSArray *user = [query findObjects];
cell.UserNameLabel.text = [[user objectAtIndex:0] objectForKey:@"name"];
cell.EmailLabel.text = [[user objectAtIndex:0] objectForKey:@"username"];
NSString *rated = [[user objectAtIndex:0] objectForKey:@"Rating"];
NSLog(@"%@ / 5.0", rated);
NSString *full = [NSString stringWithFormat:@"%@ / 5.0", rated];
cell.RatingLabel.text = full;
cell.ReportCountLabel.text = [[user objectAtIndex:0] objectForKey:@"reportCount"];
PFFile *file = [[user objectAtIndex:0] objectForKey:@"userImage"];
NSData *data = [file getData];
UIImage *theImage = [UIImage imageWithData:data];
cell.ImageLabel.image = theImage;
PFObject *tempObject = [uname objectAtIndex:indexPath.row];
objectid = [tempObject objectId];
name = [[user objectAtIndex:0] objectForKey:@"name"];
email = [[user objectAtIndex:0] objectForKey:@"username"];
rating = [[user objectAtIndex:0] objectForKey:@"Rating"];
Report = [[user objectAtIndex:0] objectForKey:@"reportCount"];
} else {
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:asFriendTwo]; // find all the women
NSArray *user = [query findObjects];
cell.UserNameLabel.text = [[user objectAtIndex:0] objectForKey:@"name"];
cell.EmailLabel.text = [[user objectAtIndex:0] objectForKey:@"username"];
NSString *rated = [[user objectAtIndex:0] objectForKey:@"Rating"];
NSLog(@"%@ / 5.0", rated);
NSString *full = [NSString stringWithFormat:@"%@ / 5.0", rated];
cell.RatingLabel.text = full;
cell.ReportCountLabel.text = [[user objectAtIndex:0] objectForKey:@"reportCount"];
PFFile *file = [[user objectAtIndex:0] objectForKey:@"userImage"];
NSData *data = [file getData];
UIImage *theImage = [UIImage imageWithData:data];
cell.ImageLabel.image = theImage;
PFObject *tempObject = [uname objectAtIndex:indexPath.row];
objectid = [tempObject objectId];
name = [[user objectAtIndex:0] objectForKey:@"name"];
email = [[user objectAtIndex:0] objectForKey:@"username"];
rating = [[user objectAtIndex:0] objectForKey:@"Rating"];
Report = [[user objectAtIndex:0] objectForKey:@"reportCount"];
}
[activityIndicator stopAnimating]; // end spinning wheel!
return cell;
}
//user selects folder to add tag to
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//this will set all variables to prepare for segue
PFObject *tempObject = [uname objectAtIndex:indexPath.row];
NSString *asFriendOne = [tempObject objectForKey:@"friendOne"];
NSString *asFriendTwo = [tempObject objectForKey:@"friendTwo"];
NSString *userInfo = [[PFUser currentUser]objectForKey:@"username"];
if ([asFriendOne isEqualToString:userInfo]) {
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:asFriendTwo]; // find all the women
NSArray *user = [query findObjects];
name = [[user objectAtIndex:0] objectForKey:@"name"];
email = [[user objectAtIndex:0] objectForKey:@"username"];
NSString *rated = [[user objectAtIndex:0] objectForKey:@"Rating"];
NSString *full = [NSString stringWithFormat:@"%@ / 5.0", rated];
rating = full;
Report = [[user objectAtIndex:0] objectForKey:@"reportCount"];
} else {
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:asFriendTwo]; // find all the women
NSArray *user = [query findObjects];
name = [[user objectAtIndex:0] objectForKey:@"name"];
email = [[user objectAtIndex:0] objectForKey:@"username"];
NSString *rated = [[user objectAtIndex:0] objectForKey:@"Rating"];
NSString *full = [NSString stringWithFormat:@"%@ / 5.0", rated];
rating = full;
Report = [[user objectAtIndex:0] objectForKey:@"reportCount"];
}
objectid = [tempObject objectId];
[self performSegueWithIdentifier:@"ShowDetails" sender:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"ShowDetails"]){
FriendDetail *D1 = [segue destinationViewController];
D1.aemail = email;
D1.aname = name;
D1.arating = rating;
D1.areport = Report;
D1.aobjectid = objectid;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end