Commit d50e916a authored by Carola's avatar Carola
Browse files

added reusable progressView (close #11998)

parent 62c2784f
......@@ -22,6 +22,7 @@
#import "VLCDropboxConstants.h"
#import "UIBarButtonItem+Theme.h"
#import <DropboxSDK/DropboxSDK.h>
#import "VLCProgressView.h"
@interface VLCDropboxTableViewController () <VLCCloudStorageTableViewCell, VLCDropboxController>
{
......@@ -34,8 +35,7 @@
UIBarButtonItem *_numberOfFilesBarButtonItem;
UIBarButtonItem *_progressBarButtonItem;
UIBarButtonItem *_downloadingBarLabel;
UIProgressView *_progressBar;
UILabel *_progressLabel;
VLCProgressView *_progressView;
UIActivityIndicatorView *_activityIndicator;
DBMetadata *_selectedFile;
......@@ -70,24 +70,9 @@
_numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
[_numberOfFilesBarButtonItem setTitleTextAttributes:@{ UITextAttributeFont : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
_progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
_progressLabel = [[UILabel alloc] init];
_progressLabel.textColor = [UIColor whiteColor];
_progressLabel.font = [UIFont systemFontOfSize:11.];
UIView *progressView = [[UIView alloc] init];
[progressView addSubview:_progressBar];
[progressView addSubview:_progressLabel];
[progressView addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
[progressView addConstraint:[NSLayoutConstraint constraintWithItem:progressView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
[progressView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_progressBar]-[_progressLabel]-|" options:NSLayoutFormatAlignAllCenterX metrics:nil views:NSDictionaryOfVariableBindings(_progressBar, _progressLabel)]];
progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressLabel.translatesAutoresizingMaskIntoConstraints = NO;
_progressBar.translatesAutoresizingMaskIntoConstraints = NO;
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:progressView];
_progressView = [VLCProgressView new];
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
[self.cloudStorageLogo setImage:[UIImage imageNamed:@"dropbox-white.png"]];
if (!SYSTEM_RUNS_IOS7_OR_LATER) {
......@@ -134,7 +119,7 @@
if (!value)
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
else {
_progressBar.progress = 0.;
_progressView.progressBar.progress = 0.;
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
}
}
......@@ -246,13 +231,12 @@
- (void)updateRemainingTime:(NSString *)time
{
[_progressLabel setText:[NSString stringWithFormat:NSLocalizedString(@"REMAINING_TIME", nil), time]];
CGSize size = [_progressLabel.text sizeWithFont:_progressLabel.font];
[_progressLabel setFrame:CGRectMake(_progressLabel.frame.origin.x, _progressLabel.frame.origin.y, size.width, size.height)];
[_progressView updateTime:time];
}
- (void)currentProgressInformation:(float)progress {
[_progressBar setProgress:progress animated:YES];
- (void)currentProgressInformation:(float)progress
{
[_progressView.progressBar setProgress:progress animated:YES];
}
- (void)operationWithProgressInformationStopped
......
......@@ -16,6 +16,7 @@
#import "VLCGoogleDriveController.h"
#import "VLCAppDelegate.h"
#import "UIBarButtonItem+Theme.h"
#import "VLCProgressView.h"
@interface VLCGoogleDriveTableViewController () <VLCCloudStorageTableViewCell, VLCGoogleDriveController>
{
......@@ -29,8 +30,8 @@
UIBarButtonItem *_numberOfFilesBarButtonItem;
UIBarButtonItem *_progressBarButtonItem;
UIProgressView *_progressBar;
UILabel *_progressLabel;
VLCProgressView *_progressView;
UIActivityIndicatorView *_activityIndicator;
......@@ -67,25 +68,8 @@
_numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
[_numberOfFilesBarButtonItem setTitleTextAttributes:@{ UITextAttributeFont : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
_progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
_progressLabel = [[UILabel alloc] init];
_progressLabel.textColor = [UIColor whiteColor];
_progressLabel.backgroundColor = [UIColor clearColor];
_progressLabel.font = [UIFont systemFontOfSize:11.];
UIView *progressView = [[UIView alloc] init];
[progressView addSubview:_progressBar];
[progressView addSubview:_progressLabel];
[progressView addConstraint:[NSLayoutConstraint constraintWithItem:progressView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
[progressView addConstraint:[NSLayoutConstraint constraintWithItem:_progressBar attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
[progressView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_progressBar]-[_progressLabel]-|" options:NSLayoutFormatAlignAllCenterX metrics:nil views:NSDictionaryOfVariableBindings(_progressBar, _progressLabel)]];
progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressLabel.translatesAutoresizingMaskIntoConstraints = NO;
_progressBar.translatesAutoresizingMaskIntoConstraints = NO;
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:progressView];
_progressView = [VLCProgressView new];
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
[self.cloudStorageLogo setImage:[UIImage imageNamed:@"DriveWhite"]];
......@@ -159,7 +143,7 @@
if (!value)
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
else {
_progressBar.progress = 0.;
_progressView.progressBar.progress = 0.;
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
}
}
......@@ -281,13 +265,11 @@
- (void)updateRemainingTime:(NSString *)time
{
[_progressLabel setText:[NSString stringWithFormat:NSLocalizedString(@"REMAINING_TIME", nil), time]];
CGSize size = [_progressLabel.text sizeWithFont:_progressLabel.font];
[_progressLabel setFrame:CGRectMake(_progressLabel.frame.origin.x, _progressLabel.frame.origin.y, size.width, size.height)];
[_progressView updateTime:time];
}
- (void)currentProgressInformation:(float)progress {
[_progressBar setProgress:progress animated:YES];
[_progressView.progressBar setProgress:progress animated:YES];
}
- (void)operationWithProgressInformationStopped
......
......@@ -46,6 +46,7 @@
4115E60319797B660071C4B9 /* collectionViewIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4115E60119797B660071C4B9 /* collectionViewIcon@2x.png */; };
4171D35018A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 4171D34F18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m */; };
4171D35818A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 4171D35718A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m */; };
41C881101A05B5020010A3C5 /* VLCProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = 41C8810F1A05B5020010A3C5 /* VLCProgressView.m */; };
41F475D21899A438001B919F /* folderIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 41F475CE1899A438001B919F /* folderIcon.png */; };
41F475D31899A438001B919F /* folderIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 41F475CF1899A438001B919F /* folderIcon@2x.png */; };
41F475D41899A438001B919F /* folderIcon@2x~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 41F475D01899A438001B919F /* folderIcon@2x~ipad.png */; };
......@@ -518,6 +519,8 @@
4171D34F18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCFolderCollectionViewFlowLayout.m; path = Sources/VLCFolderCollectionViewFlowLayout.m; sourceTree = SOURCE_ROOT; };
4171D35618A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LXReorderableCollectionViewFlowLayout.h; sourceTree = "<group>"; };
4171D35718A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LXReorderableCollectionViewFlowLayout.m; sourceTree = "<group>"; };
41C8810E1A05B5020010A3C5 /* VLCProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCProgressView.h; sourceTree = SOURCE_ROOT; };
41C8810F1A05B5020010A3C5 /* VLCProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCProgressView.m; sourceTree = SOURCE_ROOT; };
41F475CE1899A438001B919F /* folderIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = folderIcon.png; sourceTree = "<group>"; };
41F475CF1899A438001B919F /* folderIcon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "folderIcon@2x.png"; sourceTree = "<group>"; };
41F475D01899A438001B919F /* folderIcon@2x~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "folderIcon@2x~ipad.png"; sourceTree = "<group>"; };
......@@ -1701,6 +1704,8 @@
7D3784B0183A990F009EE944 /* VLCCloudStorageTableViewCell.m */,
9B088306183D7BEC004B5C2A /* VLCCloudStorageTableViewController.h */,
9B088307183D7BEC004B5C2A /* VLCCloudStorageTableViewController.m */,
41C8810E1A05B5020010A3C5 /* VLCProgressView.h */,
41C8810F1A05B5020010A3C5 /* VLCProgressView.m */,
);
name = "Cloud Integration";
sourceTree = "<group>";
......@@ -2851,6 +2856,7 @@
7DC19B051868D1C400810BF7 /* VLCFirstStepsFifthPageViewController.m in Sources */,
2915543B17490B9C00B86CAD /* HTTPAsyncFileResponse.m in Sources */,
2915543C17490B9C00B86CAD /* HTTPDataResponse.m in Sources */,
41C881101A05B5020010A3C5 /* VLCProgressView.m in Sources */,
2915543D17490B9C00B86CAD /* HTTPDynamicFileResponse.m in Sources */,
9BADAF45185FBD9D00108BD8 /* VLCFrostedGlasView.m in Sources */,
2915543E17490B9C00B86CAD /* HTTPErrorResponse.m in Sources */,
......
/*****************************************************************************
* VLCProgressView.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@interface VLCProgressView : UIView
@property(nonatomic) UIProgressView *progressBar;
@property(nonatomic) UILabel *progressLabel;
- (void)updateTime:(NSString *)time;
@end
/*****************************************************************************
* VLCProgressView.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCProgressView.h"
@implementation VLCProgressView
- (instancetype)init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup
{
self.progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
self.progressLabel = [[UILabel alloc] init];
self.progressLabel.textColor = [UIColor whiteColor];
self.progressLabel.font = [UIFont systemFontOfSize:11.];
self.progressLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.progressBar.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_progressBar];
[self addSubview:_progressLabel];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_progressBar(200)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressBar)]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.progressBar attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_progressBar]-[_progressLabel]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressBar, _progressLabel)]];
}
- (void)updateTime:(NSString *)time
{
[self.progressLabel setText:[NSString stringWithFormat:NSLocalizedString(@"REMAINING_TIME", nil), time]];
CGSize size = [self.progressLabel.text sizeWithFont:self.progressLabel.font];
[self.progressLabel setFrame:CGRectMake(self.progressLabel.frame.origin.x, self.progressLabel.frame.origin.y, size.width, size.height)];
}
@end
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