瀏覽代碼

Fix a few warnings because of referencing private atributes from
closures. Using private properties instead.

David Cordero 6 年之前
父節點
當前提交
3a9b4d8681

+ 38 - 34
Apple-TV/Playback/Playback Info/VLCPlaybackInfoSubtitlesFetcherViewController.m

@@ -18,11 +18,11 @@
 #define SPUDownloadHeaderReUseIdentifier @"SPUDownloadHeaderReUseIdentifier"
 
 @interface VLCPlaybackInfoSubtitlesFetcherViewController () <UITableViewDataSource, UITableViewDelegate, MDFOSOFetcherDataRecipient>
-{
-    MDFOSOFetcher *_osoFetcher;
-    NSArray <MDFSubtitleItem *>* _searchResults;
-    UIActivityIndicatorView *_activityIndicatorView;
-}
+
+@property (strong, nonatomic) MDFOSOFetcher *osoFetcher;
+@property (strong, nonatomic) NSArray<MDFSubtitleItem *>* searchResults;
+@property (strong, nonatomic) UIActivityIndicatorView *activityIndicatorView;
+
 @end
 
 @implementation VLCPlaybackInfoSubtitlesFetcherViewController
@@ -33,10 +33,10 @@
     self.titleLabel.text = self.title;
     self.tableView.backgroundColor = [UIColor clearColor];
 
-    _osoFetcher = [[MDFOSOFetcher alloc] init];
-    _osoFetcher.userAgentKey = @"VLSub 0.9";
-    _osoFetcher.dataRecipient = self;
-    [_osoFetcher prepareForFetching];
+    self.osoFetcher = [[MDFOSOFetcher alloc] init];
+    self.osoFetcher.userAgentKey = @"VLSub 0.9";
+    self.osoFetcher.dataRecipient = self;
+    [self.osoFetcher prepareForFetching];
 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     NSString *selectedLocale = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
@@ -53,15 +53,15 @@
         }
         [defaults setObject:selectedLocale forKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
     }
-    _osoFetcher.subtitleLanguageId = selectedLocale;
+    self.osoFetcher.subtitleLanguageId = selectedLocale;
 
-    _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
-    [_activityIndicatorView sizeToFit];
-    [_activityIndicatorView setTranslatesAutoresizingMaskIntoConstraints:NO];
-    _activityIndicatorView.hidesWhenStopped = YES;
-    [self.view addSubview:_activityIndicatorView];
+    self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
+    [self.activityIndicatorView sizeToFit];
+    [self.activityIndicatorView setTranslatesAutoresizingMaskIntoConstraints:NO];
+    self.activityIndicatorView.hidesWhenStopped = YES;
+    [self.view addSubview:self.activityIndicatorView];
 
