Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAYRTS-5566 SwiftFormat and trim trailing whitespaces #495

Merged
merged 13 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# format options
--swiftversion 5.10

# file options
--exclude Pods,Generated,build,archive,fastlane,vendor

# rules
--disable trailingCommas,wrapMultilineStatementBraces
2 changes: 1 addition & 1 deletion Application/Sources/Application/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ - (void)playbackDidContinueAutomatically:(NSNotification *)notification
SRGMedia *media = notification.userInfo[SRGLetterboxMediaKey];
if (media) {
[[AnalyticsEventObjC continuousPlaybackWithAction:AnalyticsContiniousPlaybackActionPlayAutomatic
mediaUrn:media.URN]
mediaUrn:media.URN]
send];
}
}
Expand Down
514 changes: 254 additions & 260 deletions Application/Sources/Application/Navigation.swift

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions Application/Sources/Bridges/SwiftMessagesBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,30 @@ final class SwiftMessagesBridge: NSObject {
*/
@objc static func show(_ message: String, accessibilityPrefix: String?, image: UIImage?, backgroundColor: UIColor?, foregroundColor: UIColor?, sticky: Bool) {
SwiftMessages.hideAll()

let messageView = MessageView.viewFromNib(layout: .cardView)
messageView.button?.isHidden = true
messageView.bodyLabel?.font = SRGFont.font(.body)
messageView.configureDropShadow()

messageView.configureContent(title: nil, body: message, iconImage: nil, iconText: nil, buttonImage: nil, buttonTitle: nil, buttonTapHandler: nil)
messageView.configureTheme(backgroundColor: backgroundColor ?? UIColor.white, foregroundColor: foregroundColor ?? UIColor.black)

messageView.accessibilityPrefix = accessibilityPrefix

messageView.iconImageView?.image = image
messageView.iconImageView?.isHidden = (image == nil)

messageView.tapHandler = { _ in SwiftMessages.hide() }

var config = SwiftMessages.defaultConfig
if sticky {
config.duration = .forever
}
else {
} else {
config.duration = .seconds(seconds: 4)
}
config.presentationStyle = .bottom

// Set a presentation context (with a preference for navigation controllers). A context is required so that
// the notification rotation behavior matches the one of the currently visible view controller.
var presentationController = UIApplication.shared.mainTopViewController
Expand All @@ -58,16 +57,16 @@ final class SwiftMessagesBridge: NSObject {
}
presentationController = presentationController?.parent
}

if let presentationController {
config.presentationContext = .viewController(presentationController)
}

// Remark: VoiceOver is supported natively, but with the system language (not the one we might set on the
// UIApplication instance)
SwiftMessages.show(config: config, view: messageView)
}

/**
* Hide all notification messages.
*/
Expand Down
36 changes: 18 additions & 18 deletions Application/Sources/Browser/WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds];
view.backgroundColor = UIColor.srg_gray16Color;

// WKWebView cannot be instantiated in storyboards, do it programmatically
WKWebView *webView = [[WKWebView alloc] init];
webView.opaque = NO;
Expand All @@ -77,7 +77,7 @@ - (void)loadView
webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
webView.scrollView.delegate = self;
[view insertSubview:webView atIndex:0];

webView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[webView.topAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.topAnchor],
Expand All @@ -86,56 +86,56 @@ - (void)loadView
[webView.trailingAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.trailingAnchor]
]];
self.webView = webView;

if (self.customizationBlock) {
self.customizationBlock(webView);
}

UIImageView *loadingImageView = [UIImageView play_largeLoadingImageViewWithTintColor:UIColor.srg_grayD2Color];
loadingImageView.hidden = YES;
[view insertSubview:loadingImageView atIndex:0];
self.loadingImageView = loadingImageView;

loadingImageView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[loadingImageView.centerXAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.centerXAnchor],
[loadingImageView.centerYAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.centerYAnchor]
]];

UILabel *errorLabel = [[UILabel alloc] init];
errorLabel.textColor = UIColor.whiteColor;
errorLabel.font = [SRGFont fontWithStyle:SRGFontStyleBody];
[view addSubview:errorLabel];
self.errorLabel = errorLabel;

errorLabel.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[errorLabel.leadingAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.leadingAnchor constant:40.f],
[errorLabel.trailingAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.trailingAnchor constant:-40.f],
[errorLabel.centerYAnchor constraintEqualToAnchor:view.centerYAnchor]
]];

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.progressTintColor = UIColor.srg_redColor;
[view addSubview:progressView];
self.progressView = progressView;

