Commit cd4ccaee authored by Felix Paul Kühne's avatar Felix Paul Kühne

Various cleanups and modernizations

parent 941ad45d
......@@ -46,7 +46,7 @@
* \return the current receiver
* \note should be set before doing any requests
*/
@property (weak, nonatomic) id<MDFMovieDBFetcherDataRecipient> dataRecipient;
@property (weak, nonatomic, nullable) id<MDFMovieDBFetcherDataRecipient> dataRecipient;
/**
* The fetcher can process input strings by removing stray characters, file extensions, etc.,
......
......@@ -96,8 +96,8 @@
NSURLSessionTask *task = [sessionManager GET:@"search/movie"
parameters:parameters
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
@synchronized(_requests) {
[_requests removeObject:task];
@synchronized(self->_requests) {
[self->_requests removeObject:task];
}
MDFMovie *movie;
......@@ -129,8 +129,8 @@
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
@synchronized(_requests) {
[_requests removeObject:task];
@synchronized(self->_requests) {
[self->_requests removeObject:task];
}
if (self.dataRecipient) {
......@@ -184,8 +184,8 @@
NSURLSessionTask *task = [sessionManager GET:@"search/tv"
parameters:parameters
success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) {
@synchronized(_requests) {
[_requests removeObject:task];
@synchronized(self->_requests) {
[self->_requests removeObject:task];
}
MDFTVShow *tvShow;
......@@ -216,8 +216,8 @@
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
@synchronized(_requests) {
[_requests removeObject:task];
@synchronized(self->_requests) {
[self->_requests removeObject:task];
}
if (self.dataRecipient) {
......
......@@ -22,9 +22,8 @@
*****************************************************************************/
#import <Foundation/Foundation.h>
#import "AFNetworking.h"
@interface MDFMovieDBSessionManager : AFHTTPSessionManager
@interface MDFMovieDBSessionManager : NSObject
+ (_Nonnull instancetype)sharedInstance;
......@@ -77,4 +76,9 @@
* the properties for image sizes */
- (void)fetchProperties;
- (nullable NSURLSessionDataTask *)GET:(nonnull NSString *)URLString
parameters:(nullable id)parameters
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *_Nullable error))failure;
@end
......@@ -22,17 +22,18 @@
*****************************************************************************/
#import "MDFMovieDBSessionManager.h"
#import "AFNetworking/AFNetworking.h"
static NSString * const MovieDBBaseURLString = @"https://api.themoviedb.org/3/";
static AFHTTPSessionManager *_sharedClient = nil;
@implementation MDFMovieDBSessionManager
+ (instancetype)sharedInstance
{
static MDFMovieDBSessionManager *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[MDFMovieDBSessionManager alloc] initWithBaseURL:[NSURL URLWithString:MovieDBBaseURLString]];
_sharedClient = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:MovieDBBaseURLString]];
_sharedClient.requestSerializer = [AFJSONRequestSerializer serializer];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
......@@ -41,7 +42,7 @@ static NSString * const MovieDBBaseURLString = @"https://api.themoviedb.org/3/";
_sharedClient.securityPolicy = securityPolicy;
});
return _sharedClient;
return (MDFMovieDBSessionManager *)_sharedClient;
}
- (NSString *)description
......@@ -58,19 +59,24 @@ static NSString * const MovieDBBaseURLString = @"https://api.themoviedb.org/3/";
success:^(NSURLSessionDataTask * __unused task, NSDictionary * responseObject) {
NSDictionary *images = responseObject[@"images"];
if (images != nil) {
_secureImageBaseURL = images[@"secure_base_url"];
_imageBaseURL = images[@"base_url"];
_backdropSizes = images[@"backdrop_sizes"];
_logoSizes = images[@"logo_sizes"];
_posterSizes = images[@"poster_sizes"];
_profileSizes = images[@"profile_sizes"];
_stillSizes = images[@"still_sizes"];
_hasFetchedProperties = YES;
self->_secureImageBaseURL = images[@"secure_base_url"];
self->_imageBaseURL = images[@"base_url"];
self->_backdropSizes = images[@"backdrop_sizes"];
self->_logoSizes = images[@"logo_sizes"];
self->_posterSizes = images[@"poster_sizes"];
self->_profileSizes = images[@"profile_sizes"];
self->_stillSizes = images[@"still_sizes"];
self->_hasFetchedProperties = YES;
}
} failure:^(NSURLSessionDataTask * __unused task, NSError *error) {
NSLog(@"%@", error);
_hasFetchedProperties = NO;
self->_hasFetchedProperties = NO;
}];
}
- (NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(id)parameters success:(void (^)(NSURLSessionDataTask * _Nullable, id _Nullable))success failure:(void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nullable))failure
{
return [_sharedClient GET:URLString parameters:parameters success:success failure:failure];
}
@end
......@@ -49,7 +49,7 @@
* \return the current receiver
* \note should be set before doing any requests
*/
@property (weak, nonatomic) id<MDFOSOFetcherDataRecipient> dataRecipient;
@property (weak, nonatomic, nullable) id <MDFOSOFetcherDataRecipient> dataRecipient;
- (void)prepareForFetching;
......@@ -64,7 +64,7 @@
/**
* search for the list of languages potentially available on the website
*/
@property (readonly, nonatomic, copy) NSArray *availableLanguages;
@property (readonly, nonatomic, copy, nullable) NSArray * availableLanguages;
/**
* the language ID (ISO-639-3) to use for the fetches
......
......@@ -119,7 +119,7 @@
[languageItems addObject:item];
}
_availableLanguages = [languageItems copy];
self->_availableLanguages = [languageItems copy];
[self openSubtitlerDidLogIn:nil];
}];
......
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