-    NSLayoutConstraint *yConstraint = [NSLayoutConstraint constraintWithItem:_activityIndicatorView
+    NSLayoutConstraint *yConstraint = [NSLayoutConstraint constraintWithItem:self.activityIndicatorView
                                                                    attribute:NSLayoutAttributeCenterY
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:self.view
@@ -69,7 +69,7 @@
                                                                   multiplier:1.0
                                                                     constant:0.0];
     [self.view addConstraint:yConstraint];
-    NSLayoutConstraint *xConstraint = [NSLayoutConstraint constraintWithItem:_activityIndicatorView
+    NSLayoutConstraint *xConstraint = [NSLayoutConstraint constraintWithItem:self.activityIndicatorView
                                                                    attribute:NSLayoutAttributeCenterX
                                                                    relatedBy:NSLayoutRelationEqual
                                                                       toItem:self.view
@@ -96,8 +96,9 @@
 
 - (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher readyToSearch:(BOOL)bValue
 {
-    if (!bValue)
+    if (!bValue) {
         return;
+    }
 
     [self searchForMedia];
 }
@@ -107,14 +108,14 @@
     [self startActivity];
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    _osoFetcher.subtitleLanguageId = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
-    [_osoFetcher searchForSubtitlesWithQuery:vpc.metadata.title];
+    self.osoFetcher.subtitleLanguageId = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
+    [self.osoFetcher searchForSubtitlesWithQuery:vpc.metadata.title];
 }
 
 - (void)MDFOSOFetcher:(MDFOSOFetcher *)aFetcher didFindSubtitles:(NSArray<MDFSubtitleItem *> *)subtitles forSearchRequest:(NSString *)searchRequest
 {
     [self stopActivity];
-    _searchResults = subtitles;
+    self.searchResults = subtitles;
     [self.tableView reloadData];
 }
 
@@ -143,11 +144,12 @@
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
-    if (section == 0)
+    if (section == 0) {
         return 1;
+    }
 
-    if (_searchResults) {
-        return _searchResults.count;
+    if (self.searchResults) {
+        return self.searchResults.count;
     }
 
     return 0;
@@ -157,11 +159,12 @@
 {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SPUDownloadReUseIdentifier];
 
-    if (!cell)
+    if (!cell) {
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:SPUDownloadReUseIdentifier];
-
+    }
+    
     if (indexPath.section != 0) {
-        MDFSubtitleItem *item = _searchResults[indexPath.row];
+        MDFSubtitleItem *item = self.searchResults[indexPath.row];
         cell.textLabel.text = item.name;
         cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", item.rating, [item.format uppercaseStringWithLocale:[NSLocale currentLocale]]];
         cell.accessoryType = UITableViewCellAccessoryNone;
@@ -178,8 +181,9 @@
 
 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
 {
-    if (section == 0)
+    if (section == 0) {
         return @"";
+    }
 
     return NSLocalizedString(@"FOUND_SUBS", nil);
 }
@@ -192,7 +196,7 @@
         UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"LANGUAGE", nil)
                                                                                  message:nil preferredStyle:UIAlertControllerStyleActionSheet];
 
-        NSArray<MDFSubtitleLanguage *> *languages = _osoFetcher.availableLanguages;
+        NSArray<MDFSubtitleLanguage *> *languages = self.osoFetcher.availableLanguages;
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSString *currentCode = [defaults stringForKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
 
@@ -201,7 +205,7 @@
             UIAlertAction *action = [UIAlertAction actionWithTitle:item.localizedName
                                                              style:UIAlertActionStyleDefault
                                                            handler:^(UIAlertAction * _Nonnull action) {
-                                                               _osoFetcher.subtitleLanguageId = itemID;
+                                                               self.osoFetcher.subtitleLanguageId = itemID;
                                                                [defaults setObject:itemID forKey:kVLCSettingLastUsedSubtitlesSearchLanguage];
                                                                [self searchForMedia];
                                                                [self.tableView reloadData];
@@ -218,24 +222,24 @@
         [self presentViewController:alertController animated:YES completion:nil];
     } else {
         [self startActivity];
-        MDFSubtitleItem *item = _searchResults[indexPath.row];
+        MDFSubtitleItem *item = self.searchResults[indexPath.row];
         NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
         NSString *folderPath = [searchPaths[0] stringByAppendingPathComponent:@"tempsubs"];
         [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
         NSString *subStorageLocation = [folderPath stringByAppendingPathComponent:item.name];
-        [_osoFetcher downloadSubtitleItem:item toPath:subStorageLocation];
+        [self.osoFetcher downloadSubtitleItem:item toPath:subStorageLocation];
     }
 }
 
 - (void)startActivity
 {
-    [_activityIndicatorView startAnimating];
+    [self.activityIndicatorView startAnimating];
     self.tableView.userInteractionEnabled = NO;
 }
 
 - (void)stopActivity
 {
-    [_activityIndicatorView stopAnimating];
+    [self.activityIndicatorView stopAnimating];
     self.tableView.userInteractionEnabled = YES;
 }
 

+ 13 - 8
Apple-TV/Playback/Playback Info/VLCPlaybackInfoTVCollectionViewCell.m

@@ -11,9 +11,14 @@
 
 #import "VLCPlaybackInfoTVCollectionViewCell.h"
 
-@implementation VLCPlaybackInfoTVCollectionViewCell {
-    UIColor *textColor;
-}
+
+@interface VLCPlaybackInfoTVCollectionViewCell()
+
+@property (strong, nonatomic) UIColor *textColor;
+
+@end
+
+@implementation VLCPlaybackInfoTVCollectionViewCell
 
 + (NSString *)identifier
 {
@@ -42,19 +47,19 @@
     self.selectionMarkerVisible = NO;
     self.titleLabel.text = nil;
     if ([UIScreen mainScreen].traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
-        textColor = [UIColor VLCDarkFadedTextColor];
+        self.textColor = [UIColor VLCDarkFadedTextColor];
     } else {
-        textColor = [UIColor VLCDarkTextColor];
+        self.textColor = [UIColor VLCDarkTextColor];
     }
-    self.selectionMarkerView.textColor = textColor;
-    self.titleLabel.textColor = textColor;
+    self.selectionMarkerView.textColor = self.textColor;
+    self.titleLabel.textColor = self.textColor;
 }
 
 - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
 {
     [super didUpdateFocusInContext:context withAnimationCoordinator:coordinator];
     [coordinator addCoordinatedAnimations:^{
-        self.titleLabel.textColor = self.focused ? [UIColor whiteColor] : textColor;
+        self.titleLabel.textColor = self.focused ? [UIColor whiteColor] : self.textColor;
     } completion:nil];
 }
 

+ 48 - 46
Sources/VLCDropboxController.m

@@ -19,19 +19,18 @@
 #import "VLCDropboxConstants.h"
 
 @interface VLCDropboxController ()
-{
-    DBUserClient *_client;
-    NSArray *_currentFileList;
 
-    NSMutableArray *_listOfDropboxFilesToDownload;
-    BOOL _downloadInProgress;
+@property (strong, nonatomic) DBUserClient *client;
+@property (strong, nonatomic) NSArray *currentFileList;
 
-    CGFloat _averageSpeed;
-    NSTimeInterval _startDL;
-    NSTimeInterval _lastStatsUpdate;
+@property (strong, nonatomic) NSMutableArray *listOfDropboxFilesToDownload;
+@property (assign, nonatomic) BOOL downloadInProgress;
 
-    UINavigationController *_lastKnownNavigationController;
-}
+@property (assign, nonatomic) CGFloat averageSpeed;
+@property (assign, nonatomic) NSTimeInterval startDL;
+@property (assign, nonatomic) NSTimeInterval lastStatsUpdate;
+
+@property (strong, nonatomic) UINavigationController *lastKnownNavigationController;
 
 @end
 
@@ -69,8 +68,9 @@
     NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
     [ubiquitousStore synchronize];
     NSArray *credentials = [ubiquitousStore arrayForKey:kVLCStoreDropboxCredentials];
-    if (!credentials)
+    if (!credentials) {
         return NO;
+    }
     for (NSString *tmp in credentials) {
         [DBSDKKeychain storeValueWithKey:kVLCStoreDropboxCredentials value:tmp];
     }
@@ -122,8 +122,9 @@
         NSString *rawFileName = [fileName stringByDeletingPathExtension];
         for (NSUInteger x = 1; x < 100; x++) {
             potentialFilename = [NSString stringWithFormat:@"%@_%lu.%@", rawFileName, (unsigned long)x, fileExtension];
-            if (![fileManager fileExistsAtPath:[finalFilePath stringByAppendingPathComponent:potentialFilename]])
+            if (![fileManager fileExistsAtPath:[finalFilePath stringByAppendingPathComponent:potentialFilename]]) {
                 break;
+            }
         }
         return [finalFilePath stringByAppendingPathComponent:potentialFilename];
     }
@@ -137,19 +138,22 @@
 
 - (void)requestDirectoryListingAtPath:(NSString *)path
 {
-    if (self.isAuthorized)
+    if (self.isAuthorized) {
         [self listFiles:path];
+    }
 }
 
 - (void)downloadFileToDocumentFolder:(DBFILESMetadata *)file
 {
     if (![file isKindOfClass:[DBFILESFolderMetadata class]]) {
-        if (!_listOfDropboxFilesToDownload)
-            _listOfDropboxFilesToDownload = [[NSMutableArray alloc] init];
-        [_listOfDropboxFilesToDownload addObject:file];
+        if (!self.listOfDropboxFilesToDownload) {
+            self.listOfDropboxFilesToDownload = [[NSMutableArray alloc] init];
+        }
+        [self.listOfDropboxFilesToDownload addObject:file];
 
-        if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
+        if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)]) {
             [self.delegate numberOfFilesWaitingToBeDownloadedChanged];
+        }
 
         [self _triggerNextDownload];
     }
@@ -157,12 +161,13 @@
 
 - (void)_triggerNextDownload
 {
-    if (_listOfDropboxFilesToDownload.count > 0 && !_downloadInProgress) {
-        [self _reallyDownloadFileToDocumentFolder:_listOfDropboxFilesToDownload[0]];
-        [_listOfDropboxFilesToDownload removeObjectAtIndex:0];
+    if (self.listOfDropboxFilesToDownload.count > 0 && !self.downloadInProgress) {
+        [self _reallyDownloadFileToDocumentFolder:self.listOfDropboxFilesToDownload[0]];
+        [self.listOfDropboxFilesToDownload removeObjectAtIndex:0];
 
-        if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
+        if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)]) {
             [self.delegate numberOfFilesWaitingToBeDownloadedChanged];
+        }
     }
 }
 
