From 4e283d45431c3b47348b6b3074823c5de573cdeb Mon Sep 17 00:00:00 2001 From: kean Date: Wed, 8 Jan 2025 15:02:50 -0500 Subject: [PATCH] Remove WPProgressTableViewCell --- .../System/WordPress-Bridging-Header.h | 1 - .../Cells/WPProgressTableViewCell.h | 15 --- .../Cells/WPProgressTableViewCell.m | 124 ------------------ .../Post/PostSettingsViewController.m | 3 - .../PostSettingsViewController_Internal.h | 3 - .../StoppableProgressIndicatorView.swift | 117 ----------------- 6 files changed, 263 deletions(-) delete mode 100644 WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h delete mode 100644 WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m delete mode 100644 WordPress/Classes/ViewRelated/Views/StoppableProgressIndicatorView.swift diff --git a/WordPress/Classes/System/WordPress-Bridging-Header.h b/WordPress/Classes/System/WordPress-Bridging-Header.h index cce86c7a3683..01a375ecb212 100644 --- a/WordPress/Classes/System/WordPress-Bridging-Header.h +++ b/WordPress/Classes/System/WordPress-Bridging-Header.h @@ -41,7 +41,6 @@ #import "PostServiceOptions.h" #import "PostSettingsViewController.h" #import "PostSettingsViewController_Internal.h" -#import "WPProgressTableViewCell.h" #import "PostTag.h" #import "PostTagService.h" diff --git a/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h b/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h deleted file mode 100644 index d576ff22671f..000000000000 --- a/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h +++ /dev/null @@ -1,15 +0,0 @@ -@import UIKit; -@import WordPressSharedObjC; - -@class WPTableViewCell; - -/** - The corresponding value is an UIImage instance representing the work being done - */ -extern NSProgressUserInfoKey const WPProgressImageThumbnailKey; - -@interface WPProgressTableViewCell : WPTableViewCell - -- (void) setProgress:(NSProgress *)progress; - -@end diff --git a/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m b/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m deleted file mode 100644 index 099920c77192..000000000000 --- a/WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m +++ /dev/null @@ -1,124 +0,0 @@ -#import "WPProgressTableViewCell.h" -#import "WordPress-Swift.h" - -static void *ProgressObserverContext = &ProgressObserverContext; - -NSProgressUserInfoKey const WPProgressImageThumbnailKey = @"WPProgressImageThumbnailKey"; -@interface WPProgressTableViewCell () - -@property (nonatomic, strong) StoppableProgressIndicatorView * progressView; - -@end - -@implementation WPProgressTableViewCell { - NSProgress *_progress; -} - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier -{ - self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; - if (self) { - _progressView = [[StoppableProgressIndicatorView alloc] initWithFrame:CGRectMake(10.0,0.0,40.0,40.0)]; - _progressView.hidden = YES; - self.accessoryView = _progressView; - } - return self; -} - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - NSAssert(false, @"WPProgressTableViewCell can't be created using a nib"); - return [super initWithCoder:coder]; -} - -- (void)dealloc -{ - [_progress removeObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted))]; -} - -- (void)prepareForReuse -{ - [super prepareForReuse]; - [self setProgress:nil]; - self.progressView.hidden = YES; - self.progressView.hidesWhenStopped=YES; - [self.progressView stopAnimating]; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - self.imageView.frame = CGRectInset(self.imageView.frame, 0.0, 5.0); -} - -#pragma mark - Progress handling - -- (void) setProgress:(NSProgress *) progress { - if (progress == _progress){ - return; - } - [_progress removeObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted))]; - - _progress = progress; - - [_progress addObserver:self - forKeyPath:NSStringFromSelector(@selector(fractionCompleted)) - options:NSKeyValueObservingOptionInitial - context:ProgressObserverContext]; - - if (_progress.isCancellable){ - [self.progressView.stopButton addTarget:self action:@selector(stopPressed:) forControlEvents:UIControlEventTouchUpInside]; - } - [self updateProgress]; -} - -- (void)updateProgress -{ - if (_progress.fractionCompleted < 1 && !_progress.isCancelled) { - [_progressView startAnimating]; - } else { - [_progressView stopAnimating]; - } - - _progressView.mayStop = _progress.isCancellable; - if ([_progress isCancelled]) { - self.textLabel.text = NSLocalizedString(@"Canceled", @"The action was canceled"); - self.detailTextLabel.text = @""; - } else if ((_progress.totalUnitCount == 0 && _progress.completedUnitCount == 0) || _progress.userInfo[@"mediaError"] ) { - self.textLabel.text = NSLocalizedString(@"Failed", @"The action failed"); - self.detailTextLabel.text = @""; - } else if (_progress.fractionCompleted >= 1) { - self.textLabel.text = NSLocalizedString(@"Completed", @"The action is completed"); - self.detailTextLabel.text = @""; - } else { - self.textLabel.text = [_progress localizedDescription]; - self.detailTextLabel.text = [_progress localizedAdditionalDescription]; - } - [self.imageView setImage:_progress.userInfo[WPProgressImageThumbnailKey]]; -} - -#pragma mark - KVO - -- (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(id)object - change:(NSDictionary *)change - context:(void *)context -{ - if (context == ProgressObserverContext && object == _progress) { - [[NSOperationQueue mainQueue] addOperationWithBlock:^{ - [self updateProgress]; - }]; - } else { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } -} - -#pragma mark - Stop Button events - -- (void) stopPressed:(id)sender -{ - [_progress cancel]; - [self updateProgress]; -} - -@end diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m index c731d540caf4..7cb3b8140780 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m @@ -5,9 +5,6 @@ #import "SharingDetailViewController.h" #import "CoreDataStack.h" #import "MediaService.h" -#import "WPProgressTableViewCell.h" -#import -#import #import "WordPress-Swift.h" @import Gridicons; diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController_Internal.h b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController_Internal.h index b801650a2bbe..7be46a2547ac 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController_Internal.h +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController_Internal.h @@ -13,9 +13,6 @@ typedef enum { PostSettingsSectionPageAttributes } PostSettingsSection; - -@class WPProgressTableViewCell; - @interface PostSettingsViewController () @property (nonnull, nonatomic, strong) NSArray *sections; diff --git a/WordPress/Classes/ViewRelated/Views/StoppableProgressIndicatorView.swift b/WordPress/Classes/ViewRelated/Views/StoppableProgressIndicatorView.swift deleted file mode 100644 index d374bd509a3b..000000000000 --- a/WordPress/Classes/ViewRelated/Views/StoppableProgressIndicatorView.swift +++ /dev/null @@ -1,117 +0,0 @@ -import Foundation -import UIKit - -private let rotationAnimationKey = "rotation" - -@objcMembers class StoppableProgressIndicatorView: UIView { - - private let progressIndicator: CAShapeLayer - let stopButton: UIControl - - var hidesWhenStopped: Bool = true { - didSet { - if hidesWhenStopped, !isAnimating { - isHidden = true - } - } - } - - var mayStop: Bool { - get { !stopButton.isHidden } - set { stopButton.isHidden = !newValue } - } - - var isAnimating: Bool { - progressIndicator.animation(forKey: rotationAnimationKey) != nil - } - - private var resumeAnimation: Bool = true - - override init(frame: CGRect) { - stopButton = UIControl(frame: .zero) - progressIndicator = CAShapeLayer() - progressIndicator.isHidden = true - progressIndicator.lineWidth = 2 - super.init(frame: frame) - - layer.addSublayer(progressIndicator) - addSubview(stopButton) - stopButton.translatesAutoresizingMaskIntoConstraints = false - NSLayoutConstraint.activate([ - stopButton.centerXAnchor.constraint(equalTo: centerXAnchor), - stopButton.centerYAnchor.constraint(equalTo: centerYAnchor), - stopButton.widthAnchor.constraint(equalTo: stopButton.heightAnchor), - stopButton.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.3), - ]) - - updateAppearance() - NotificationCenter.default.addObserver(self, selector: #selector(enterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func tintColorDidChange() { - super.tintColorDidChange() - updateAppearance() - } - - override func layoutSubviews() { - super.layoutSubviews() - progressIndicator.frame = layer.bounds - resetIndicatorShape() - } - - func startAnimating() { - if isAnimating { - return - } - - isHidden = false - progressIndicator.isHidden = false - resumeAnimation = true - - let rotation = CABasicAnimation(keyPath: "transform.rotation") - rotation.toValue = CGFloat.pi * 2 - rotation.duration = 1 - rotation.repeatCount = Float.infinity - progressIndicator.add(rotation, forKey: rotationAnimationKey) - } - - func stopAnimating() { - resumeAnimation = false - progressIndicator.removeAnimation(forKey: rotationAnimationKey) - progressIndicator.isHidden = true - - if hidesWhenStopped { - isHidden = true - } - } - - func enterForeground() { - if resumeAnimation { - startAnimating() - } - } - - private func resetIndicatorShape() { - let bounds = progressIndicator.bounds - let path = CGMutablePath() - path.addArc( - center: CGPoint(x: bounds.midX, y: bounds.midY), - radius: (bounds.width - progressIndicator.lineWidth) / 2, - startAngle: -CGFloat.pi / 2, - endAngle: -CGFloat.pi / 2 + CGFloat.pi * 1.8, - clockwise: false - ) - progressIndicator.path = path - } - - private func updateAppearance() { - stopButton.backgroundColor = tintColor - progressIndicator.strokeColor = tintColor.cgColor - progressIndicator.fillColor = nil - } - -}