This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
NPHistoryWindowController.m
269 lines (183 loc) · 10.3 KB
/
NPHistoryWindowController.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
//
// NPHistoryWindowController.m
// Get_iPlayer GUI
//
// Created by LFS on 8/6/16.
//
//
#import "GetITVListings.h"
#import "NPHistoryWindowController.h"
#import "GetITVListings.h"
NewProgrammeHistory *sharedHistoryContoller;
@implementation NPHistoryTableViewController
-(id)init
{
self = [super init];
if (!self)
return self;
/* Load in programme History */
sharedHistoryContoller = [NewProgrammeHistory sharedInstance];
programmeHistoryArray = [sharedHistoryContoller getHistoryArray];
historyDisplayArray = [[NSMutableArray alloc]init];
[self loadDisplayData];
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(loadDisplayData) name:@"NewProgrammeDisplayFilterChanged" object:nil];
return self;
}
- (IBAction)changeFilter:(id)sender {
[self loadDisplayData];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [historyDisplayArray count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
ProgrammeHistoryObject *np = [historyDisplayArray objectAtIndex:row];
NSString *identifer = [tableColumn identifier];
return [np valueForKey:identifer];
}
-(void)loadDisplayData
{
NSString *displayDate = nil;
NSString *headerDate = nil;
NSString *theItem = nil;
int pageNumber = 0;
/* Set up date for use in headings comparison */
double secondsSince1970 = [[NSDate date] timeIntervalSince1970];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE MMM dd"];
NSDateFormatter *dateFormatterDayOfWeek = [[NSDateFormatter alloc] init]; [dateFormatterDayOfWeek setDateFormat:@"EEEE"];
NSMutableDictionary *dayNames = [[NSMutableDictionary alloc]init];
NSString *keyValue;
NSString *key;
for (int i=0;i<7;i++, secondsSince1970-=(24*60*60)) {
if (i==0)
keyValue = @"Today";
else if (i==1)
keyValue = @"Yesterday";
else
keyValue = [dateFormatterDayOfWeek stringFromDate:[NSDate dateWithTimeIntervalSince1970:secondsSince1970]];
key = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:secondsSince1970]];
[dayNames setValue:keyValue forKey:key];
}
[historyDisplayArray removeAllObjects];
for (ProgrammeHistoryObject *np in programmeHistoryArray ) {
if ( [self showITVProgramme:np] || [self showBBCTVProgramme:np] || [self showBBCRadioProgramme:np] ) {
if ( [np.dateFound isNotEqualTo:displayDate] ) {
displayDate = np.dateFound;
headerDate = [dayNames objectForKey:np.dateFound];
if (!headerDate) {
headerDate = @"On : ";
headerDate = [headerDate stringByAppendingString:displayDate];
}
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:nil andTVChannel:nil andLineNumber:2 andPageNumber:pageNumber]];
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:headerDate andTVChannel:nil andLineNumber:0 andPageNumber:++pageNumber]];
}
theItem = @" ";
theItem = [theItem stringByAppendingString:[np programmeName]];
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:theItem andTVChannel:np.tvChannel andLineNumber:1 andPageNumber:pageNumber]];
}
}
[historyDisplayArray addObject:[[HistoryDisplay alloc]initWithItemString:nil andTVChannel:nil andLineNumber:2 andPageNumber:pageNumber]];
/* Sort in to programme within reverse date order */
NSSortDescriptor *sort4 = [NSSortDescriptor sortDescriptorWithKey:@"networkNameString" ascending:YES];
NSSortDescriptor *sort3 = [NSSortDescriptor sortDescriptorWithKey:@"programmeNameString" ascending:YES];
NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"lineNumber" ascending:YES];
NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"pageNumber" ascending:NO];
[historyDisplayArray sortUsingDescriptors:[NSArray arrayWithObjects:sort1, sort2, sort3, sort4, nil]];
[historyTable reloadData];
return;
}
-(BOOL)showITVProgramme:(ProgrammeHistoryObject *)np
{
if ( [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowITV"]isEqualTo:@NO] )
return NO;
if ( ![np.networkName isEqualToString:@"ITV"] )
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllTVNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
return YES;
}
-(BOOL)showBBCTVProgramme:(ProgrammeHistoryObject *)np
{
if ( [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowBBCTV"]isEqualTo:@NO] )
return NO;
if ( ![np.networkName isEqualToString:@"BBC TV"] )
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllTVNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
if (([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCOne"]isEqualTo:@YES] && [np.tvChannel hasPrefix:@"BBC One"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCTwo"]isEqualTo:@YES] && [np.tvChannel hasPrefix:@"BBC Two"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCThree"]isEqualTo:@YES] && [np.tvChannel hasPrefix:@"BBC Three"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCFour"]isEqualTo:@YES] && [np.tvChannel hasPrefix:@"BBC Four"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCNews"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"BBC News"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCParliament"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"BBC Parliament"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"S4C"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"S4C"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCAlba"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"BBC Alba"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"CBeebies"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"CBeebies"]) ||
([[[NSUserDefaults standardUserDefaults] valueForKey:@"CBBC"]isEqualTo:@YES] && [np.tvChannel isEqualToString:@"CBBC"])
)
return YES;
return NO;
}
-(BOOL)showBBCRadioProgramme:(ProgrammeHistoryObject *)np
{
NSArray *regions = @[@"Radio Scotland", @"Radio Nan", @"Radio Shetland", @"Radio Orkney", @"Radio Wales", @"Radio Cymru", @"Radio Ulster", @"Radio Foyle" ];
/* Filter out if not radio or news and news not wanted */
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowBBCRadio"]isEqualTo:@NO])
return NO;
if (![np.networkName isEqualToString:@"BBC Radio"])
return NO;
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"IgnoreAllRadioNews"]isEqualTo:@YES]) {
if ([np.programmeName rangeOfString:@"news" options:NSCaseInsensitiveSearch].location != NSNotFound) {
return NO;
}
}
/* Filter each of the nationals in turn */
if ([np.tvChannel isEqualToString:@"BBC Radio 1"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio1"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 2"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio2"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 3"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio3"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 4"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio4"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 1Xtra"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio1Xtra"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 4 Extra"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio4Extra"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Radio 5 live"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio5Live"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC 5 live sports extra"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio5LiveSportsExtra"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC 6 Music"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"Radio6Music"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC Asian Network"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"RadioAsianNetwork"]isEqualTo:@YES] ? YES:NO;
if ([np.tvChannel isEqualToString:@"BBC World Service"])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"BBCWorldService"]isEqualTo:@YES] ? YES:NO;
/* Filter for regionals */
for (int i=0; i<regions.count;i++)
if ([np.tvChannel containsString:regions[i]])
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowRegionalRadioStations"]isEqualTo:@YES] ? YES:NO;
/* Otherwise must be local */
return [[[NSUserDefaults standardUserDefaults] valueForKey:@"ShowLocalRadioStations"]isEqualTo:@YES] ? YES:NO;
}
@end
@implementation HistoryDisplay
- (id)initWithItemString:(NSString *)aItemString andTVChannel:(NSString *)aTVChannel andLineNumber:(int)aLineNumber andPageNumber:(int)aPageNumber;
{
programmeNameString = aItemString;
lineNumber = aLineNumber;
pageNumber = aPageNumber;
networkNameString = aTVChannel;
return self;
}
@end