forked from tomcool420/SMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMFMoviePreviewController.m
768 lines (680 loc) · 29.7 KB
/
SMFMoviePreviewController.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
//
// SMFMoviePreviewController.m
// SMFramework
//
// Created by Thomas Cool on 2/6/11.
// Copyright 2011 tomcool.org. All rights reserved.
//
#import "Backrow/BRThemeInfo.h"
#import "Backrow/BRController.h"
#import "Backrow/BRControl.h"
#import "SMFControlFactory.h"
#import "SMFMoviePreviewController.h"
#import "SMFDefines.h"
#import "SMFBaseAsset.h"
#import "SMFListDropShadowControl.h"
#import "SMFCompatibility.h"
#import "SMFMoviePreviewDelegateDatasource.h"
#define NOSHELF
NSString * const kSMFMoviePreviewTitle = @"title";
NSString * const kSMFMoviePreviewSubtitle = @"substitle";
NSString * const kSMFMoviePreviewSummary = @"summary";
NSString * const kSMFMoviePreviewPosterPath = @"posterPath";
NSString * const kSMFMoviePreviewPoster = @"poster";
NSString * const kSMFMoviePreviewHeaders = @"headers";
NSString * const kSMFMoviePreviewColumns = @"columns";
NSString * const kSMFMoviePreviewRating = @"rating";
NSString * const kMoviePreviewControllerSelectionChanged = @"kMoviePreviewControllerSelectionChanged";
NSString * const kMoviePreviewControllerNewSelectedControl = @"kMoviePreviewControllerNewSelectedControl";
@implementation SMFMoviePreviewController
@synthesize delegate;
@synthesize datasource;
@synthesize shelfControl=_shelfControl;
@synthesize _buttons;
-(id)_shelfControl
{
return _shelfControl;
}
+(NSDictionary *)columnHeaderAttributes
{
return [[BRThemeInfo sharedTheme]movieMetadataLabelAttributes];
}
+(NSDictionary *)columnLabelAttributes
{
return [[BRThemeInfo sharedTheme]metadataLineAttributes];
}
void logFrame(CGRect frame)
{
NSLog(@"{{%f, %f},{%f,%f}}",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
}
-(id)getProviderForShelf
{
return [self.datasource providerForShelf];
}
-(NSMutableDictionary *)getInformation
{
NSMutableDictionary *d = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
@"",kSMFMoviePreviewTitle,
@"",kSMFMoviePreviewSubtitle,
@"(no summary)",kSMFMoviePreviewSummary,
[NSArray array],kSMFMoviePreviewHeaders,
[NSArray array],kSMFMoviePreviewColumns,
[BRImage imageWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"colorAppleTVNameImage" ofType:@"png"]],kSMFMoviePreviewPoster,
@"",kSMFMoviePreviewPosterPath,
@"pg",kSMFMoviePreviewRating,
nil];
//NSLog(@"get information %@",self.datasource);
if (self.datasource!=nil /*&& [self.datasource conformsToProtocol:@protocol(SMFMoviePreviewControllerDatasource)]*/) {
//NSLog(@"conforms to protocol");
NSString *t = [self.datasource title];
if (t!=nil) {[d setObject:t forKey:kSMFMoviePreviewTitle];}
t = [self.datasource subtitle];
if (t!=nil) {[d setObject:t forKey:kSMFMoviePreviewSubtitle];}
t = [self.datasource summary];
if (t!=nil) {[d setObject:t forKey:kSMFMoviePreviewSummary];}
NSArray *a = [self.datasource headers];
if (a!=nil) {[d setObject:a forKey:kSMFMoviePreviewHeaders];}
a = [self.datasource columns];
if (a!=nil) {[d setObject:a forKey:kSMFMoviePreviewColumns];}
if ([self.datasource respondsToSelector:@selector(coverArt)]) {
BRImage *i = [self.datasource coverArt];
if (i!=nil) {[d setObject:i forKey:kSMFMoviePreviewPoster];}
}
else if([self.datasource respondsToSelector:@selector(posterPath)])
{
t = [self.datasource posterPath];
if (t!=nil) {[d setObject:t forKey:kSMFMoviePreviewPosterPath];}
}
t = [self.datasource rating];
if (t!=nil) {[d setObject:t forKey:kSMFMoviePreviewRating];}
}
return [d autorelease];
}
void checkNil(NSObject *ctrl)
{
if (ctrl!=nil) {
[ctrl release];
ctrl=nil;
}
}
-(void)reload
{
// Class $BRMediaShelfView = NSClassFromString(@"BRMediaShelfView");
// Class __BRMediaShelfControl = NSClassFromString(@"BRMediaShelfControl");
Class __BRProxyManager=NSClassFromString(@"BRProxyManager");
if (__BRProxyManager !=nil)
_usingShelfView=YES;
//[self _removeAllControls];
if (_hideList!=nil) {
[_hideList release];
_hideList=nil;
}
_hideList=[[NSMutableArray alloc] init];
for (BRControl *c in [self controls]) {
if (c!=_shelfControl) {
[c removeFromParent];
}
}
CGRect masterFrame=[BRWindow interfaceFrame];
[_info release];
_info=nil;
_info = [[self getInformation] retain];
_summaryToggled=NO;
/*
* The Poster
*/
checkNil(_previewControl);
CGRect imageFrame = CGRectMake(-100.f,//masterFrame.origin.x+masterFrame.size.width*0.00f,
164.f,//masterFrame.origin.y+masterFrame.size.height*0.20f,
masterFrame.size.width*0.48f,
masterFrame.size.height*0.843f);
_previewControl =[[BRCoverArtPreviewControl alloc]init];
SMFBaseAsset *a = [SMFBaseAsset asset];
[a setCoverArt:[_info objectForKey:kSMFMoviePreviewPoster]];
BRPhotoImageProxy *proxy = [[BRPhotoImageProxy alloc] initWithAsset:a];
[_previewControl setImageProxy:proxy];
[proxy release];
[_previewControl setFrame:imageFrame];
[self addControl:_previewControl];
/*
* The Title
*/
// NSLog(@"1");
checkNil(_metadataTitleControl);
_metadataTitleControl=[[BRMetadataTitleControl alloc]init];
[_metadataTitleControl setTitle:[_info objectForKey:kSMFMoviePreviewTitle]];
[_metadataTitleControl setTitleSubtext:[_info objectForKey:kSMFMoviePreviewSubtitle]];
[_metadataTitleControl setRating:[_info objectForKey:kSMFMoviePreviewRating]];
CGRect mtcf=CGRectMake(masterFrame.size.width*0.29766f,
masterFrame.size.height*0.875f,
masterFrame.size.width*0.648f,
masterFrame.size.height*0.0695);
// mtcf.size=CGSizeMake(830., 50);
// mtcf.origin.x=masterFrame.size.width*0.29766f; //381 on a 1280p wide
// mtcf.origin.y=masterFrame.size.width*0.875f;
[_metadataTitleControl setFrame:mtcf];
[self addControl:_metadataTitleControl];
//[self addControl:_titleControl];
/*
* The Subtitle
*/
//[self addControl:_subtitleControl];
/*
* First Divider
*/
BRDividerControl *div1 = [[BRDividerControl alloc]init];
CGRect div1Frame = CGRectMake(mtcf.origin.x ,
mtcf.origin.y-masterFrame.size.height*(10.f/720.f),
mtcf.size.width,//masterFrame.size.width*0.64f,
masterFrame.size.height*(10.f/720.f));
[div1 setFrame:div1Frame];
[self addControl:div1];
[div1 release];
/*
* Summary
*/
checkNil(_summaryControl);
_summaryControl = [[BRTextControl alloc]init];
CGRect summaryFrame = CGRectMake(mtcf.origin.x,
div1Frame.origin.y-masterFrame.size.height*(94.f/720.f),//masterFrame.size.height*0.118f,
mtcf.size.width,//masterFrame.size.width*0.64f,
masterFrame.size.height*(94.f/720.f));//masterFrame.size.height*0.113f);
[_summaryControl setFrame:summaryFrame];
[_summaryControl setText:[_info objectForKey:kSMFMoviePreviewSummary]
withAttributes:[[BRThemeInfo sharedTheme]metadataSummaryFieldAttributes]];
//[_summaryControl setBackgroundColor:[[SMFThemeInfo sharedTheme]blackColor]];
/*
* Second Divider
*/
BRDividerControl *div2 = [[BRDividerControl alloc]init];
CGRect div2Frame =CGRectMake(mtcf.origin.x ,
summaryFrame.origin.y-10.f/720.f*masterFrame.size.height,//masterFrame.size.height*0.01f,
mtcf.size.width,//masterFrame.size.width*0.64f,
masterFrame.size.height*(10.f/720.f));
[div2 setFrame:div2Frame];
[self addControl:div2];
[_hideList addObject:div2];
[div2 release];
//NSLog(@"2");
/*
* Headers for information
*/
NSArray *headers = [_info objectForKey:kSMFMoviePreviewHeaders];
float increment = (mtcf.size.width/masterFrame.size.width)/(float)[headers count];
//int counter=0;
float lastOriginY=0.0f;
//NSLog(@"obj: %@",headers);
for(int counter=0;counter<[headers count];counter++)
{
BRTextControl *head = [[BRTextControl alloc]init];
[head setText:[headers objectAtIndex:counter] withAttributes:[SMFMoviePreviewController columnHeaderAttributes] ];
CGRect headFrame;
headFrame.size=[head renderedSize];
if (headFrame.size.width>(masterFrame.size.width*increment*0.95f))
headFrame.size.width=(masterFrame.size.width*increment*0.95f);
headFrame.origin.x=mtcf.origin.x+masterFrame.size.width*increment*(float)counter;
headFrame.origin.y=div2Frame.origin.y-masterFrame.size.height*0.001-headFrame.size.height;
lastOriginY=headFrame.origin.y;
[head setFrame:headFrame];
[self addControl:head];
[_hideList addObject:head];
[head release];
}
/*
* Main Information
*/
//NSLog(@"3");
NSArray *objects = [_info objectForKey:kSMFMoviePreviewColumns];
for (int counter=0; counter<[objects count]; counter++) {
NSArray *current = [objects objectAtIndex:counter];
int maxObj = [current count]>5?5:[current count];
float tempY = lastOriginY;
for (int objcount=0; objcount<maxObj; objcount++) {
if ([[current objectAtIndex:objcount] isKindOfClass:[NSArray class]]) {
NSArray *objects = [current objectAtIndex:objcount];
float x = mtcf.origin.x+masterFrame.size.width*increment*(float)counter;
float maxX=mtcf.origin.x+masterFrame.size.width*increment*(float)counter+masterFrame.size.width*increment*0.95;
float maxY=0.0;
for (int i=0;i<[objects count];i++)
{
id ctrl = nil;
CGRect r= CGRectMake(x, 0.0, 0.0, 0.0 );
if ([[objects objectAtIndex:i] isKindOfClass:[NSAttributedString class]])
{
ctrl = [[BRTextControl alloc]init];
[ctrl setAttributedString:[objects objectAtIndex:i]];
r.size=[ctrl renderedSize];
r.origin.y=tempY-r.size.height;
if (r.size.width+r.origin.x>maxX) {
r.size.width=maxX-r.origin.x;
}
logFrame(r);
}
else if([[objects objectAtIndex:i] isKindOfClass:[NSString class]])
{
ctrl = [[BRTextControl alloc]init];
[ctrl setText:[objects objectAtIndex:i] withAttributes:[SMFMoviePreviewController columnLabelAttributes]];
r.size=[ctrl renderedSize];
r.origin.y=tempY-r.size.height;
if (r.size.width+r.origin.x>maxX) {
r.size.width=maxX-r.origin.x;
}
logFrame(r);
}
else if([[objects objectAtIndex:i] isKindOfClass:[BRImage class]])
{
ctrl = [[BRImageControl alloc]init];
[(BRImageControl *)ctrl setImage:[objects objectAtIndex:i]];
float aspectRatio = [(BRImageControl *)ctrl aspectRatio];
r.size=[(BRImageControl *)ctrl pixelBounds];
r.size.height=22.f;
r.size.width=r.size.height*aspectRatio;
if (r.size.width+r.origin.x>maxX)
{
float rescaleFactor=r.size.width/(maxX-r.origin.x);
r.size.width=r.size.width*rescaleFactor;
r.size.height=r.size.height*rescaleFactor;
ctrl=nil;
}
r.origin.y=tempY-r.size.height;
logFrame(r);
}
if (maxY<r.size.height)
maxY=r.size.height;
if(i==([objects count]-1))
tempY=tempY-maxY;
if (ctrl!=nil) {
[ctrl setFrame:r];
[self addControl:ctrl];
[ctrl release];
[_hideList addObject:ctrl];
x=r.origin.x+r.size.width;
}
}
}
else {
BRControl *obj=nil;
CGRect objFrame=CGRectMake(0.0, 0.0, 0.0, 0.0);
if ([[current objectAtIndex:objcount] isKindOfClass:[NSString class]]) {
obj = [[BRTextControl alloc] init];
[(BRTextControl *)obj setText:[current objectAtIndex:objcount] withAttributes:[SMFMoviePreviewController columnLabelAttributes]];
objFrame.size=[(BRTextControl *)obj renderedSize];
if (objFrame.size.width>(masterFrame.size.width*increment*0.95f))
objFrame.size.width=(masterFrame.size.width*increment*0.95f);
}
else if ([[current objectAtIndex:objcount] isKindOfClass:[NSAttributedString class]]) {
obj = [[BRTextControl alloc] init];
[(BRTextControl *)obj setAttributedString:[current objectAtIndex:objcount]];
objFrame.size=[(BRTextControl *)obj renderedSize];
if (objFrame.size.width>(masterFrame.size.width*increment*0.95f))
objFrame.size.width=(masterFrame.size.width*increment*0.95f);
}
else if([[current objectAtIndex:objcount] isKindOfClass:[BRImage class]])
{
obj = [[BRImageControl alloc]init];
[(BRImageControl *)obj setImage:[current objectAtIndex:objcount]];
objFrame.size=[(BRImageControl *)obj pixelBounds];
float aspectRatio = [(BRImageControl *)obj aspectRatio];
objFrame.size.height=24.f;
objFrame.size.width=objFrame.size.height*aspectRatio;
if (objFrame.size.width>(masterFrame.size.width*increment*0.95f))
{
float rescaleFactor=objFrame.size.width/(masterFrame.size.width*increment*0.95f);
objFrame.size.width=objFrame.size.width*rescaleFactor;
objFrame.size.height=objFrame.size.height*rescaleFactor;
}
}
objFrame.origin.x=mtcf.origin.x+masterFrame.size.width*increment*(float)counter;
objFrame.origin.y=tempY-objFrame.size.height;
tempY=objFrame.origin.y;
[obj setFrame:objFrame];
[self addControl:obj];
[_hideList addObject:obj];
[obj release];
}
}
}
//NSLog(@"buttons");
checkNil(_buttons);
_buttons=[[NSMutableArray alloc]init];
NSArray *tbuttons=nil;//[NSArray array];
if ([self.datasource respondsToSelector:@selector(buttons)]) {
tbuttons = [self.datasource buttons];
}
else {
tbuttons=[[NSMutableArray alloc]init];
[(NSMutableArray *)tbuttons addObject:[BRButtonControl actionButtonWithImage:[[BRThemeInfo sharedTheme]previewActionImage]
subtitle:@"Preview"
badge:nil]];
[(NSMutableArray *)tbuttons addObject:[BRButtonControl actionButtonWithImage:[[BRThemeInfo sharedTheme]playActionImage]
subtitle:@"Play"
badge:nil]];
[(NSMutableArray *)tbuttons addObject:[BRButtonControl actionButtonWithImage:[[BRThemeInfo sharedTheme]queueActionImage]
subtitle:@"Queue"
badge:nil]];
[(NSMutableArray *)tbuttons addObject:[BRButtonControl actionButtonWithImage:[[BRThemeInfo sharedTheme]rateActionImage]
subtitle:@"More"
badge:nil]];
[tbuttons autorelease];
}
CGRect previewFrame=CGRectMake(masterFrame.origin.x + masterFrame.size.width*0.42f,
masterFrame.origin.y + masterFrame.size.height *0.32f,
masterFrame.size.height*0.15,
masterFrame.size.height*0.15f);
CGRect firstButtonFrame = CGRectZero;
CGRect lastButtonFrame = CGRectZero;
int button=0;
for(int i=0;i<[tbuttons count];i++)
{
id b = [tbuttons objectAtIndex:i];
if([b isKindOfClass:[BRButtonControl class]])
{
CGRect f = previewFrame;
f.origin.x=f.origin.x+ masterFrame.size.height*0.17*(float)button;
[b setFrame:f];
[self addControl:b];
button++;
[_buttons addObject:b];
if (i == 0) {
firstButtonFrame = f;
} else if (i == [tbuttons count]-1) {
lastButtonFrame = f;
}
}
}
/*
* Next/Previous arrows
*/
checkNil(_previousArrowImageControl);
checkNil(_nextArrowImageControl);
float arrowImageControlMargin = 20.0f;
if ([tbuttons count] > 0) { //if there are no buttons, we cannot go next/previous
//next/previous arrows
if ([self.delegate respondsToSelector:@selector(controllerCanSwitchToPrevious:)]) {
//does respond
if ([self.delegate controllerCanSwitchToPrevious:self]) {
//draw previous arrow
_previousArrowImageControl = [[BRImageControl alloc] init];
if (_previousArrowTurnedOn) {
[self switchPreviousArrowOn];
} else {
[self switchPreviousArrowOff];
}
CGRect objFrame = firstButtonFrame;
objFrame.origin.x -= [_previousArrowImageControl.image pixelBounds].width + arrowImageControlMargin;
objFrame.origin.y += (objFrame.size.height/2) - ([_previousArrowImageControl.image pixelBounds].height / 2);
objFrame.size.height = [_previousArrowImageControl.image pixelBounds].height;
objFrame.size.width = [_previousArrowImageControl.image pixelBounds].width;
[_previousArrowImageControl setFrame:objFrame];
//rotate imageview so arrow points in the right direction
CGAffineTransform cgCTM = CGAffineTransformMakeRotation(M_PI);
_previousArrowImageControl.affineTransform = cgCTM;
[self addControl:_previousArrowImageControl];
}
}
if ([self.delegate respondsToSelector:@selector(controllerCanSwitchToNext:)]) {
//does respond
if ([self.delegate controllerCanSwitchToNext:self]) {
//draw next arrow
_nextArrowImageControl = [[BRImageControl alloc] init];
if (_nextArrowTurnedOn) {
[self switchNextArrowOn];
} else {
[self switchNextArrowOff];
}
CGRect objFrame = lastButtonFrame;
objFrame.origin.x += lastButtonFrame.size.width + arrowImageControlMargin;
objFrame.origin.y += (objFrame.size.height/2) - ([_nextArrowImageControl.image pixelBounds].height / 2);
objFrame.size.height = [_nextArrowImageControl.image pixelBounds].height;
objFrame.size.width = [_nextArrowImageControl.image pixelBounds].width;
[_nextArrowImageControl setFrame:objFrame];
[self addControl:_nextArrowImageControl];
}
}
}
//NSLog(@"end buttons");
BRTextControl *moviesControl =[[BRTextControl alloc] init];
NSString *title=@"";
if([self.datasource respondsToSelector:@selector(shelfTitle)])
title=[self.datasource shelfTitle];
else
title=@"Movies";
[moviesControl setText:title withAttributes:[[BRThemeInfo sharedTheme]metadataSummaryFieldAttributes]];
CGRect mf;
mf.size = [moviesControl renderedSize];
mf.origin.x=masterFrame.size.width*0.1;
mf.origin.y=masterFrame.size.height*0.29f,
[moviesControl setFrame:mf];
[self addControl:moviesControl];
[moviesControl release];
BRDividerControl *div3 = [[BRDividerControl alloc]init];
CGRect div3Frame =CGRectMake(mf.origin.x + mf.size.width+masterFrame.size.width*0.02f,
mf.origin.y+(mf.size.height-[div3 recommendedHeight])/2.0f,
mtcf.origin.x+mtcf.size.width-(mf.origin.x + mf.size.width+masterFrame.size.width*0.02),
[div3 recommendedHeight]);
[div3 setFrame:div3Frame];
[self addControl:div3];
[div3 release];
BRCursorControl * cursor = [[[BRCursorControl alloc] init] autorelease];
[self addControl:cursor];
[self addControl:_summaryControl];
}
-(void)reloadShelf
{
NSLog(@"reloadShelf");
if (_shelfControl!=nil) {
[_shelfControl release];
_shelfControl=nil;
}
CGRect masterFrame=[BRWindow interfaceFrame];
if(![SMF_COMPAT usingFourPointFourPlus] && ![SMF_COMPAT usingFourPointFourGM])
{
_shelfControl = [[NSClassFromString(@"BRMediaShelfControl") alloc] init];
[_shelfControl setProvider:[self getProviderForShelf]];
[_shelfControl setColumnCount:8];
[_shelfControl setCentered:NO];
[_shelfControl setHorizontalGap:23];
}
else
{
_shelfControl=[[BRMediaShelfView alloc]init];
[_shelfControl setCentered:YES];
if (_provider!=nil) {
[_provider release];
_provider=nil;
}
_provider=[[self getProviderForShelf] retain];
_adap = [[NSClassFromString(@"BRProviderDataSourceAdapter") alloc] init];
[_adap setProviders:[NSArray arrayWithObject:_provider]];
//NSLog(@"Provider: %@ %@",_provider,_provider.controlFactory);
[_provider.controlFactory setDefaultImage:[[BRThemeInfo sharedTheme]appleTVIcon]];
[_adap setGridColumnCount:8];
if ([_shelfControl respondsToSelector:@selector(setColumnCount:)]) {
[_shelfControl setColumnCount:8];
}
[_shelfControl setCentered:NO];
[_shelfControl setDataSource:_adap];
[_shelfControl setDelegate:_adap];
//[adap autorelease];
[_shelfControl reloadData];
[_shelfControl setColumnCount:8];
[_shelfControl setHorizontalGap:33];
[_shelfControl setReadyToDisplay];
[_shelfControl layoutSubcontrols];
[_shelfControl loadWithCompletionBlock:nil];
//[_shelfControl scrollingCompleted];
}
// [_shelfControl setCoverflowMargin:.021746988594532013];
CGRect gframe=CGRectMake(masterFrame.size.width*0.00,
masterFrame.origin.y+masterFrame.size.height*0.04f,
masterFrame.size.width*1.f,
masterFrame.size.height*0.24f);
[_shelfControl setFrame:gframe];
[self addControl:_shelfControl];
}
-(void)wasPushed
{
[self reload];
[self reloadShelf];
}
-(void)controlWasActivated
{
//[_shelfControl _loadControlWithStartIndex:0 start:YES];
[super controlWasActivated];
// if([_shelfControl respondsToSelector:@selector(_loadControlWithStartIndex:start:)])
// [_shelfControl _loadControlWithStartIndex:0 start:YES];
}
-(void)toggleLongSummary
{
CGRect f = [_summaryControl frame];
CGSize masterSize = [BRWindow maxBounds];
float sh=94.f/720.f*masterSize.height;
float lh=275.f/720.f*masterSize.height;
if (_summaryToggled==YES) {
f.origin.y=f.origin.y+(lh-sh);
f.size.height=sh;
_summaryToggled=NO;
for (BRControl *c in _hideList)
[c setHidden:NO];
}
else {
f.origin.y=f.origin.y-(lh-sh);
f.size.height=lh;
_summaryToggled=YES;
for (BRControl *c in _hideList)
[c setHidden:YES];
}
[_summaryControl setFrame:f];
[_summaryControl layoutSubcontrols];
}
-(void)switchPreviousArrowOn
{
_previousArrowTurnedOn = YES; //used to retain arrow state if view is reloaded
if (_previousArrowImageControl) {
BRImage *arrowImageON = [BRImage imageWithPath:[[NSBundle bundleForClass:[BRThemeInfo class]]pathForResource:@"Arrow_ON" ofType:@"png"]];
_previousArrowImageControl.image = arrowImageON;
[_previousArrowImageControl setNeedsLayout];
}
}
-(void)switchPreviousArrowOff
{
_previousArrowTurnedOn = NO; //used to retain arrow state if view is reloaded
if (_previousArrowImageControl) {
BRImage *arrowImageOFF = [BRImage imageWithPath:[[NSBundle bundleForClass:[BRThemeInfo class]]pathForResource:@"Arrow_OFF" ofType:@"png"]];
_previousArrowImageControl.image = arrowImageOFF;
[_previousArrowImageControl setNeedsLayout];
}
}
-(void)switchNextArrowOn
{
_nextArrowTurnedOn = YES; //used to retain arrow state if view is reloaded
if (_nextArrowImageControl) {
BRImage *arrowImageON = [BRImage imageWithPath:[[NSBundle bundleForClass:[BRThemeInfo class]]pathForResource:@"Arrow_ON" ofType:@"png"]];
_nextArrowImageControl.image = arrowImageON;
[_nextArrowImageControl setNeedsLayout];
}
}
-(void)switchNextArrowOff
{
_nextArrowTurnedOn = NO; //used to retain arrow state if view is reloaded
if (_nextArrowImageControl) {
BRImage *arrowImageOFF = [BRImage imageWithPath:[[NSBundle bundleForClass:[BRThemeInfo class]]pathForResource:@"Arrow_OFF" ofType:@"png"]];
_nextArrowImageControl.image = arrowImageOFF;
[_nextArrowImageControl setNeedsLayout];
}
}
-(BOOL)brEventAction:(BREvent *)action
{
// NSLog(@"shelf D D: %@ %@",_shelfControl.delegate,_shelfControl.dataSource);
// _shelfControl.dataSource=self;
BRControl *c = [self focusedControl];
long shelfIndex=1;
if ([[self stack] peekController]!=self)
return [super brEventAction:action];
int remoteAction = [action remoteAction];
if (remoteAction==kBREventRemoteActionUp&&action.value==1) {
if ([[self focusedControl] isKindOfClass:[BRButtonControl class]]) {
[self toggleLongSummary];
return YES;
}
}
if([[self focusedControl] isKindOfClass:[SMFListDropShadowControl class]])
{
return [super brEventAction:action];
}
if (self.delegate && [self.delegate conformsToProtocol:@protocol(SMFMoviePreviewControllerDelegate)]) {
}
if (remoteAction==kBREventRemoteActionPlay &&
self.delegate!=nil &&
action.value==1 &&
[self.delegate conformsToProtocol:@protocol(SMFMoviePreviewControllerDelegate)]&&
[self.delegate respondsToSelector:@selector(controller:buttonSelectedAtIndex:)]) {
id selectedC = [self focusedControl];
for (int j=0;j<[_buttons count];j++) {
if([_buttons objectAtIndex:j]==selectedC)
[self.delegate controller:self buttonSelectedAtIndex:j];
}
}
if (remoteAction==kBREventRemoteActionPlay &&
self.delegate!=nil &&
action.value==1 &&
[self.delegate conformsToProtocol:@protocol(SMFMoviePreviewControllerDelegate)])
{
[self.delegate controller:self selectedControl:[self focusedControl]];
return YES;
}
else if(action.value==1 && self.delegate!=nil)
{
if ((remoteAction==kBREventRemoteActionRight ||
remoteAction==kBREventRemoteActionSwipeRight) &&
[self.delegate respondsToSelector:@selector(controllerCanSwitchToNext:)] &&
[self focusedControl]==[_buttons lastObject]) {
if ([self.delegate controllerCanSwitchToNext:self]) {
if ([self.delegate respondsToSelector:@selector(controllerSwitchToNext:)]) {
[self.delegate controllerSwitchToNext:self];
return YES;
}
}
}
else if((remoteAction==kBREventRemoteActionLeft ||
remoteAction==kBREventRemoteActionSwipeLeft) &&
[self.delegate respondsToSelector:@selector(controllerCanSwitchToPrevious:)] &&
[self focusedControl]==[_buttons objectAtIndex:0]) {
if ([self.delegate controllerCanSwitchToPrevious:self]) {
if ([self.delegate respondsToSelector:@selector(controllerSwitchToPrevious:)]) {
[self.delegate controllerSwitchToPrevious:self];
return YES;
}
}
}
}
BOOL b=[super brEventAction:action];
BRControl *d = [self focusedControl];
if (action.value==1 && c!=d) {
if (delegate!=nil && [delegate respondsToSelector:@selector(controller:shelfLastIndex:)]) {
[delegate controller:self shelfLastIndex:shelfIndex];
}
if (delegate!=nil && [delegate respondsToSelector:@selector(controller:switchedFocusTo:)]) {
[delegate controller:self switchedFocusTo:d];
}
}
return b;
}
-(void)dealloc
{
[_previewControl release];
[_metadataTitleControl release];
self.datasource=nil;
self.delegate=nil;
[_shelfControl release];
[_buttons release];
checkNil(_adap);
checkNil(_previousArrowImageControl);
checkNil(_nextArrowImageControl);
checkNil(_info);
checkNil(_summaryControl);
checkNil(_hideList);
checkNil(_provider);
[super dealloc];
}
@end