forked from tomcool420/SMFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SMFControlFactory.m
205 lines (194 loc) · 7.39 KB
/
SMFControlFactory.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
//
// SMFControlFactory.m
// SMFramework
//
// Created by Thomas Cool on 2/7/11.
// Copyright 2011 tomcool.org. All rights reserved.
//
#import "SMFControlFactory.h"
#import "SMFPhotoMethods.h"
#import "SMFBaseAsset.h"
@interface BRPosterControl (private)
+(BRPosterControl *)posterButtonWithImage:(id)image title:(id)title;
@end
@implementation SMFControlFactory
@synthesize _poster;
@synthesize _alwaysShowTitles;
@synthesize favorProxy=_favorProxy;
@synthesize defaultImage=_defaultImage;
+(id)mainMenuFactory
{
return [[[SMFControlFactory alloc] initForMainMenu:YES] autorelease];
}
+(id)standardFactory
{
SMFControlFactory *a = [[[SMFControlFactory alloc] initForMainMenu:NO] autorelease];
return a;
}
+(SMFControlFactory *)posterControlFactory
{
SMFControlFactory *a =[[[SMFControlFactory alloc] initForMainMenu:NO] autorelease];
a._poster=YES;
return a;
}
//Returns the control shown on main menu
-(id)initForMainMenu:(BOOL)arg1
{
self = [super initForMainMenu:arg1];
_mainmenu = arg1;
self._poster=NO;
self.defaultImage=nil;
self.favorProxy=NO;
self._alwaysShowTitles=NO;
return self;
}
-(void)dealloc
{
self.defaultImage=nil;
[super dealloc];
}
-(id)controlForData:(id)arg1 currentControl:(id)arg2 requestedBy:(id)arg3
{
NSLog(@"control for data: %@",arg1);
id returnObj=nil;
if([arg1 isKindOfClass:[SMFPhotoMediaCollection class]])
{
NSLog(@"1");
BRDataStore *store = [SMFPhotoMethods dataStoreForAssets:[arg1 mediaAssets]];
BRPhotoControlFactory* controlFactory = [BRPhotoControlFactory mainMenuFactory];
SMFPhotoCollectionProvider* provider = [SMFPhotoCollectionProvider providerWithDataStore:store controlFactory:controlFactory];
returnObj = [BRCyclerControl cyclerWithProvider:provider];
if([[arg1 mediaAssets]count]>0)
[returnObj setAcceptsFocus:YES];
[returnObj setObject:arg1];
[returnObj setStartIndex:0];
}
else if([arg1 isKindOfClass:[BRImageProxyProvider class]])
{
NSLog(@"2");
BRBaseMediaAsset *a = [[arg1 dataAtIndex:0]asset];
if (self.favorProxy) {
returnObj = [self controlForImageProxy:[arg1 dataAtIndex:0] title:[a title]];
}
else if ([a respondsToSelector:@selector(coverArt)]) {
returnObj= [self controlForImage:[(BRPhotoMediaAsset *)a coverArt] title:[a title]];
}
else
returnObj= [ self controlForImage:[[a imageProxy] defaultImage] title:[a title]];
}
else if([arg1 isKindOfClass:[BRPhotoMediaAsset class]])
{
NSLog(@"3");
NSString *t = [(BRPhotoMediaAsset *)arg1 title];
if (t==nil)
t=[[[arg1 coverArtURL]lastPathComponent] stringByDeletingPathExtension];
if (self.favorProxy && [arg1 respondsToSelector:@selector(imageProxy)]) {
returnObj = [self controlForImageProxy:[arg1 imageProxy] title:t];
}
else
returnObj = [self controlForImage:[arg1 coverArt] title:t];
}
else if([arg1 isKindOfClass:[BRBaseMediaAsset class]])
{
NSLog(@"4");
id proxy = nil;//[arg1 coverArt];
if ([arg1 respondsToSelector:@selector(coverArt)]) {
proxy=[arg1 coverArt];
}
if(proxy == nil)
proxy = [arg1 imageProxy];
if (proxy==nil)
return nil;
if (self._poster==YES) {
BRImage *img = nil;
if ([proxy conformsToProtocol:@protocol(BRImageProxy)])
returnObj=[BRPosterControl posterButtonWithImageProxy:proxy title:[arg1 title]];
else if([proxy isKindOfClass:[BRImage class]])
{
img=proxy;
if (NSClassFromString(@"BRProxyManager")!=nil) {
SMFBaseAsset *a = [SMFBaseAsset asset];
[a setCoverArt:img];
[a setTitle:[arg1 title]];
NSObject<BRImageProxy>* p =[NSClassFromString(@"BRXMLImageProxy") imageProxyForAsset:a];
returnObj=[BRPosterControl posterButtonWithImageProxy:p title:[arg1 title]];
}
else
returnObj=[BRPosterControl posterButtonWithImage:img title:[arg1 title]];
}
//returnObj=[BRPosterControl posterButtonWithImage:img title:[arg1 title]];
((BRPosterControl *)returnObj).alwaysShowTitles=self._alwaysShowTitles;
}
else {
if ([proxy conformsToProtocol:@protocol(BRImageProxy)])
returnObj = [[BRAsyncImageControl alloc] initWithImageProxy:proxy];
else if([proxy isKindOfClass:[BRImage class]])
returnObj = [[BRAsyncImageControl alloc] initWithImage:proxy];
if (returnObj!=nil) {
[returnObj setAcceptsFocus:YES];
[returnObj autorelease];
}
}
}
else if([arg1 isKindOfClass:[BRDividerControl class]])
{
NSLog(@"divider");
returnObj=arg1;
}
//returning nothing is also acceptable only for main menu
NSLog(@"returning Image long %@",returnObj);
return returnObj;
}
-(BRControl *)controlForImage:(BRImage *)image title:(NSString *)title
{
if (_poster==YES) {
BRPosterControl *returnObj;
if (NSClassFromString(@"BRProxyManager")!=nil) {
SMFBaseAsset *a = [SMFBaseAsset asset];
[a setCoverArt:image];
[a setTitle:title];
NSObject<BRImageProxy>* p =[NSClassFromString(@"BRXMLImageProxy") imageProxyForAsset:a];
returnObj=[BRPosterControl posterButtonWithImageProxy:p title:title];
}
else
returnObj=[BRPosterControl posterButtonWithImage:image title:title];
returnObj.alwaysShowTitles=self._alwaysShowTitles;
returnObj.posterBorderWidth=1.f;
returnObj.titleWidthScale=1.3999999761581421;
returnObj.titleVerticalOffset=-0.054999999701976776;
returnObj.reflectionAmount=0.14000000059604645;
NSLog(@"returning Image %@",returnObj);
return returnObj;
}
else {
BRAsyncImageControl *returnObj = [BRAsyncImageControl imageControlWithImage:image];
[returnObj setAcceptsFocus:YES];
NSLog(@"returning Image %@",returnObj);
return returnObj;
}
}
-(BRControl *)controlForImageProxy:(BRURLImageProxy *)imageProxy title:(NSString *)title
{
if (_poster==YES) {
BRPosterControl *returnObj=[[BRPosterControl alloc] init];
returnObj.posterStyle = 0;
returnObj.title = [[[NSAttributedString alloc]initWithString:title attributes:[[BRThemeInfo sharedTheme] menuItemSmallTextAttributes]]autorelease];
returnObj.imageProxy=imageProxy;
returnObj.defaultImage=self.defaultImage;
returnObj.alwaysShowTitles=self._alwaysShowTitles;
returnObj.posterBorderWidth=1.f;
returnObj.titleWidthScale=1.3999999761581421;
returnObj.titleVerticalOffset=-0.054999999701976776;
returnObj.reflectionAmount=0.14000000059604645;
return [returnObj autorelease];
}
else {
BRAsyncImageControl *returnObj = [BRAsyncImageControl imageControlWithImageProxy:imageProxy];
//#warning did not test this one, but seemed to make sense for it to use the proxy too ^^
[returnObj setAcceptsFocus:YES];
return returnObj;
}
}
@end
@implementation SMFPhotoControlFactory
@end