-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWallPicturesViewController.m
More file actions
executable file
·190 lines (136 loc) · 5.53 KB
/
Copy pathWallPicturesViewController.m
File metadata and controls
executable file
·190 lines (136 loc) · 5.53 KB
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
//
// WallPicturesViewController.m
// TutorialBase
//
// Created by Antonio MG on 6/23/12.
// Copyright (c) 2012 AMG. All rights reserved.
//
#import "WallPicturesViewController.h"
#import "UploadImageViewController.h"
#import <Parse/Parse.h>
@interface WallPicturesViewController () {
}
@property (nonatomic, retain) NSArray *wallObjectsArray;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
-(void)getWallImages;
-(void)loadWallViews;
-(void)showErrorView:errorString;
@end
@implementation WallPicturesViewController
@synthesize wallObjectsArray = _wallObjectsArray;
@synthesize wallScroll = _wallScroll;
@synthesize activityIndicator = _loadingSpinner;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (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
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.wallScroll = nil;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//Clean the scroll view
for (id viewToRemove in [self.wallScroll subviews]){
if ([viewToRemove isMemberOfClass:[UIView class]])
[viewToRemove removeFromSuperview];
}
//Reload the wall
[self getWallImages];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark Wall Load
//Load the images on the wall
-(void)loadWallViews
{
//Clean the scroll view
for (id viewToRemove in [self.wallScroll subviews]){
if ([viewToRemove isMemberOfClass:[UIView class]])
[viewToRemove removeFromSuperview];
}
//For every wall element, put a view in the scroll
int originY = 10;
for (PFObject *wallObject in self.wallObjectsArray){
//Build the view with the image and the comments
UIView *wallImageView = [[UIView alloc] initWithFrame:CGRectMake(10, originY, self.view.frame.size.width - 20 , 300)];
//Add the image
PFFile *image = (PFFile *)[wallObject objectForKey:@"image"];
UIImageView *userImage = [[UIImageView alloc] initWithImage:[UIImage imageWithData:image.getData]];
userImage.frame = CGRectMake(0, 0, wallImageView.frame.size.width, 200);
[wallImageView addSubview:userImage];
//Add the info label (User and creation date)
NSDate *creationDate = wallObject.createdAt;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm dd/MM yyyy"];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 210, wallImageView.frame.size.width,15)];
infoLabel.text = [NSString stringWithFormat:@"Uploaded by: %@, %@", [wallObject objectForKey:@"user"], [df stringFromDate:creationDate]];
infoLabel.font = [UIFont fontWithName:@"Arial-ItalicMT" size:9];
infoLabel.textColor = [UIColor whiteColor];
infoLabel.backgroundColor = [UIColor clearColor];
[wallImageView addSubview:infoLabel];
//Add the comment
UILabel *commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 240, wallImageView.frame.size.width, 15)];
commentLabel.text = [wallObject objectForKey:@"comment"];
commentLabel.font = [UIFont fontWithName:@"ArialMT" size:13];
commentLabel.textColor = [UIColor whiteColor];
commentLabel.backgroundColor = [UIColor clearColor];
[wallImageView addSubview:commentLabel];
[self.wallScroll addSubview:wallImageView];
originY = originY + wallImageView.frame.size.width + 20;
}
//Set the bounds of the scroll
self.wallScroll.contentSize = CGSizeMake(self.wallScroll.frame.size.width, originY);
}
#pragma mark Receive Wall Objects
//Get the list of images
-(void)getWallImages
{
//Prepare the query to get all the images in descending order
PFQuery *query = [PFQuery queryWithClassName:@"WallImageObject"];
[query orderByDescending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Everything was correct, put the new objects and load the wall
self.wallObjectsArray = nil;
self.wallObjectsArray = [[NSArray alloc] initWithArray:objects];
[self loadWallViews];
} else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
}];
}
#pragma mark IB Actions
-(IBAction)logoutPressed:(id)sender
{
[PFUser logOut];
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark Error Alert
-(void)showErrorView:(NSString *)errorMsg{
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorMsg delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
}
@end