2014-10-24 16:02:10 -04:00
|
|
|
//
|
|
|
|
|
// UIAppView.m
|
2015-05-12 21:48:30 -04:00
|
|
|
// Moonlight
|
2014-10-24 16:02:10 -04:00
|
|
|
//
|
|
|
|
|
// Created by Diego Waxemberg on 10/22/14.
|
2015-05-12 21:48:30 -04:00
|
|
|
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
2014-10-24 16:02:10 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "UIAppView.h"
|
2018-08-27 01:54:58 -07:00
|
|
|
#import "AppAssetManager.h"
|
2014-10-24 16:02:10 -04:00
|
|
|
|
|
|
|
|
@implementation UIAppView {
|
2015-12-01 20:31:24 -08:00
|
|
|
TemporaryApp* _app;
|
2014-10-24 16:02:10 -04:00
|
|
|
UIButton* _appButton;
|
|
|
|
|
UILabel* _appLabel;
|
2015-07-10 18:09:12 -07:00
|
|
|
UIImageView* _appOverlay;
|
2015-11-10 21:23:00 -08:00
|
|
|
NSCache* _artCache;
|
2014-10-26 02:15:53 -04:00
|
|
|
id<AppCallback> _callback;
|
2014-10-24 16:02:10 -04:00
|
|
|
}
|
|
|
|
|
|
2015-11-10 21:23:00 -08:00
|
|
|
static UIImage* noImage;
|
|
|
|
|
|
2015-12-01 20:31:24 -08:00
|
|
|
- (id) initWithApp:(TemporaryApp*)app cache:(NSCache*)cache andCallback:(id<AppCallback>)callback {
|
2014-10-24 16:02:10 -04:00
|
|
|
self = [super init];
|
|
|
|
|
_app = app;
|
2014-10-26 02:15:53 -04:00
|
|
|
_callback = callback;
|
2015-11-10 21:23:00 -08:00
|
|
|
_artCache = cache;
|
|
|
|
|
|
|
|
|
|
// Cache the NoAppImage ourselves to avoid
|
|
|
|
|
// having to load it each time
|
|
|
|
|
if (noImage == nil) {
|
|
|
|
|
noImage = [UIImage imageNamed:@"NoAppImage"];
|
|
|
|
|
}
|
2014-10-24 16:02:10 -04:00
|
|
|
|
|
|
|
|
_appButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
2015-01-08 18:09:09 -05:00
|
|
|
[_appButton setBackgroundImage:noImage forState:UIControlStateNormal];
|
2015-07-10 21:22:57 -07:00
|
|
|
[_appButton setContentEdgeInsets:UIEdgeInsetsMake(0, 4, 0, 4)];
|
2014-10-24 16:02:10 -04:00
|
|
|
[_appButton sizeToFit];
|
2018-08-26 01:15:53 -07:00
|
|
|
[_appButton addTarget:self action:@selector(appClicked) forControlEvents:UIControlEventPrimaryActionTriggered];
|
2015-01-08 18:09:09 -05:00
|
|
|
|
2014-12-04 18:41:01 +09:00
|
|
|
[self addSubview:_appButton];
|
|
|
|
|
[self sizeToFit];
|
2015-07-10 18:09:12 -07:00
|
|
|
|
2015-01-08 20:46:04 -05:00
|
|
|
_appButton.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
|
|
|
|
self.frame = CGRectMake(0, 0, noImage.size.width, noImage.size.height);
|
2014-10-24 16:02:10 -04:00
|
|
|
|
2015-11-10 20:48:39 -08:00
|
|
|
// Rasterizing the cell layer increases rendering performance by quite a bit
|
|
|
|
|
self.layer.shouldRasterize = YES;
|
|
|
|
|
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
|
|
|
|
|
|
2014-10-24 16:02:10 -04:00
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-26 02:15:53 -04:00
|
|
|
- (void) appClicked {
|
|
|
|
|
[_callback appClicked:_app];
|
|
|
|
|
}
|
2014-10-24 16:02:10 -04:00
|
|
|
|
2014-10-26 02:15:53 -04:00
|
|
|
- (void) updateAppImage {
|
2015-11-10 21:23:00 -08:00
|
|
|
if (_appOverlay != nil) {
|
|
|
|
|
[_appOverlay removeFromSuperview];
|
|
|
|
|
_appOverlay = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 11:41:42 -07:00
|
|
|
if ([_app.id isEqualToString:_app.host.currentGame]) {
|
2015-11-10 21:23:00 -08:00
|
|
|
// Only create the app overlay if needed
|
|
|
|
|
_appOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play"]];
|
|
|
|
|
_appOverlay.layer.shadowColor = [UIColor blackColor].CGColor;
|
|
|
|
|
_appOverlay.layer.shadowOffset = CGSizeMake(0, 0);
|
|
|
|
|
_appOverlay.layer.shadowOpacity = 1;
|
|
|
|
|
_appOverlay.layer.shadowRadius = 2.0;
|
|
|
|
|
|
|
|
|
|
[self addSubview:_appOverlay];
|
|
|
|
|
|
|
|
|
|
_appOverlay.frame = CGRectMake(0, 0, noImage.size.width / 2.f, noImage.size.height / 4.f);
|
|
|
|
|
[_appOverlay setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/6)];
|
|
|
|
|
}
|
2015-07-10 18:09:12 -07:00
|
|
|
|
2015-07-10 21:22:57 -07:00
|
|
|
BOOL noAppImage = false;
|
|
|
|
|
|
2018-08-27 01:54:58 -07:00
|
|
|
// First check the memory cache
|
|
|
|
|
UIImage* appImage = [_artCache objectForKey:_app];
|
|
|
|
|
if (appImage == nil) {
|
|
|
|
|
// Next try to load from the on disk cache
|
|
|
|
|
appImage = [UIImage imageWithContentsOfFile:[AppAssetManager boxArtPathForApp:_app]];
|
|
|
|
|
if (appImage != nil) {
|
2015-11-10 21:23:00 -08:00
|
|
|
[_artCache setObject:appImage forKey:_app];
|
|
|
|
|
}
|
2018-08-27 01:54:58 -07:00
|
|
|
}
|
|
|
|
|
if (appImage != nil) {
|
2015-07-10 21:22:57 -07:00
|
|
|
// This size of image might be blank image received from GameStream.
|
2018-08-27 01:54:58 -07:00
|
|
|
// TODO: Improve no-app image detection
|
2016-07-31 14:40:08 -07:00
|
|
|
if (!(appImage.size.width == 130.f && appImage.size.height == 180.f) && // GFE 2.0
|
|
|
|
|
!(appImage.size.width == 628.f && appImage.size.height == 888.f)) { // GFE 3.0
|
2015-07-10 21:22:57 -07:00
|
|
|
_appButton.frame = CGRectMake(0, 0, appImage.size.width / 2, appImage.size.height / 2);
|
|
|
|
|
self.frame = CGRectMake(0, 0, appImage.size.width / 2, appImage.size.height / 2);
|
|
|
|
|
_appOverlay.frame = CGRectMake(0, 0, self.frame.size.width / 2.f, self.frame.size.height / 4.f);
|
|
|
|
|
_appOverlay.layer.shadowRadius = 4.0;
|
|
|
|
|
[_appOverlay setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/6)];
|
|
|
|
|
[_appButton setBackgroundImage:appImage forState:UIControlStateNormal];
|
|
|
|
|
[self setNeedsDisplay];
|
|
|
|
|
} else {
|
|
|
|
|
noAppImage = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
noAppImage = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (noAppImage) {
|
2015-01-05 14:32:11 +09:00
|
|
|
_appLabel = [[UILabel alloc] init];
|
|
|
|
|
CGFloat padding = 4.f;
|
|
|
|
|
[_appLabel setFrame: CGRectMake(padding, padding, _appButton.frame.size.width - 2 * padding, _appButton.frame.size.height - 2 * padding)];
|
|
|
|
|
[_appLabel setTextColor:[UIColor whiteColor]];
|
|
|
|
|
[_appLabel setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
|
|
|
|
|
[_appLabel setTextAlignment:NSTextAlignmentCenter];
|
|
|
|
|
[_appLabel setLineBreakMode:NSLineBreakByWordWrapping];
|
|
|
|
|
[_appLabel setNumberOfLines:0];
|
2018-08-26 16:43:45 -07:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
|
[_appLabel setFont:[UIFont systemFontOfSize:16]];
|
|
|
|
|
#endif
|
2015-07-10 21:22:57 -07:00
|
|
|
[_appLabel setText:_app.name];
|
2015-01-05 14:32:11 +09:00
|
|
|
[_appButton addSubview:_appLabel];
|
|
|
|
|
}
|
2015-07-10 21:22:57 -07:00
|
|
|
|
2014-10-24 16:02:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|