From f7bee60c911a2f19edf9dbdbb2f43ed20cf94f18 Mon Sep 17 00:00:00 2001 From: noorhashem Date: Thu, 4 Jun 2020 13:28:59 +0200 Subject: [PATCH 1/9] cartfile resolved --- Cartfile.resolved | 7 +++--- .../xcshareddata/xcschemes/Today.xcscheme | 23 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 45d7fd7dd7b7..faceb269ba22 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,8 +1,7 @@ -github "mozilla-mobile/onepassword-app-extension" "68a9d932a6373ca045984fbf4fb9a25aee43284c" -github "DaveWoodCom/XCGLogger" "7.0.0" +github "DaveWoodCom/XCGLogger" "7.0.1" github "Dev1an/A-Star" "3.0.0-beta-1" -github "Leanplum/Leanplum-iOS-SDK" "2.7.2" -github "SDWebImage/SDWebImage" "5.4.0" +github "Leanplum/Leanplum-iOS-SDK" "2.8.0" +github "SDWebImage/SDWebImage" "5.8.0" github "SnapKit/SnapKit" "5.0.1" github "SwiftyJSON/SwiftyJSON" "5.0.0" github "adjust/ios_sdk" "v4.18.3" diff --git a/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme b/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme index 621c226765b4..29cc9c57a154 100644 --- a/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme +++ b/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme @@ -42,6 +42,15 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + @@ -54,23 +63,13 @@ - - - - - - - - Date: Thu, 4 Jun 2020 14:36:39 +0200 Subject: [PATCH 2/9] Revert "cartfile resolved" This reverts commit 092343a78296c91b31b1914c0a24a161ec64e408. --- Cartfile.resolved | 7 +++--- .../xcshareddata/xcschemes/Today.xcscheme | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index faceb269ba22..45d7fd7dd7b7 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,7 +1,8 @@ -github "DaveWoodCom/XCGLogger" "7.0.1" +github "mozilla-mobile/onepassword-app-extension" "68a9d932a6373ca045984fbf4fb9a25aee43284c" +github "DaveWoodCom/XCGLogger" "7.0.0" github "Dev1an/A-Star" "3.0.0-beta-1" -github "Leanplum/Leanplum-iOS-SDK" "2.8.0" -github "SDWebImage/SDWebImage" "5.8.0" +github "Leanplum/Leanplum-iOS-SDK" "2.7.2" +github "SDWebImage/SDWebImage" "5.4.0" github "SnapKit/SnapKit" "5.0.1" github "SwiftyJSON/SwiftyJSON" "5.0.0" github "adjust/ios_sdk" "v4.18.3" diff --git a/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme b/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme index 29cc9c57a154..621c226765b4 100644 --- a/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme +++ b/Client.xcodeproj/xcshareddata/xcschemes/Today.xcscheme @@ -42,15 +42,6 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - @@ -63,13 +54,23 @@ + + + + + + + + Date: Thu, 25 Jun 2020 22:28:43 +0200 Subject: [PATCH 3/9] refactored today widget to mvvm proposed architecture + added accessibility hints --- Client.xcodeproj/project.pbxproj | 36 ++++ Extensions/Today/ButtonWithSublabel.swift | 60 ++++++ Extensions/Today/ImageButtonWithLabel.swift | 48 +++++ Extensions/Today/TodayModel.swift | 17 ++ Extensions/Today/TodayUX.swift | 37 ++++ Extensions/Today/TodayViewController.swift | 197 +++----------------- Extensions/Today/TodayViewModel.swift | 32 ++++ Extensions/Today/UIButtonExtensions.swift | 35 ++++ 8 files changed, 290 insertions(+), 172 deletions(-) create mode 100644 Extensions/Today/ButtonWithSublabel.swift create mode 100644 Extensions/Today/ImageButtonWithLabel.swift create mode 100644 Extensions/Today/TodayModel.swift create mode 100644 Extensions/Today/TodayUX.swift create mode 100644 Extensions/Today/TodayViewModel.swift create mode 100644 Extensions/Today/UIButtonExtensions.swift diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index 2924066ae65f..c94fdbc4b5b0 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -9,6 +9,18 @@ /* Begin PBXBuildFile section */ 03CCC9181AF05E7300DBF30D /* RelativeDatesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CCC9171AF05E7300DBF30D /* RelativeDatesTests.swift */; }; 0430A545203B372D00FDF76D /* IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0430A544203B372D00FDF76D /* IntegrationTests.swift */; }; + 048B4C7924A53E7B001B56E8 /* TodayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7824A53E7B001B56E8 /* TodayModel.swift */; }; + 048B4C7A24A53E7B001B56E8 /* TodayModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7824A53E7B001B56E8 /* TodayModel.swift */; }; + 048B4C7D24A53EA8001B56E8 /* TodayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7C24A53EA8001B56E8 /* TodayViewModel.swift */; }; + 048B4C7E24A53EA8001B56E8 /* TodayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7C24A53EA8001B56E8 /* TodayViewModel.swift */; }; + 048B4C8024A53EEB001B56E8 /* ImageButtonWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7F24A53EEB001B56E8 /* ImageButtonWithLabel.swift */; }; + 048B4C8124A53EEB001B56E8 /* ImageButtonWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C7F24A53EEB001B56E8 /* ImageButtonWithLabel.swift */; }; + 048B4C8324A53F26001B56E8 /* ButtonWithSublabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8224A53F26001B56E8 /* ButtonWithSublabel.swift */; }; + 048B4C8424A53F26001B56E8 /* ButtonWithSublabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8224A53F26001B56E8 /* ButtonWithSublabel.swift */; }; + 048B4C8624A53F3E001B56E8 /* TodayUX.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8524A53F3E001B56E8 /* TodayUX.swift */; }; + 048B4C8724A53F3E001B56E8 /* TodayUX.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8524A53F3E001B56E8 /* TodayUX.swift */; }; + 048B4C8924A53F81001B56E8 /* UIButtonExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8824A53F81001B56E8 /* UIButtonExtensions.swift */; }; + 048B4C8A24A53F81001B56E8 /* UIButtonExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048B4C8824A53F81001B56E8 /* UIButtonExtensions.swift */; }; 0B21E8061E26CCB7000C8779 /* EarlGrey.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0B21E8051E26CCB7000C8779 /* EarlGrey.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 0B305E1B1E3A98A900BE0767 /* BookmarkingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B305E1A1E3A98A900BE0767 /* BookmarkingTests.swift */; }; 0B3D670E1E09B90B00C1EFC7 /* AuthenticationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3D670D1E09B90B00C1EFC7 /* AuthenticationTest.swift */; }; @@ -1165,6 +1177,12 @@ /* Begin PBXFileReference section */ 03CCC9171AF05E7300DBF30D /* RelativeDatesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RelativeDatesTests.swift; sourceTree = ""; }; 0430A544203B372D00FDF76D /* IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationTests.swift; sourceTree = ""; }; + 048B4C7824A53E7B001B56E8 /* TodayModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayModel.swift; sourceTree = ""; }; + 048B4C7C24A53EA8001B56E8 /* TodayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewModel.swift; sourceTree = ""; }; + 048B4C7F24A53EEB001B56E8 /* ImageButtonWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageButtonWithLabel.swift; sourceTree = ""; }; + 048B4C8224A53F26001B56E8 /* ButtonWithSublabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonWithSublabel.swift; sourceTree = ""; }; + 048B4C8524A53F3E001B56E8 /* TodayUX.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayUX.swift; sourceTree = ""; }; + 048B4C8824A53F81001B56E8 /* UIButtonExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIButtonExtensions.swift; sourceTree = ""; }; 0B21E8051E26CCB7000C8779 /* EarlGrey.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = EarlGrey.framework; path = Carthage/Build/iOS/EarlGrey.framework; sourceTree = ""; }; 0B305E1A1E3A98A900BE0767 /* BookmarkingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookmarkingTests.swift; sourceTree = ""; }; 0B3D670D1E09B90B00C1EFC7 /* AuthenticationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationTest.swift; sourceTree = ""; }; @@ -2458,6 +2476,12 @@ 391AEFD11C8F11ED00691F84 /* Images.xcassets */, 390527531C874D35007E0BB7 /* Info.plist */, 3905274E1C874D35007E0BB7 /* TodayViewController.swift */, + 048B4C7824A53E7B001B56E8 /* TodayModel.swift */, + 048B4C7C24A53EA8001B56E8 /* TodayViewModel.swift */, + 048B4C7F24A53EEB001B56E8 /* ImageButtonWithLabel.swift */, + 048B4C8224A53F26001B56E8 /* ButtonWithSublabel.swift */, + 048B4C8524A53F3E001B56E8 /* TodayUX.swift */, + 048B4C8824A53F81001B56E8 /* UIButtonExtensions.swift */, ); path = Today; sourceTree = ""; @@ -4897,8 +4921,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 048B4C7E24A53EA8001B56E8 /* TodayViewModel.swift in Sources */, + 048B4C8724A53F3E001B56E8 /* TodayUX.swift in Sources */, + 048B4C8124A53EEB001B56E8 /* ImageButtonWithLabel.swift in Sources */, 315D05561E58DD60001F349B /* UIPasteboardExtensions.swift in Sources */, 3905274F1C874D35007E0BB7 /* TodayViewController.swift in Sources */, + 048B4C8A24A53F81001B56E8 /* UIButtonExtensions.swift in Sources */, + 048B4C7A24A53E7B001B56E8 /* TodayModel.swift in Sources */, + 048B4C8424A53F26001B56E8 /* ButtonWithSublabel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5081,6 +5111,7 @@ 5F130D2E2483508E00B0F7D0 /* FxAWebViewModel.swift in Sources */, D0FCF7F51FE45842004A7995 /* UserScriptManager.swift in Sources */, E4A960061ABB9C450069AD6F /* ReaderModeUtils.swift in Sources */, + 048B4C8324A53F26001B56E8 /* ButtonWithSublabel.swift in Sources */, 435D660323D793DF0046EFA2 /* UpdateModel.swift in Sources */, EBF47E701F7979DF00899189 /* UnifiedTelemetry.swift in Sources */, E68F36981EA694000048CF44 /* PanelDataObservers.swift in Sources */, @@ -5099,6 +5130,7 @@ D3C3696E1CC6B78800348A61 /* LocalRequestHelper.swift in Sources */, E4B423DD1ABA0318007E66C8 /* ReaderModeHandlers.swift in Sources */, D308E4E41A5306F500842685 /* SearchEngines.swift in Sources */, + 048B4C8924A53F81001B56E8 /* UIButtonExtensions.swift in Sources */, 3BCE6D3C1CEB9E4D0080928C /* ThirdPartySearchAlerts.swift in Sources */, 745DAB301CDAAFAA00D44181 /* RecentlyClosedTabsPanel.swift in Sources */, D0B9483D22A18B78002F4AA1 /* TextFieldTableViewCell.swift in Sources */, @@ -5111,6 +5143,7 @@ 39F819C61FD70F5D009E31E4 /* TabEventHandlers.swift in Sources */, E65607611C08B4E200534B02 /* SearchInputView.swift in Sources */, FA6B2AC21D41F02D00429414 /* Punycode.swift in Sources */, + 048B4C7D24A53EA8001B56E8 /* TodayViewModel.swift in Sources */, 43446CEA2412066500F5C643 /* UIViewControllerExtension.swift in Sources */, D301AAEE1A3A55B70078DD1D /* TabTrayControllerV1.swift in Sources */, EB9A179B20E69A7F00B12184 /* ThemeManager.swift in Sources */, @@ -5119,6 +5152,7 @@ EBB89509219398E500EB91A0 /* TabContentBlocker+ContentScript.swift in Sources */, D3BE7B461B054F8600641031 /* TestAppDelegate.swift in Sources */, 3BB50E111D6274CD004B33DF /* FirefoxHomeTopSitesCell.swift in Sources */, + 048B4C8624A53F3E001B56E8 /* TodayUX.swift in Sources */, 0B62EFD21AD63CD100ACB9CD /* Clearables.swift in Sources */, 7482205C1DBAB56300EEEA72 /* MailProviders.swift in Sources */, C40046FA1CF8E0B200B08303 /* BackForwardListAnimator.swift in Sources */, @@ -5130,6 +5164,7 @@ 274A36CC239EB99400A21587 /* LibraryPanelContextMenu.swift in Sources */, D314E7F71A37B98700426A76 /* TabToolbar.swift in Sources */, CEFA977E1FAA6B490016F365 /* SyncContentSettingsViewController.swift in Sources */, + 048B4C7924A53E7B001B56E8 /* TodayModel.swift in Sources */, E60D03181D511398002FE3F6 /* SyncStatusResolver.swift in Sources */, 435D660723D7962C0046EFA2 /* UpdateCoverSheetTableViewCell.swift in Sources */, C4E3983D1D21F1E7004E89BA /* TopTabsViews.swift in Sources */, @@ -5265,6 +5300,7 @@ A93067E81D0FE18E00C49C6E /* NightModeHelper.swift in Sources */, 3B39EDCB1E16E1AA00EF029F /* CustomSearchViewController.swift in Sources */, E65075571E37F714006961AC /* FaviconFetcher.swift in Sources */, + 048B4C8024A53EEB001B56E8 /* ImageButtonWithLabel.swift in Sources */, D863C8F21F68BFC20058D95F /* GradientProgressBar.swift in Sources */, EB9A178E20E525DF00B12184 /* ThemeSettingsController.swift in Sources */, D3C744CD1A687D6C004CE85D /* URIFixup.swift in Sources */, diff --git a/Extensions/Today/ButtonWithSublabel.swift b/Extensions/Today/ButtonWithSublabel.swift new file mode 100644 index 000000000000..645746114cec --- /dev/null +++ b/Extensions/Today/ButtonWithSublabel.swift @@ -0,0 +1,60 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import UIKit + +class ButtonWithSublabel: UIButton { + lazy var subtitleLabel = UILabel() + + lazy var label = UILabel() + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + convenience init() { + self.init(frame: .zero) + } + + override init(frame: CGRect) { + super.init(frame: frame) + performLayout() + } + + fileprivate func performLayout() { + let titleLabel = self.label + self.titleLabel?.removeFromSuperview() + addSubview(titleLabel) + + let imageView = self.imageView! + let subtitleLabel = self.subtitleLabel + self.addSubview(subtitleLabel) + + imageView.snp.makeConstraints { make in + make.centerY.left.equalTo(10) + make.width.equalTo(TodayUX.copyLinkImageWidth) + } + + titleLabel.snp.makeConstraints { make in + make.left.equalTo(imageView.snp.right).offset(10) + make.trailing.top.equalTo(self) + make.height.equalTo(15) + } + titleLabel.numberOfLines = 1 + titleLabel.lineBreakMode = .byWordWrapping + + subtitleLabel.lineBreakMode = .byTruncatingTail + subtitleLabel.snp.makeConstraints { make in + make.bottom.equalTo(self).inset(10) + make.top.equalTo(titleLabel.snp.bottom).offset(3) + make.leading.trailing.equalTo(titleLabel) + make.height.equalTo(10) + } + } + + override func setTitle(_ text: String?, for state: UIControl.State) { + self.label.text = text + super.setTitle(text, for: state) + } +} diff --git a/Extensions/Today/ImageButtonWithLabel.swift b/Extensions/Today/ImageButtonWithLabel.swift new file mode 100644 index 000000000000..e53131efb323 --- /dev/null +++ b/Extensions/Today/ImageButtonWithLabel.swift @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import UIKit + +class ImageButtonWithLabel: UIView { + + lazy var button = UIButton() + lazy var label = UILabel() + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override init(frame: CGRect) { + super.init(frame: frame) + performLayout() + } + + func performLayout() { + addSubview(button) + addSubview(label) + button.imageView?.contentMode = .scaleAspectFit + + button.snp.makeConstraints { make in + make.centerX.equalTo(self) + make.top.equalTo(self.safeAreaLayoutGuide).offset(5) + make.right.greaterThanOrEqualTo(self.safeAreaLayoutGuide).offset(40) + make.left.greaterThanOrEqualTo(self.safeAreaLayoutGuide).inset(40) + make.height.greaterThanOrEqualTo(60) + } + + label.snp.makeConstraints { make in + make.top.equalTo(button.snp.bottom).offset(10) + make.leading.trailing.bottom.equalTo(self) + make.height.greaterThanOrEqualTo(10) + } + + label.numberOfLines = 1 + label.lineBreakMode = .byWordWrapping + label.textAlignment = .center + } + + func addTarget(_ target: AnyObject?, action: Selector, forControlEvents events: UIControl.Event) { + button.addTarget(target, action: action, for: events) + } +} diff --git a/Extensions/Today/TodayModel.swift b/Extensions/Today/TodayModel.swift new file mode 100644 index 000000000000..090144b02749 --- /dev/null +++ b/Extensions/Today/TodayModel.swift @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import Foundation + +struct TodayModel { + static var copiedURL: URL? + + var scheme: String { + guard let string = Bundle.main.object(forInfoDictionaryKey: "MozInternalURLScheme") as? String else { + // Something went wrong/weird, but we should fallback to the public one. + return "firefox" + } + return string + } +} diff --git a/Extensions/Today/TodayUX.swift b/Extensions/Today/TodayUX.swift new file mode 100644 index 000000000000..e64928dc9775 --- /dev/null +++ b/Extensions/Today/TodayUX.swift @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import UIKit + +struct TodayUX { + + static let backgroundHightlightColor = UIColor(white: 216.0/255.0, alpha: 44.0/255.0) + static let linkTextSize: CGFloat = 9.0 + static let labelTextSize: CGFloat = 12.0 + static let imageButtonTextSize: CGFloat = 13.0 + static let copyLinkImageWidth: CGFloat = 20 + static let margin: CGFloat = 8 + static let buttonsHorizontalMarginPercentage: CGFloat = 0.1 + static let buttonStackViewSpacing: CGFloat = 20.0 + static var labelColor: UIColor { + if #available(iOS 13, *) { + return UIColor(named: "widgetLabelColors") ?? UIColor(rgb: 0x242327) + } else { + return UIColor(rgb: 0x242327) + } + } + static var subtitleLabelColor: UIColor { + if #available(iOS 13, *) { + return UIColor(named: "subtitleLableColor") ?? UIColor(rgb: 0x38383C) + } else { + return UIColor(rgb: 0x38383C) + } + } +} + +struct TodayStrings { + static let NewPrivateTabButtonLabel = NSLocalizedString("TodayWidget.NewPrivateTabButtonLabel", tableName: "Today", value: "Private Search", comment: "New Private Tab button label") + static let NewTabButtonLabel = NSLocalizedString("TodayWidget.NewTabButtonLabel", tableName: "Today", value: "New Search", comment: "New Tab button label") + static let GoToCopiedLinkLabel = NSLocalizedString("TodayWidget.GoToCopiedLinkLabel", tableName: "Today", value: "Go to copied link", comment: "Go to link on clipboard") +} diff --git a/Extensions/Today/TodayViewController.swift b/Extensions/Today/TodayViewController.swift index 02d4d3ce5809..9e8eace9730b 100644 --- a/Extensions/Today/TodayViewController.swift +++ b/Extensions/Today/TodayViewController.swift @@ -10,40 +10,11 @@ import XCGLogger private let log = Logger.browserLogger -struct TodayStrings { - static let NewPrivateTabButtonLabel = NSLocalizedString("TodayWidget.NewPrivateTabButtonLabel", tableName: "Today", value: "Private Search", comment: "New Private Tab button label") - static let NewTabButtonLabel = NSLocalizedString("TodayWidget.NewTabButtonLabel", tableName: "Today", value: "New Search", comment: "New Tab button label") - static let GoToCopiedLinkLabel = NSLocalizedString("TodayWidget.GoToCopiedLinkLabel", tableName: "Today", value: "Go to copied link", comment: "Go to link on clipboard") -} - -private struct TodayUX { - static let backgroundHightlightColor = UIColor(white: 216.0/255.0, alpha: 44.0/255.0) - static let linkTextSize: CGFloat = 9.0 - static let labelTextSize: CGFloat = 12.0 - static let imageButtonTextSize: CGFloat = 13.0 - static let copyLinkImageWidth: CGFloat = 20 - static let margin: CGFloat = 8 - static let buttonsHorizontalMarginPercentage: CGFloat = 0.1 - static let buttonStackViewSpacing: CGFloat = 30.0 - static var labelColor: UIColor { - if #available(iOS 13, *) { - return UIColor(named: "widgetLabelColors") ?? UIColor(rgb: 0x242327) - } else { - return UIColor(rgb: 0x242327) - } - } - static var subtitleLabelColor: UIColor { - if #available(iOS 13, *) { - return UIColor(named: "subtitleLableColor") ?? UIColor(rgb: 0x38383C) - } else { - return UIColor(rgb: 0x38383C) - } - } -} - @objc (TodayViewController) -class TodayViewController: UIViewController, NCWidgetProviding { - var copiedURL: URL? +class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppearanceDelegate { + + let viewModel = TodayWidgetViewModel() + let model = TodayModel() fileprivate lazy var newTabButton: ImageButtonWithLabel = { let imageButton = ImageButtonWithLabel() @@ -51,10 +22,11 @@ class TodayViewController: UIViewController, NCWidgetProviding { imageButton.label.text = TodayStrings.NewTabButtonLabel let button = imageButton.button button.setImage(UIImage(named: "search-button")?.withRenderingMode(.alwaysOriginal), for: .normal) + button.accessibilityLabel = TodayStrings.NewTabButtonLabel let label = imageButton.label label.textColor = TodayUX.labelColor label.tintColor = TodayUX.labelColor - label.font = UIFont.systemFont(ofSize: TodayUX.imageButtonTextSize) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.imageButtonTextSize)) imageButton.sizeToFit() return imageButton }() @@ -65,10 +37,11 @@ class TodayViewController: UIViewController, NCWidgetProviding { imageButton.label.text = TodayStrings.NewPrivateTabButtonLabel let button = imageButton.button button.setImage(UIImage(named: "private-search")?.withRenderingMode(.alwaysOriginal), for: .normal) + button.accessibilityLabel = TodayStrings.NewPrivateTabButtonLabel let label = imageButton.label label.textColor = TodayUX.labelColor label.tintColor = TodayUX.labelColor - label.font = UIFont.systemFont(ofSize: TodayUX.imageButtonTextSize) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.imageButtonTextSize)) imageButton.sizeToFit() return imageButton }() @@ -81,12 +54,14 @@ class TodayViewController: UIViewController, NCWidgetProviding { button.setBackgroundColor(UIColor.clear, forState: .normal) button.setBackgroundColor(TodayUX.backgroundHightlightColor, forState: .highlighted) button.setImage(UIImage(named: "copy_link_icon")?.withRenderingMode(.alwaysOriginal), for: .normal) - button.label.font = UIFont.systemFont(ofSize: TodayUX.labelTextSize) - button.subtitleLabel.font = UIFont.systemFont(ofSize: TodayUX.linkTextSize) + button.label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.labelTextSize)) + button.accessibilityLabel = TodayStrings.GoToCopiedLinkLabel button.label.textColor = TodayUX.labelColor button.label.tintColor = TodayUX.labelColor + button.label.sizeToFit() button.subtitleLabel.textColor = TodayUX.subtitleLabelColor button.subtitleLabel.tintColor = TodayUX.subtitleLabelColor + button.subtitleLabel.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.linkTextSize)) return button }() @@ -108,16 +83,9 @@ class TodayViewController: UIViewController, NCWidgetProviding { return stackView }() - fileprivate var scheme: String { - guard let string = Bundle.main.object(forInfoDictionaryKey: "MozInternalURLScheme") as? String else { - // Something went wrong/weird, but we should fallback to the public one. - return "firefox" - } - return string - } - override func viewDidLoad() { super.viewDidLoad() + viewModel.setViewDelegate(todayViewDelegate: self) let widgetView: UIView! self.extensionContext?.widgetLargestAvailableDisplayMode = .compact @@ -148,7 +116,7 @@ class TodayViewController: UIViewController, NCWidgetProviding { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - updateCopiedLink() + viewModel.updateCopiedLink() } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { @@ -160,18 +128,14 @@ class TodayViewController: UIViewController, NCWidgetProviding { return .zero } - func updateCopiedLink() { - UIPasteboard.general.asyncURL().uponQueue(.main) { res in - if let copiedURL: URL? = res.successValue, - let url = copiedURL { - self.openCopiedLinkButton.isHidden = false - self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() - self.openCopiedLinkButton.subtitleLabel.text = url.absoluteDisplayString - self.copiedURL = url - } else { - self.openCopiedLinkButton.isHidden = true - self.copiedURL = nil - } + func updateCopiedLinkInView(clipboardURL: URL?) { + if let url = clipboardURL { + self.openCopiedLinkButton.isHidden = false + self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() + self.openCopiedLinkButton.subtitleLabel.text = url.absoluteDisplayString + } else { + self.openCopiedLinkButton.isHidden = true + self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() } } @@ -183,129 +147,18 @@ class TodayViewController: UIViewController, NCWidgetProviding { @objc func onPressNewPrivateTab(_ view: UIView) { openContainingApp("?private=true") } - + //TODO: Move it to model?? fileprivate func openContainingApp(_ urlSuffix: String = "") { - let urlString = "\(scheme)://open-url\(urlSuffix)" + let urlString = "\(model.scheme)://open-url\(urlSuffix)" self.extensionContext?.open(URL(string: urlString)!) { success in log.info("Extension opened containing app: \(success)") } } @objc func onPressOpenClibpoard(_ view: UIView) { - if let url = copiedURL, + if let url = TodayModel.copiedURL, let encodedString = url.absoluteString.escape() { openContainingApp("?url=\(encodedString)") } } } - -extension UIButton { - func setBackgroundColor(_ color: UIColor, forState state: UIControl.State) { - let colorView = UIView(frame: CGRect(width: 1, height: 1)) - colorView.backgroundColor = color - - UIGraphicsBeginImageContext(colorView.bounds.size) - if let context = UIGraphicsGetCurrentContext() { - colorView.layer.render(in: context) - } - let colorImage = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - - self.setBackgroundImage(colorImage, for: state) - } -} - -class ImageButtonWithLabel: UIView { - - lazy var button = UIButton() - lazy var label = UILabel() - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override init(frame: CGRect) { - super.init(frame: frame) - performLayout() - } - - func performLayout() { - addSubview(button) - addSubview(label) - button.imageView?.contentMode = .scaleAspectFit - - button.snp.makeConstraints { make in - make.centerX.equalTo(self) - make.top.equalTo(self.safeAreaLayoutGuide).offset(5) - make.right.greaterThanOrEqualTo(self.safeAreaLayoutGuide).offset(40) - make.left.greaterThanOrEqualTo(self.safeAreaLayoutGuide).inset(40) - make.height.greaterThanOrEqualTo(60) - } - - label.snp.makeConstraints { make in - make.top.equalTo(button.snp.bottom).offset(10) - make.leading.trailing.bottom.equalTo(self) - make.height.equalTo(10) - } - - label.numberOfLines = 1 - label.lineBreakMode = .byWordWrapping - label.textAlignment = .center - } - - func addTarget(_ target: AnyObject?, action: Selector, forControlEvents events: UIControl.Event) { - button.addTarget(target, action: action, for: events) - } -} - -class ButtonWithSublabel: UIButton { - lazy var subtitleLabel = UILabel() - lazy var label = UILabel() - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - convenience init() { - self.init(frame: .zero) - } - - override init(frame: CGRect) { - super.init(frame: frame) - performLayout() - } - - fileprivate func performLayout() { - let titleLabel = self.label - self.titleLabel?.removeFromSuperview() - addSubview(titleLabel) - - let imageView = self.imageView! - let subtitleLabel = self.subtitleLabel - self.addSubview(subtitleLabel) - - imageView.snp.makeConstraints { make in - make.centerY.left.equalTo(10) - make.width.equalTo(TodayUX.copyLinkImageWidth) - } - - titleLabel.snp.makeConstraints { make in - make.left.equalTo(imageView.snp.right).offset(10) - make.trailing.top.equalTo(self) - make.height.greaterThanOrEqualTo(12) - } - - subtitleLabel.lineBreakMode = .byTruncatingTail - subtitleLabel.snp.makeConstraints { make in - make.bottom.equalTo(self).inset(10) - make.top.equalTo(titleLabel.snp.bottom) - make.leading.trailing.equalTo(titleLabel) - make.height.greaterThanOrEqualTo(10) - } - } - - override func setTitle(_ text: String?, for state: UIControl.State) { - self.label.text = text - super.setTitle(text, for: state) - } -} diff --git a/Extensions/Today/TodayViewModel.swift b/Extensions/Today/TodayViewModel.swift new file mode 100644 index 000000000000..4ba7060045e2 --- /dev/null +++ b/Extensions/Today/TodayViewModel.swift @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import Foundation +import NotificationCenter + +protocol TodayWidgetAppearanceDelegate { + func updateCopiedLinkInView(clipboardURL: URL?) +} + +class TodayWidgetViewModel { + + var AppearanceDelegate: TodayWidgetAppearanceDelegate? + + func setViewDelegate(todayViewDelegate: TodayWidgetAppearanceDelegate?) { + self.AppearanceDelegate = todayViewDelegate + } + + func updateCopiedLink() { + UIPasteboard.general.asyncURL().uponQueue(.main) { res in + if let URL: URL? = res.successValue, + let url = URL { + TodayModel.copiedURL = url + self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: url) + } else { + TodayModel.copiedURL = nil + self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: nil) + } + } + } +} diff --git a/Extensions/Today/UIButtonExtensions.swift b/Extensions/Today/UIButtonExtensions.swift new file mode 100644 index 000000000000..63b548dbc40e --- /dev/null +++ b/Extensions/Today/UIButtonExtensions.swift @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import UIKit + +extension UIButton { +func performGradient(colorOne: UIColor, colorTwo: UIColor, colorThree: UIColor) { + let gradientLayer = CAGradientLayer() + gradientLayer.frame = self.frame + gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor, colorThree.cgColor] + gradientLayer.startPoint = CGPoint(x: 1.0, y: 0.0) + gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0) + gradientLayer.locations = [0.0, 0.5, 1.0] + gradientLayer.cornerRadius = self.frame.size.width/2 + layer.masksToBounds = true + layer.insertSublayer(gradientLayer, below: self.imageView?.layer) + } +} + +extension UIButton { + func setBackgroundColor(_ color: UIColor, forState state: UIControl.State) { + let colorView = UIView(frame: CGRect(width: 1, height: 1)) + colorView.backgroundColor = color + + UIGraphicsBeginImageContext(colorView.bounds.size) + if let context = UIGraphicsGetCurrentContext() { + colorView.layer.render(in: context) + } + let colorImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + self.setBackgroundImage(colorImage, for: state) + } +} From 3dd808c98edbd0ecf97ddc293d4e2abf8eca9e08 Mon Sep 17 00:00:00 2001 From: noorhashem Date: Thu, 25 Jun 2020 22:36:03 +0200 Subject: [PATCH 4/9] removed gradient function for buttons (unneeded) --- Extensions/Today/UIButtonExtensions.swift | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Extensions/Today/UIButtonExtensions.swift b/Extensions/Today/UIButtonExtensions.swift index 63b548dbc40e..eb7e6d3c1fb8 100644 --- a/Extensions/Today/UIButtonExtensions.swift +++ b/Extensions/Today/UIButtonExtensions.swift @@ -4,20 +4,6 @@ import UIKit -extension UIButton { -func performGradient(colorOne: UIColor, colorTwo: UIColor, colorThree: UIColor) { - let gradientLayer = CAGradientLayer() - gradientLayer.frame = self.frame - gradientLayer.colors = [colorOne.cgColor, colorTwo.cgColor, colorThree.cgColor] - gradientLayer.startPoint = CGPoint(x: 1.0, y: 0.0) - gradientLayer.endPoint = CGPoint(x: 0.0, y: 1.0) - gradientLayer.locations = [0.0, 0.5, 1.0] - gradientLayer.cornerRadius = self.frame.size.width/2 - layer.masksToBounds = true - layer.insertSublayer(gradientLayer, below: self.imageView?.layer) - } -} - extension UIButton { func setBackgroundColor(_ color: UIColor, forState state: UIControl.State) { let colorView = UIView(frame: CGRect(width: 1, height: 1)) From 0f4eb544f7c11d88e2c156857124ca87f73462d7 Mon Sep 17 00:00:00 2001 From: noorhashem Date: Fri, 3 Jul 2020 02:52:17 +0200 Subject: [PATCH 5/9] code styling edits + guard statements instead of optional binding --- Extensions/Today/ButtonWithSublabel.swift | 98 ++++++++++----------- Extensions/Today/ImageButtonWithLabel.swift | 3 +- Extensions/Today/TodayUX.swift | 1 - Extensions/Today/TodayViewController.swift | 12 +-- Extensions/Today/TodayViewModel.swift | 23 +++-- 5 files changed, 64 insertions(+), 73 deletions(-) diff --git a/Extensions/Today/ButtonWithSublabel.swift b/Extensions/Today/ButtonWithSublabel.swift index 645746114cec..c2d7cf29dac1 100644 --- a/Extensions/Today/ButtonWithSublabel.swift +++ b/Extensions/Today/ButtonWithSublabel.swift @@ -6,55 +6,51 @@ import UIKit class ButtonWithSublabel: UIButton { lazy var subtitleLabel = UILabel() - - lazy var label = UILabel() - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - convenience init() { - self.init(frame: .zero) - } - - override init(frame: CGRect) { - super.init(frame: frame) - performLayout() - } - - fileprivate func performLayout() { - let titleLabel = self.label - self.titleLabel?.removeFromSuperview() - addSubview(titleLabel) - - let imageView = self.imageView! - let subtitleLabel = self.subtitleLabel - self.addSubview(subtitleLabel) - - imageView.snp.makeConstraints { make in - make.centerY.left.equalTo(10) - make.width.equalTo(TodayUX.copyLinkImageWidth) - } - - titleLabel.snp.makeConstraints { make in - make.left.equalTo(imageView.snp.right).offset(10) - make.trailing.top.equalTo(self) - make.height.equalTo(15) - } - titleLabel.numberOfLines = 1 - titleLabel.lineBreakMode = .byWordWrapping - - subtitleLabel.lineBreakMode = .byTruncatingTail - subtitleLabel.snp.makeConstraints { make in - make.bottom.equalTo(self).inset(10) - make.top.equalTo(titleLabel.snp.bottom).offset(3) - make.leading.trailing.equalTo(titleLabel) - make.height.equalTo(10) - } - } - - override func setTitle(_ text: String?, for state: UIControl.State) { - self.label.text = text - super.setTitle(text, for: state) - } + lazy var label = UILabel() + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + convenience init() { + self.init(frame: .zero) + } + + override init(frame: CGRect) { + super.init(frame: frame) + performLayout() + } + + fileprivate func performLayout() { + let buttonImage = self.imageView! + self.titleLabel?.removeFromSuperview() + addSubview(self.label) + addSubview(self.subtitleLabel) + + buttonImage.snp.makeConstraints { make in + make.centerY.left.equalTo(10) + make.width.equalTo(TodayUX.copyLinkImageWidth) + } + + self.label.snp.makeConstraints { make in + make.left.equalTo(buttonImage.snp.right).offset(10) + make.trailing.top.equalTo(self) + make.height.equalTo(15) + } + self.label.numberOfLines = 1 + self.label.lineBreakMode = .byWordWrapping + + self.subtitleLabel.lineBreakMode = .byTruncatingTail + self.subtitleLabel.snp.makeConstraints { make in + make.bottom.equalTo(self).inset(10) + make.top.equalTo(self.label.snp.bottom).offset(3) + make.leading.trailing.equalTo(self.label) + make.height.equalTo(10) + } + } + + override func setTitle(_ text: String?, for state: UIControl.State) { + self.label.text = text + super.setTitle(text, for: state) + } } diff --git a/Extensions/Today/ImageButtonWithLabel.swift b/Extensions/Today/ImageButtonWithLabel.swift index e53131efb323..e511b3e0a72e 100644 --- a/Extensions/Today/ImageButtonWithLabel.swift +++ b/Extensions/Today/ImageButtonWithLabel.swift @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import UIKit - class ImageButtonWithLabel: UIView { lazy var button = UIButton() @@ -18,7 +17,7 @@ class ImageButtonWithLabel: UIView { performLayout() } - func performLayout() { + fileprivate func performLayout() { addSubview(button) addSubview(label) button.imageView?.contentMode = .scaleAspectFit diff --git a/Extensions/Today/TodayUX.swift b/Extensions/Today/TodayUX.swift index e64928dc9775..30261b1f6303 100644 --- a/Extensions/Today/TodayUX.swift +++ b/Extensions/Today/TodayUX.swift @@ -5,7 +5,6 @@ import UIKit struct TodayUX { - static let backgroundHightlightColor = UIColor(white: 216.0/255.0, alpha: 44.0/255.0) static let linkTextSize: CGFloat = 9.0 static let labelTextSize: CGFloat = 12.0 diff --git a/Extensions/Today/TodayViewController.swift b/Extensions/Today/TodayViewController.swift index 9e8eace9730b..7eb6726bbf1e 100644 --- a/Extensions/Today/TodayViewController.swift +++ b/Extensions/Today/TodayViewController.swift @@ -129,14 +129,14 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea } func updateCopiedLinkInView(clipboardURL: URL?) { - if let url = clipboardURL { - self.openCopiedLinkButton.isHidden = false - self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() - self.openCopiedLinkButton.subtitleLabel.text = url.absoluteDisplayString - } else { + guard let url = clipboardURL else { self.openCopiedLinkButton.isHidden = true self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() + return } + self.openCopiedLinkButton.isHidden = false + self.openCopiedLinkButton.subtitleLabel.isHidden = SystemUtils.isDeviceLocked() + self.openCopiedLinkButton.subtitleLabel.text = url.absoluteDisplayString } // MARK: Button behaviour @@ -147,7 +147,7 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea @objc func onPressNewPrivateTab(_ view: UIView) { openContainingApp("?private=true") } - //TODO: Move it to model?? + //TODO: Move it to Viewmodel fileprivate func openContainingApp(_ urlSuffix: String = "") { let urlString = "\(model.scheme)://open-url\(urlSuffix)" self.extensionContext?.open(URL(string: urlString)!) { success in diff --git a/Extensions/Today/TodayViewModel.swift b/Extensions/Today/TodayViewModel.swift index 4ba7060045e2..02a121548c82 100644 --- a/Extensions/Today/TodayViewModel.swift +++ b/Extensions/Today/TodayViewModel.swift @@ -1,16 +1,14 @@ /* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import Foundation import NotificationCenter - protocol TodayWidgetAppearanceDelegate { func updateCopiedLinkInView(clipboardURL: URL?) } class TodayWidgetViewModel { - var AppearanceDelegate: TodayWidgetAppearanceDelegate? func setViewDelegate(todayViewDelegate: TodayWidgetAppearanceDelegate?) { @@ -18,15 +16,14 @@ class TodayWidgetViewModel { } func updateCopiedLink() { - UIPasteboard.general.asyncURL().uponQueue(.main) { res in - if let URL: URL? = res.successValue, - let url = URL { - TodayModel.copiedURL = url - self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: url) - } else { - TodayModel.copiedURL = nil - self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: nil) - } + UIPasteboard.general.asyncURL().uponQueue(.main) { res in + guard let url: URL? = res.successValue else { + TodayModel.copiedURL = nil + self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: nil) + return } + TodayModel.copiedURL = url + self.AppearanceDelegate?.updateCopiedLinkInView(clipboardURL: url) } + } } From 8b767e01f2df43c35b4dce0819e9edcb6ced091c Mon Sep 17 00:00:00 2001 From: noorhashem Date: Fri, 3 Jul 2020 06:06:24 +0200 Subject: [PATCH 6/9] added accessibility traits --- Extensions/Today/TodayUX.swift | 1 + Extensions/Today/TodayViewController.swift | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Extensions/Today/TodayUX.swift b/Extensions/Today/TodayUX.swift index 30261b1f6303..d87633e39336 100644 --- a/Extensions/Today/TodayUX.swift +++ b/Extensions/Today/TodayUX.swift @@ -33,4 +33,5 @@ struct TodayStrings { static let NewPrivateTabButtonLabel = NSLocalizedString("TodayWidget.NewPrivateTabButtonLabel", tableName: "Today", value: "Private Search", comment: "New Private Tab button label") static let NewTabButtonLabel = NSLocalizedString("TodayWidget.NewTabButtonLabel", tableName: "Today", value: "New Search", comment: "New Tab button label") static let GoToCopiedLinkLabel = NSLocalizedString("TodayWidget.GoToCopiedLinkLabel", tableName: "Today", value: "Go to copied link", comment: "Go to link on clipboard") + static let CopiedLinkLabelFromPasteBoard = NSLocalizedString("TodayWidget.CopiedLinkLabelFromPasteBoard", tableName: "Today", value: "Copied Link from clipboard", comment: "Copied Link from clipboard displayed") } diff --git a/Extensions/Today/TodayViewController.swift b/Extensions/Today/TodayViewController.swift index 7eb6726bbf1e..05b28b1db08f 100644 --- a/Extensions/Today/TodayViewController.swift +++ b/Extensions/Today/TodayViewController.swift @@ -23,6 +23,7 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea let button = imageButton.button button.setImage(UIImage(named: "search-button")?.withRenderingMode(.alwaysOriginal), for: .normal) button.accessibilityLabel = TodayStrings.NewTabButtonLabel + button.accessibilityTraits = .button let label = imageButton.label label.textColor = TodayUX.labelColor label.tintColor = TodayUX.labelColor @@ -38,6 +39,7 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea let button = imageButton.button button.setImage(UIImage(named: "private-search")?.withRenderingMode(.alwaysOriginal), for: .normal) button.accessibilityLabel = TodayStrings.NewPrivateTabButtonLabel + button.accessibilityTraits = .button let label = imageButton.label label.textColor = TodayUX.labelColor label.tintColor = TodayUX.labelColor @@ -56,12 +58,15 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea button.setImage(UIImage(named: "copy_link_icon")?.withRenderingMode(.alwaysOriginal), for: .normal) button.label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.labelTextSize)) button.accessibilityLabel = TodayStrings.GoToCopiedLinkLabel + button.accessibilityTraits = .button button.label.textColor = TodayUX.labelColor button.label.tintColor = TodayUX.labelColor button.label.sizeToFit() button.subtitleLabel.textColor = TodayUX.subtitleLabelColor button.subtitleLabel.tintColor = TodayUX.subtitleLabelColor button.subtitleLabel.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.linkTextSize)) + button.label.accessibilityLabel = TodayStrings.CopiedLinkLabelFromPasteBoard + button.accessibilityTraits = .none return button }() From 30001b43fa23916fe852ab61787ca31181ae73b4 Mon Sep 17 00:00:00 2001 From: noorhashem Date: Tue, 7 Jul 2020 18:12:22 +0200 Subject: [PATCH 7/9] fixed nits --- Extensions/Today/ButtonWithSublabel.swift | 4 ++-- Extensions/Today/ImageButtonWithLabel.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Extensions/Today/ButtonWithSublabel.swift b/Extensions/Today/ButtonWithSublabel.swift index c2d7cf29dac1..a3d559d46873 100644 --- a/Extensions/Today/ButtonWithSublabel.swift +++ b/Extensions/Today/ButtonWithSublabel.swift @@ -35,7 +35,7 @@ class ButtonWithSublabel: UIButton { self.label.snp.makeConstraints { make in make.left.equalTo(buttonImage.snp.right).offset(10) make.trailing.top.equalTo(self) - make.height.equalTo(15) + make.height.greaterThanOrEqualTo(15) } self.label.numberOfLines = 1 self.label.lineBreakMode = .byWordWrapping @@ -45,7 +45,7 @@ class ButtonWithSublabel: UIButton { make.bottom.equalTo(self).inset(10) make.top.equalTo(self.label.snp.bottom).offset(3) make.leading.trailing.equalTo(self.label) - make.height.equalTo(10) + make.height.greaterThanOrEqualTo(10) } } diff --git a/Extensions/Today/ImageButtonWithLabel.swift b/Extensions/Today/ImageButtonWithLabel.swift index e511b3e0a72e..57a86d706d0c 100644 --- a/Extensions/Today/ImageButtonWithLabel.swift +++ b/Extensions/Today/ImageButtonWithLabel.swift @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import UIKit -class ImageButtonWithLabel: UIView { +class ImageButtonWithLabel: UIView { lazy var button = UIButton() lazy var label = UILabel() From aca169a2e2bdda9a5352c4d9c5872b942b43bf1a Mon Sep 17 00:00:00 2001 From: noorhashem Date: Tue, 7 Jul 2020 18:56:06 +0200 Subject: [PATCH 8/9] used global string file and updated strings --- Extensions/Today/TodayUX.swift | 7 ------- Extensions/Today/TodayViewController.swift | 14 +++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Extensions/Today/TodayUX.swift b/Extensions/Today/TodayUX.swift index d87633e39336..43bfe67a9d86 100644 --- a/Extensions/Today/TodayUX.swift +++ b/Extensions/Today/TodayUX.swift @@ -28,10 +28,3 @@ struct TodayUX { } } } - -struct TodayStrings { - static let NewPrivateTabButtonLabel = NSLocalizedString("TodayWidget.NewPrivateTabButtonLabel", tableName: "Today", value: "Private Search", comment: "New Private Tab button label") - static let NewTabButtonLabel = NSLocalizedString("TodayWidget.NewTabButtonLabel", tableName: "Today", value: "New Search", comment: "New Tab button label") - static let GoToCopiedLinkLabel = NSLocalizedString("TodayWidget.GoToCopiedLinkLabel", tableName: "Today", value: "Go to copied link", comment: "Go to link on clipboard") - static let CopiedLinkLabelFromPasteBoard = NSLocalizedString("TodayWidget.CopiedLinkLabelFromPasteBoard", tableName: "Today", value: "Copied Link from clipboard", comment: "Copied Link from clipboard displayed") -} diff --git a/Extensions/Today/TodayViewController.swift b/Extensions/Today/TodayViewController.swift index 05b28b1db08f..25792b194cfc 100644 --- a/Extensions/Today/TodayViewController.swift +++ b/Extensions/Today/TodayViewController.swift @@ -19,10 +19,10 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea fileprivate lazy var newTabButton: ImageButtonWithLabel = { let imageButton = ImageButtonWithLabel() imageButton.addTarget(self, action: #selector(onPressNewTab), forControlEvents: .touchUpInside) - imageButton.label.text = TodayStrings.NewTabButtonLabel + imageButton.label.text = String.NewTabButtonLabel let button = imageButton.button button.setImage(UIImage(named: "search-button")?.withRenderingMode(.alwaysOriginal), for: .normal) - button.accessibilityLabel = TodayStrings.NewTabButtonLabel + button.accessibilityLabel = String.NewTabButtonLabel button.accessibilityTraits = .button let label = imageButton.label label.textColor = TodayUX.labelColor @@ -35,10 +35,10 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea fileprivate lazy var newPrivateTabButton: ImageButtonWithLabel = { let imageButton = ImageButtonWithLabel() imageButton.addTarget(self, action: #selector(onPressNewPrivateTab), forControlEvents: .touchUpInside) - imageButton.label.text = TodayStrings.NewPrivateTabButtonLabel + imageButton.label.text = String.NewPrivateTabButtonLabel let button = imageButton.button button.setImage(UIImage(named: "private-search")?.withRenderingMode(.alwaysOriginal), for: .normal) - button.accessibilityLabel = TodayStrings.NewPrivateTabButtonLabel + button.accessibilityLabel = String.NewPrivateTabButtonLabel button.accessibilityTraits = .button let label = imageButton.label label.textColor = TodayUX.labelColor @@ -50,14 +50,14 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea fileprivate lazy var openCopiedLinkButton: ButtonWithSublabel = { let button = ButtonWithSublabel() - button.setTitle(TodayStrings.GoToCopiedLinkLabel, for: .normal) + button.setTitle(String.GoToCopiedLinkLabel, for: .normal) button.addTarget(self, action: #selector(onPressOpenClibpoard), for: .touchUpInside) // We need to set the background image/color for .Normal, so the whole button is tappable. button.setBackgroundColor(UIColor.clear, forState: .normal) button.setBackgroundColor(TodayUX.backgroundHightlightColor, forState: .highlighted) button.setImage(UIImage(named: "copy_link_icon")?.withRenderingMode(.alwaysOriginal), for: .normal) button.label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.labelTextSize)) - button.accessibilityLabel = TodayStrings.GoToCopiedLinkLabel + button.accessibilityLabel = String.GoToCopiedLinkLabel button.accessibilityTraits = .button button.label.textColor = TodayUX.labelColor button.label.tintColor = TodayUX.labelColor @@ -65,7 +65,7 @@ class TodayViewController: UIViewController, NCWidgetProviding, TodayWidgetAppea button.subtitleLabel.textColor = TodayUX.subtitleLabelColor button.subtitleLabel.tintColor = TodayUX.subtitleLabelColor button.subtitleLabel.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont.preferredFont(forTextStyle: .body).withSize(TodayUX.linkTextSize)) - button.label.accessibilityLabel = TodayStrings.CopiedLinkLabelFromPasteBoard + button.label.accessibilityLabel = String.CopiedLinkLabelFromPasteBoard button.accessibilityTraits = .none return button }() From d83a55a2b6fa1b092095331e4e39eb5b61015e37 Mon Sep 17 00:00:00 2001 From: noorhashem Date: Tue, 7 Jul 2020 19:01:36 +0200 Subject: [PATCH 9/9] fixed license header spacings --- Extensions/Today/ImageButtonWithLabel.swift | 4 ++-- Extensions/Today/TodayModel.swift | 4 ++-- Extensions/Today/UIButtonExtensions.swift | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Extensions/Today/ImageButtonWithLabel.swift b/Extensions/Today/ImageButtonWithLabel.swift index 57a86d706d0c..5cfe20fd93fe 100644 --- a/Extensions/Today/ImageButtonWithLabel.swift +++ b/Extensions/Today/ImageButtonWithLabel.swift @@ -1,6 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import UIKit diff --git a/Extensions/Today/TodayModel.swift b/Extensions/Today/TodayModel.swift index 090144b02749..46fc04c89986 100644 --- a/Extensions/Today/TodayModel.swift +++ b/Extensions/Today/TodayModel.swift @@ -1,6 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import Foundation diff --git a/Extensions/Today/UIButtonExtensions.swift b/Extensions/Today/UIButtonExtensions.swift index eb7e6d3c1fb8..a008b3a059ea 100644 --- a/Extensions/Today/UIButtonExtensions.swift +++ b/Extensions/Today/UIButtonExtensions.swift @@ -1,6 +1,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import UIKit