Commit 3de447db authored by Felix Paul Kühne's avatar Felix Paul Kühne

VLCRemoteBrowsingTVCell: split artwork lookup code to designated class

parent 10c6ad2c
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <Foundation/Foundation.h>
#import "VLCServerBrowsingController.h"
@interface VLCMDFBrowsingArtworkProvider : NSObject
@property (readwrite, weak) id<VLCRemoteBrowsingCell> artworkReceiver;
- (void)reset;
- (void)searchForArtworkForVideoRelatedString:(NSString *)string;
@end
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCMDFBrowsingArtworkProvider.h"
#import "MetaDataFetcherKit.h"
@interface VLCMDFBrowsingArtworkProvider () <MDFMovieDBFetcherDataRecipient>
{
MDFMovieDBFetcher *_metadataFetcher;
}
@end
@implementation VLCMDFBrowsingArtworkProvider
- (void)reset
{
if (_metadataFetcher) {
[_metadataFetcher cancelAllRequests];
} else {
_metadataFetcher = [[MDFMovieDBFetcher alloc] init];
_metadataFetcher.dataRecipient = self;
_metadataFetcher.shouldDecrapifyInputStrings = YES;
}
}
- (void)searchForArtworkForVideoRelatedString:(NSString *)string
{
[_metadataFetcher searchForMovie:string];
}
#pragma mark - MDFMovieDB
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindMovie:(MDFMovie *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
return;
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
return;
if (details.movieDBID == 0) {
/* we found nothing, let's see if it's a TV show */
[_metadataFetcher searchForTVShow:searchRequest];
return;
}
NSString *imagePath = details.posterPath;
NSArray *sizes = sessionManager.posterSizes;
NSString *imageSize;
if (sizes != nil) {
if (sizes.count > 1) {
imageSize = sizes[1];
} else if (sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath) {
imagePath = details.backdropPath;
sizes = sessionManager.backdropSizes;
if (sizes != nil && sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath)
return;
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
imageSize,
imagePath];
self.artworkReceiver.thumbnailURL = [NSURL URLWithString:thumbnailURLString];
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindMovieForSearchRequest:(NSString *)searchRequest
{
APLog(@"Failed to find a movie for '%@'", searchRequest);
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindTVShow:(MDFTVShow *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
return;
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
return;
NSString *imagePath = details.posterPath;
NSArray *sizes = sessionManager.posterSizes;
NSString *imageSize;
if (sizes != nil) {
if (sizes.count > 1) {
imageSize = sizes[1];
} else if (sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath) {
imagePath = details.backdropPath;
sizes = sessionManager.backdropSizes;
if (sizes != nil && sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath)
return;
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
imageSize,
imagePath];
self.artworkReceiver.thumbnailURL = [NSURL URLWithString:thumbnailURLString];
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindTVShowForSearchRequest:(NSString *)searchRequest
{
APLog(@"failed to find TV show");
}
@end
......@@ -11,13 +11,13 @@
*****************************************************************************/
#import "VLCRemoteBrowsingTVCell.h"
#import "MetaDataFetcherKit.h"
#import "VLCMDFBrowsingArtworkProvider.h"
NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
@interface VLCRemoteBrowsingTVCell () <MDFMovieDBFetcherDataRecipient>
@interface VLCRemoteBrowsingTVCell ()
{
MDFMovieDBFetcher *_metadataFetcher;
VLCMDFBrowsingArtworkProvider *_artworkProvider;
}
@property (nonatomic) IBOutlet NSLayoutConstraint *aspectRationConstraint;
......@@ -30,6 +30,8 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
- (void)awakeFromNib
{
[super awakeFromNib];
_artworkProvider = [[VLCMDFBrowsingArtworkProvider alloc] init];
_artworkProvider.artworkReceiver = self;
[self prepareForReuse];
UILayoutGuide *focusedFrameGuide = self.thumbnailImageView.focusedFrameGuide;
NSLayoutConstraint *constraint = [self.titleLabel.topAnchor constraintEqualToAnchor:focusedFrameGuide.bottomAnchor];
......@@ -39,13 +41,7 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
- (void)prepareForReuse
{
[super prepareForReuse];
if (_metadataFetcher) {
[_metadataFetcher cancelAllRequests];
} else {
_metadataFetcher = [[MDFMovieDBFetcher alloc] init];
_metadataFetcher.dataRecipient = self;
_metadataFetcher.shouldDecrapifyInputStrings = YES;
}
[_artworkProvider reset];
[self.thumbnailImageView cancelLoading];
self.title = nil;
self.subtitle = nil;
......@@ -59,7 +55,7 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
} else {
NSString *searchString = self.title;
if (searchString != nil && !_isDirectory) {
[_metadataFetcher searchForMovie:searchString];
[_artworkProvider searchForArtworkForVideoRelatedString:searchString];
}
}
}
......@@ -78,7 +74,7 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
{
self.titleLabel.text = title;
if (title != nil && !_isDirectory) {
[_metadataFetcher searchForMovie:title];
[_artworkProvider searchForArtworkForVideoRelatedString:title];
}
}
......@@ -97,98 +93,4 @@ NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
return self.subtitleLabel.text;
}
#pragma mark - MDFMovieDB
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindMovie:(MDFMovie *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
return;
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
return;
if (details.movieDBID == 0) {
/* we found nothing, let's see if it's a TV show */
[_metadataFetcher searchForTVShow:searchRequest];
return;
}
NSString *imagePath = details.posterPath;
NSArray *sizes = sessionManager.posterSizes;
NSString *imageSize;
if (sizes != nil) {
if (sizes.count > 1) {
imageSize = sizes[1];
} else if (sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath) {
imagePath = details.backdropPath;
sizes = sessionManager.backdropSizes;
if (sizes != nil && sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath)
return;
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
imageSize,
imagePath];
self.thumbnailURL = [NSURL URLWithString:thumbnailURLString];
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindMovieForSearchRequest:(NSString *)searchRequest
{
APLog(@"Failed to find a movie for '%@'", searchRequest);
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFindTVShow:(MDFTVShow *)details forSearchRequest:(NSString *)searchRequest
{
if (details == nil)
return;
[aFetcher cancelAllRequests];
MDFMovieDBSessionManager *sessionManager = [MDFMovieDBSessionManager sharedInstance];
if (!sessionManager.hasFetchedProperties)
return;
NSString *imagePath = details.posterPath;
NSArray *sizes = sessionManager.posterSizes;
NSString *imageSize;
if (sizes != nil) {
if (sizes.count > 1) {
imageSize = sizes[1];
} else if (sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath) {
imagePath = details.backdropPath;
sizes = sessionManager.backdropSizes;
if (sizes != nil && sizes.count > 0) {
imageSize = sizes.firstObject;
}
}
if (!imagePath)
return;
NSString *thumbnailURLString = [NSString stringWithFormat:@"%@%@%@",
sessionManager.imageBaseURL,
imageSize,
imagePath];
self.thumbnailURL = [NSURL URLWithString:thumbnailURLString];
}
- (void)MDFMovieDBFetcher:(MDFMovieDBFetcher *)aFetcher didFailToFindTVShowForSearchRequest:(NSString *)searchRequest
{
APLog(@"failed to find TV show");
}
@end
......@@ -57,6 +57,7 @@
7D168F7118D4A21B003FAF59 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D168F7018D4A21B003FAF59 /* Accelerate.framework */; };
7D168F7418D4A33F003FAF59 /* UIImage+Blur.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D168F7318D4A33F003FAF59 /* UIImage+Blur.m */; };
7D18F0A21B34522000651A30 /* VLCActivityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D18F0A11B34522000651A30 /* VLCActivityManager.m */; };
7D1A2DB11BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D1A2DB01BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m */; };
7D1FEBD41BA3184A00D1058E /* libTVVLCKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D1FEBD31BA3184A00D1058E /* libTVVLCKit.a */; };
7D27EB9419DEE11900EF0370 /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D27EB9319DEE11900EF0370 /* Launch Screen.xib */; };
7D27EC2B19DF310300EF0370 /* VLCFirstStepsSecondPageViewController~ipad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D27EC2919DF310300EF0370 /* VLCFirstStepsSecondPageViewController~ipad.xib */; };
......@@ -566,6 +567,8 @@
7D18F0A01B34522000651A30 /* VLCActivityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCActivityManager.h; path = Sources/VLCActivityManager.h; sourceTree = SOURCE_ROOT; };
7D18F0A11B34522000651A30 /* VLCActivityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCActivityManager.m; path = Sources/VLCActivityManager.m; sourceTree = SOURCE_ROOT; };
7D19492B17C661A300959800 /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/Localizable.strings; sourceTree = "<group>"; };
7D1A2DAF1BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMDFBrowsingArtworkProvider.h; sourceTree = "<group>"; };
7D1A2DB01BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCMDFBrowsingArtworkProvider.m; sourceTree = "<group>"; };
7D1AB27C179C98BF004CC271 /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Localizable.strings; sourceTree = "<group>"; };
7D1AB281179C98CD004CC271 /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
7D1AB286179C98D4004CC271 /* sk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Localizable.strings; sourceTree = "<group>"; };
......@@ -1853,6 +1856,8 @@
7DF383AB1BF206F100D71A5C /* VLCRemoteBrowsingCollectionViewController.m */,
DD3EABE71BE13D5B003668DA /* VLCRemoteBrowsingTVCell.h */,
DD3EABE81BE13D5B003668DA /* VLCRemoteBrowsingTVCell.m */,
7D1A2DAF1BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.h */,
7D1A2DB01BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m */,
);
name = "Common Code";
sourceTree = "<group>";
......@@ -2722,6 +2727,7 @@
7DC5A3E71BF6370800CFEBA8 /* VLCRemotePlaybackViewController.m in Sources */,
DDEAECF11BDFE9E800756C83 /* VLCServerListTVViewController.m in Sources */,
7DEC8BDE1BD67899006E1093 /* VLCFullscreenMovieTVViewController.m in Sources */,
7D1A2DB11BF66335002E0962 /* VLCMDFBrowsingArtworkProvider.m in Sources */,
DD3EFF501BDEBCE500B68579 /* VLCPlexParser.m in Sources */,
7D405ED31BEA11CD006ED886 /* VLCHTTPUploaderController.m in Sources */,
7DF90B4B1BE7A8110059C0E3 /* IASKSpecifier.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment