-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRecordingsListViewController.mm
177 lines (138 loc) · 5.18 KB
/
RecordingsListViewController.mm
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
//
// RecordingsListViewController.m
// LectureLeaks
//
// Created by Christopher Ballinger on 6/6/11.
// Copyright 2011. All rights reserved.
//
#import "RecordingsListViewController.h"
#import "LecturePlayerViewController.h"
#import "Recording.h"
@implementation RecordingsListViewController
@synthesize listContent;
- (id)init
{
self = [super init];
if (self) {
self.tableView = [[UITableView alloc] init];
self.tableView.dataSource = self;
self.tableView.delegate = self;
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDirectoryEnumerator *direnum = [manager enumeratorAtPath:documentsDirectory];
NSMutableArray *lectureList = [[NSMutableArray alloc] init];
Recording *newRecording;
NSString *filename;
while ((filename = [direnum nextObject] ))
{
if ([filename hasSuffix:@".audio.plist"])
{
newRecording = [Recording recordingWithFile:filename];
[lectureList addObject:newRecording];
}
}
listContent = lectureList;
}
return self;
}
- (void) loadView {
[super loadView];
[self.view addSubview:self.tableView];
}
#pragma mark -
#pragma mark UITableView data source and delegate methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.listContent count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kCellID = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
/*
If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list.
*/
Recording *recording = nil;
recording = [self.listContent objectAtIndex:indexPath.row];
if([recording.name isEqualToString:@""])
cell.textLabel.text = [recording.date description];
else
cell.textLabel.text = recording.name;
if(!recording.isSubmitted)
{
cell.textLabel.textColor = [UIColor redColor];
cell.detailTextLabel.text = @"Not submitted!";
}
else
{
cell.detailTextLabel.text = @"Submitted";
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
LecturePlayerViewController *lecturePlayerController = [[LecturePlayerViewController alloc] init];
Recording *recording = nil;
recording = [self.listContent objectAtIndex:indexPath.row];
lecturePlayerController.title = [recording.date description];
lecturePlayerController.recording = recording;
[[self navigationController] pushViewController:lecturePlayerController animated:YES];
[lecturePlayerController release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[[listContent objectAtIndex:indexPath.row] deleteFiles];
[listContent removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void)dealloc
{
[super dealloc];
}
- (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];
// Do any additional setup after loading the view from its nib.
self.editButtonItem.target = self;
[self.navigationItem setRightBarButtonItem:self.editButtonItem animated:YES];
self.title = @"My Recordings";
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
[self.tableView setNeedsDisplay];
[self.navigationController setNavigationBarHidden:NO animated:YES];
CGFloat navHeight = self.navigationController.navigationBarHidden ? 0 :
self.navigationController.navigationBar.frame.size.height;
self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - navHeight);
}
- (void)viewDidUnload
{
self.tableView = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end