@@ -170,14 +175,15 @@
 {
     NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *filePath = [searchPaths[0] stringByAppendingFormat:@"/%@", file.name];
-    _startDL = [NSDate timeIntervalSinceReferenceDate];
+    self.startDL = [NSDate timeIntervalSinceReferenceDate];
 
     [self downloadFileFrom:file.pathDisplay to:filePath];
 
-    if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)])
+    if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)]) {
         [self.delegate operationWithProgressInformationStarted];
+    }
 
-    _downloadInProgress = YES;
+    self.downloadInProgress = YES;
 }
 
 - (void)streamFile:(DBFILESMetadata *)file currentNavigationController:(UINavigationController *)navigationController
@@ -198,12 +204,12 @@
     }
     [[[self client].filesRoutes listFolder:path] setResponseBlock:^(DBFILESListFolderResult * _Nullable result, DBFILESListFolderError * _Nullable routeError, DBRequestError * _Nullable networkError) {
         if (result) {
-            self->_currentFileList = [result.entries sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
+            self.currentFileList = [result.entries sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
                 NSString *first = [(DBFILESMetadata*)a name];
                 NSString *second = [(DBFILESMetadata*)b name];
                 return [first caseInsensitiveCompare:second];
             }];
-            APLog(@"found filtered metadata for %lu files", (unsigned long)self->_currentFileList.count);
+            APLog(@"found filtered metadata for %lu files", (unsigned long)self.currentFileList.count);
             if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
                 [self.delegate mediaListUpdated];
         } else {
@@ -230,14 +236,14 @@
 
     destination = [self _createPotentialNameFrom:destination];
 
-    [[[_client.filesRoutes downloadUrl:path overwrite:YES destination:[NSURL URLWithString:destination]]
+    [[[self.client.filesRoutes downloadUrl:path overwrite:YES destination:[NSURL URLWithString:destination]]
         setResponseBlock:^(DBFILESFileMetadata * _Nullable result, DBFILESDownloadError * _Nullable routeError, DBRequestError * _Nullable networkError, NSURL * _Nonnull destination) {
 
             if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)]) {
                 [self.delegate operationWithProgressInformationStopped];
             }
 
-            self->_downloadInProgress = NO;
+            self.downloadInProgress = NO;
             [self _triggerNextDownload];
             if (networkError) {
                 APLog(@"downloadFile failed with network error %li and error tag %li", (long)networkError.statusCode, (long)networkError.tag);
@@ -248,9 +254,9 @@
                 UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, NSLocalizedString(@"GDRIVE_DOWNLOAD_SUCCESSFUL", nil));
             }
 
-            if ((self->_lastStatsUpdate > 0 && ([NSDate timeIntervalSinceReferenceDate] - self->_lastStatsUpdate > .5)) || self->_lastStatsUpdate <= 0) {
+            if ((self.lastStatsUpdate > 0 && ([NSDate timeIntervalSinceReferenceDate] - self.lastStatsUpdate > .5)) || self.lastStatsUpdate <= 0) {
                 [self calculateRemainingTime:(CGFloat)totalBytesWritten expectedDownloadSize:(CGFloat)totalBytesExpectedToWrite];
-                self->_lastStatsUpdate = [NSDate timeIntervalSinceReferenceDate];
+                self.lastStatsUpdate = [NSDate timeIntervalSinceReferenceDate];
             }
 
             if ([self.delegate respondsToSelector:@selector(currentProgressInformation:)])
@@ -266,7 +272,7 @@
         return;
     }
 
-    [[_client.filesRoutes getTemporaryLink:path] setResponseBlock:^(DBFILESGetTemporaryLinkResult * _Nullable result, DBFILESGetTemporaryLinkError * _Nullable routeError, DBRequestError * _Nullable networkError) {
+    [[self.client.filesRoutes getTemporaryLink:path] setResponseBlock:^(DBFILESGetTemporaryLinkResult * _Nullable result, DBFILESGetTemporaryLinkError * _Nullable routeError, DBRequestError * _Nullable networkError) {
 
         if (result) {
             VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:result.link]];
@@ -274,9 +280,9 @@
             [medialist addMedia:media];
             [[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
 #if TARGET_OS_TV
-            if (_lastKnownNavigationController) {
+            if (self.lastKnownNavigationController) {
                 VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
-                [_lastKnownNavigationController presentViewController:movieVC
+                [self.lastKnownNavigationController presentViewController:movieVC
                                                              animated:YES
                                                            completion:nil];
             }
@@ -292,11 +298,11 @@
 
 - (void)calculateRemainingTime:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
 {
-    CGFloat lastSpeed = receivedDataSize / ([NSDate timeIntervalSinceReferenceDate] - _startDL);
+    CGFloat lastSpeed = receivedDataSize / ([NSDate timeIntervalSinceReferenceDate] - self.startDL);
     CGFloat smoothingFactor = 0.005;
-    _averageSpeed = isnan(_averageSpeed) ? lastSpeed : smoothingFactor * lastSpeed + (1 - smoothingFactor) * _averageSpeed;
+    self.averageSpeed = isnan(self.averageSpeed) ? lastSpeed : smoothingFactor * lastSpeed + (1 - smoothingFactor) * self.averageSpeed;
 
-    CGFloat RemainingInSeconds = (expectedDownloadSize - receivedDataSize)/_averageSpeed;
+    CGFloat RemainingInSeconds = (expectedDownloadSize - receivedDataSize)/self.averageSpeed;
 
     NSDate *date = [NSDate dateWithTimeIntervalSince1970:RemainingInSeconds];
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
@@ -304,20 +310,16 @@
     [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
 
     NSString  *remaingTime = [formatter stringFromDate:date];
-    if ([self.delegate respondsToSelector:@selector(updateRemainingTime:)])
+    if ([self.delegate respondsToSelector:@selector(updateRemainingTime:)]) {
         [self.delegate updateRemainingTime:remaingTime];
-}
-
-- (NSArray *)currentListFiles
-{
-    return _currentFileList;
+    }
 }
 
 - (NSInteger)numberOfFilesWaitingToBeDownloaded
 {
-    if (_listOfDropboxFilesToDownload)
-        return _listOfDropboxFilesToDownload.count;
-
+    if (self.listOfDropboxFilesToDownload) {
+        return self.listOfDropboxFilesToDownload.count;
+    }
     return 0;
 }
 
@@ -340,7 +342,7 @@
 
 - (void)reset
 {
-    _currentFileList = nil;
+    self.currentFileList = nil;
 }
 
 @end