progressView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[progressView.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],
[progressView.trailingAnchor constraintEqualToAnchor:view.trailingAnchor],
self.progressTopConstraint = [progressView.topAnchor constraintEqualToAnchor:view.safeAreaLayoutGuide.topAnchor]
]];

self.view = view;
}

- (void)viewDidLoad
{
[super viewDidLoad];

[self.webView loadRequest:self.request];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(webViewController_reachabilityDidChange:)
name:FXReachabilityStatusDidChangeNotification
Expand Down Expand Up @@ -213,7 +213,7 @@ - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation
{
self.loadingImageView.hidden = NO;
self.errorLabel.text = nil;

[UIView animateWithDuration:0.3 animations:^{
self.progressView.alpha = 1.f;
}];
Expand All @@ -223,7 +223,7 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat
{
self.loadingImageView.hidden = YES;
self.errorLabel.text = nil;

[UIView animateWithDuration:0.3 animations:^{
self.webView.alpha = 1.f;
self.progressView.alpha = 0.f;
Expand All @@ -234,25 +234,25 @@ - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation
{
self.loadingImageView.hidden = YES;
NSError *updatedError = error;

NSURL *failingURL = ([error.domain isEqualToString:NSURLErrorDomain]) ? error.userInfo[NSURLErrorFailingURLErrorKey] : nil;
if (failingURL && ! [failingURL.scheme isEqualToString:@"http"] && ! [failingURL.scheme isEqualToString:@"https"] && ! [failingURL.scheme isEqualToString:@"file"]) {
updatedError = nil;
}

if ([updatedError.domain isEqualToString:NSURLErrorDomain]) {
self.errorLabel.text = [NSHTTPURLResponse srg_localizedStringForURLErrorCode:updatedError.code];

[UIView animateWithDuration:0.3 animations:^{
self.progressView.alpha = 0.f;
self.webView.alpha = 0.f;
}];
}
else {
self.errorLabel.text = nil;

[webView goBack];

[UIView animateWithDuration:0.3 animations:^{
self.progressView.alpha = 0.f;
}];
Expand Down
2 changes: 1 addition & 1 deletion Application/Sources/Calendar/CalendarViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
NS_ASSUME_NONNULL_BEGIN

@interface CalendarViewController : UIViewController <ContainerContentInsets, FSCalendarDataSource, FSCalendarDelegate, FSCalendarDelegateAppearance,
Oriented, ScrollableContentContainer, SRGAnalyticsViewTracking, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIGestureRecognizerDelegate>
Oriented, ScrollableContentContainer, SRGAnalyticsViewTracking, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIGestureRecognizerDelegate>

/**
* Instantiate for medias belonging to the specified radio channel. If no channel is provided, TV medias will be
Expand Down
2 changes: 1 addition & 1 deletion Application/Sources/Calendar/CalendarViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ - (void)calendarCurrentPageDidChange:(FSCalendar *)calendar

// Hidden if in the same page as today and current date is not today
BOOL hidden = [NSCalendar.srg_defaultCalendar compareDate:calendar.currentPage toDate:calendar.today toUnitGranularity:unitGranularity] == NSOrderedSame
&& [calendar.today isEqualToDate:dailyMediasViewController.date];
&& [calendar.today isEqualToDate:dailyMediasViewController.date];
[self setNavigationBarItemsHidden:hidden];
}

Expand Down
9 changes: 4 additions & 5 deletions Application/Sources/CarPlay/CarPlay+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension CPListTemplate {
template.controller = CarPlayTemplateListController(list: list, template: template, interfaceController: interfaceController)
return template
}

static var playbackRate: CPListTemplate {
let template = CPListTemplate(title: NSLocalizedString("Playback speed", comment: "Playback speed screen title"), sections: [])
template.controller = CarPlayPlaybackSpeedController(template: template)
Expand All @@ -26,19 +26,18 @@ extension CPInterfaceController {
if controller.play_mainMedia != media {
controller.playMedia(media, at: HistoryResumePlaybackPositionForMedia(media), withPreferredSettings: ApplicationSettingPlaybackSettings())
}
}
else {
} else {
let controller = SRGLetterboxController()
controller.playMedia(media, at: HistoryResumePlaybackPositionForMedia(media), withPreferredSettings: ApplicationSettingPlaybackSettings())
SRGLetterboxService.shared.enable(with: controller, pictureInPictureDelegate: nil)
}

if let controller = SRGLetterboxService.shared.controller {
let playlist = PlaylistForURN(media.urn)
controller.playlistDataSource = playlist
controller.playbackTransitionDelegate = playlist
}

let nowPlayingTemplate = CPNowPlayingTemplate.shared
pushTemplate(nowPlayingTemplate, animated: true) { _, _ in
completion()
Expand Down
Loading