Skip to content

Commit

Permalink
Fix #6735 - Added support for private tabs in chronological order(#6786)
Browse files Browse the repository at this point in the history
- Added condition to not show toast for when user is in private mode
- Fixed issue with tabs showing no imageview
  • Loading branch information
nbhasin2 authored and dnarcese committed Oct 20, 2020
1 parent 98aaf67 commit 1ce690c
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 102 deletions.
4 changes: 4 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
43118D07251A9CD100F24376 /* SavedTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63306D3821103EAE00F25400 /* SavedTab.swift */; };
4334145424C63779001541F3 /* IntroScreenSyncViewV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4334145324C63779001541F3 /* IntroScreenSyncViewV1.swift */; };
4334145724C6378B001541F3 /* IntroScreenWelcomeViewV1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4334145624C6378B001541F3 /* IntroScreenWelcomeViewV1.swift */; };
43162A2F2492DB7800F91658 /* EmptyPrivateTabsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43162A2E2492DB7800F91658 /* EmptyPrivateTabsView.swift */; };
43446CE7240D9F3000F5C643 /* ETP.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 43446CE5240D9F3000F5C643 /* ETP.xcassets */; };
43446CEA2412066500F5C643 /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43446CE92412066500F5C643 /* UIViewControllerExtension.swift */; };
43446CF02412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43446CEF2412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift */; };
Expand Down Expand Up @@ -1901,6 +1902,7 @@
42D84A3EBD583A4797682E74 /* ia */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ia; path = ia.lproj/PrivateBrowsing.strings; sourceTree = "<group>"; };
4334145324C63779001541F3 /* IntroScreenSyncViewV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroScreenSyncViewV1.swift; sourceTree = "<group>"; };
4334145624C6378B001541F3 /* IntroScreenWelcomeViewV1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroScreenWelcomeViewV1.swift; sourceTree = "<group>"; };
43162A2E2492DB7800F91658 /* EmptyPrivateTabsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyPrivateTabsView.swift; sourceTree = "<group>"; };
43446CE5240D9F3000F5C643 /* ETP.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = ETP.xcassets; sourceTree = "<group>"; };
43446CE92412066500F5C643 /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIViewControllerExtension.swift; path = Extensions/UIViewControllerExtension.swift; sourceTree = "<group>"; };
43446CEF2412DDBE00F5C643 /* UpdateCoverSheetViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateCoverSheetViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4232,6 +4234,7 @@
23AE36612475A0EF00ACB7BA /* TabTrayV2ViewController.swift */,
23F2C369244E463C00FA4496 /* TabTrayV2ViewModel.swift */,
436715882488216A006D1D4E /* TabTableViewCell.swift */,
43162A2E2492DB7800F91658 /* EmptyPrivateTabsView.swift */,
);
path = Tabs;
sourceTree = "<group>";
Expand Down Expand Up @@ -7772,6 +7775,7 @@
59A681BDFC95A19F05E07223 /* SearchViewController.swift in Sources */,
E6CF28E71CB43B7900151AB3 /* SensitiveViewController.swift in Sources */,
E68E7ADA1CAC207400FDCA76 /* ChangePasscodeViewController.swift in Sources */,
43162A2F2492DB7800F91658 /* EmptyPrivateTabsView.swift in Sources */,
E640E85E1C73A45A00C5F072 /* PasscodeEntryViewController.swift in Sources */,
D0625C98208E87F10081F3B2 /* DownloadQueue.swift in Sources */,
8D8251811F4DE67F00780643 /* AdvancedAccountSettingViewController.swift in Sources */,
Expand Down
6 changes: 5 additions & 1 deletion Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class BrowserViewController: UIViewController {
fileprivate var copyAddressAction: AccessibleAction!

fileprivate weak var tabTrayController: TabTrayControllerV1?
fileprivate weak var tabTrayControllerV2: TabTrayV2ViewController?
let profile: Profile
let tabManager: TabManager

Expand Down Expand Up @@ -1294,6 +1295,7 @@ extension BrowserViewController: URLBarDelegate {
let controller = ThemedNavigationController(rootViewController: tabTrayViewController)
controller.presentingModalViewControllerDelegate = self
self.present(controller, animated: true, completion: nil)
self.tabTrayControllerV2 = tabTrayViewController
} else {
let tabTrayController = TabTrayControllerV1(tabManager: tabManager, profile: profile, tabTrayDelegate: self)
navigationController?.pushViewController(tabTrayController, animated: true)
Expand Down Expand Up @@ -1957,7 +1959,9 @@ extension BrowserViewController: TabManagerDelegate {
}

func tabManagerDidRemoveAllTabs(_ tabManager: TabManager, toast: ButtonToast?) {
guard let toast = toast, !(tabTrayController?.tabDisplayManager.isPrivate ?? false) else {
let tabTrayV2PrivateMode = tabTrayControllerV2?.viewModel.isInPrivateMode
let tabTrayV1PrivateMode = tabTrayController?.tabDisplayManager.isPrivate
guard let toast = toast, !(tabTrayV1PrivateMode ?? (tabTrayV2PrivateMode ?? false)) else {
return
}
show(toast: toast, afterWaiting: ButtonToastUX.ToastDelay)
Expand Down
86 changes: 0 additions & 86 deletions Client/Frontend/Browser/TabTrayControllerV1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -844,92 +844,6 @@ fileprivate class TabLayoutDelegate: NSObject, UICollectionViewDelegateFlowLayou
}
}

private struct EmptyPrivateTabsViewUX {
static let TitleFont = UIFont.systemFont(ofSize: 22, weight: UIFont.Weight.medium)
static let DescriptionFont = UIFont.systemFont(ofSize: 17)
static let LearnMoreFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
static let TextMargin: CGFloat = 18
static let LearnMoreMargin: CGFloat = 30
static let MaxDescriptionWidth: CGFloat = 250
static let MinBottomMargin: CGFloat = 10
}

// View we display when there are no private tabs created
fileprivate class EmptyPrivateTabsView: UIView {
fileprivate lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.Photon.White100
label.font = EmptyPrivateTabsViewUX.TitleFont
label.textAlignment = .center
return label
}()

fileprivate var descriptionLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.Photon.White100
label.font = EmptyPrivateTabsViewUX.DescriptionFont
label.textAlignment = .center
label.numberOfLines = 0
label.preferredMaxLayoutWidth = EmptyPrivateTabsViewUX.MaxDescriptionWidth
return label
}()

fileprivate var learnMoreButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle(
NSLocalizedString("Learn More", tableName: "PrivateBrowsing", comment: "Text button displayed when there are no tabs open while in private mode"),
for: [])
button.setTitleColor(UIColor.theme.tabTray.privateModeLearnMore, for: [])
button.titleLabel?.font = EmptyPrivateTabsViewUX.LearnMoreFont
return button
}()

fileprivate var iconImageView: UIImageView = {
let imageView = UIImageView(image: UIImage.templateImageNamed("largePrivateMask"))
imageView.tintColor = UIColor.Photon.Grey60
return imageView
}()

override init(frame: CGRect) {
super.init(frame: frame)

titleLabel.text = NSLocalizedString("Private Browsing",
tableName: "PrivateBrowsing", comment: "Title displayed for when there are no open tabs while in private mode")
descriptionLabel.text = NSLocalizedString("Firefox won’t remember any of your history or cookies, but new bookmarks will be saved.",
tableName: "PrivateBrowsing", comment: "Description text displayed when there are no open tabs while in private mode")

addSubview(titleLabel)
addSubview(descriptionLabel)
addSubview(iconImageView)
addSubview(learnMoreButton)

titleLabel.snp.makeConstraints { make in
make.center.equalTo(self)
}

iconImageView.snp.makeConstraints { make in
make.bottom.equalTo(titleLabel.snp.top)
make.height.width.equalTo(120)
make.centerX.equalTo(self)
}

descriptionLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(EmptyPrivateTabsViewUX.TextMargin)
make.centerX.equalTo(self)
}

learnMoreButton.snp.makeConstraints { (make) -> Void in
make.top.equalTo(descriptionLabel.snp.bottom).offset(EmptyPrivateTabsViewUX.LearnMoreMargin).priority(10)
make.bottom.lessThanOrEqualTo(self).offset(-EmptyPrivateTabsViewUX.MinBottomMargin).priority(1000)
make.centerX.equalTo(self)
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension TabTrayControllerV1: DevicePickerViewControllerDelegate {
func devicePickerViewController(_ devicePickerViewController: DevicePickerViewController, didPickDevices devices: [RemoteDevice]) {
if let item = devicePickerViewController.shareItem {
Expand Down
93 changes: 93 additions & 0 deletions Client/Frontend/Browser/Tabs/EmptyPrivateTabsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* 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
import SnapKit
import Foundation

struct EmptyPrivateTabsViewUX {
static let TitleFont = UIFont.systemFont(ofSize: 22, weight: UIFont.Weight.medium)
static let DescriptionFont = UIFont.systemFont(ofSize: 17)
static let LearnMoreFont = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
static let TextMargin: CGFloat = 18
static let LearnMoreMargin: CGFloat = 30
static let MaxDescriptionWidth: CGFloat = 250
static let MinBottomMargin: CGFloat = 10
}

// View we display when there are no private tabs created
class EmptyPrivateTabsView: UIView {
lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.Photon.White100
label.font = EmptyPrivateTabsViewUX.TitleFont
label.textAlignment = .center
return label
}()

var descriptionLabel: UILabel = {
let label = UILabel()
label.textColor = UIColor.Photon.White100
label.font = EmptyPrivateTabsViewUX.DescriptionFont
label.textAlignment = .center
label.numberOfLines = 0
label.preferredMaxLayoutWidth = EmptyPrivateTabsViewUX.MaxDescriptionWidth
return label
}()

var learnMoreButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle(
NSLocalizedString("Learn More", tableName: "PrivateBrowsing", comment: "Text button displayed when there are no tabs open while in private mode"),
for: [])
button.setTitleColor(UIColor.theme.tabTray.privateModeLearnMore, for: [])
button.titleLabel?.font = EmptyPrivateTabsViewUX.LearnMoreFont
return button
}()

fileprivate var iconImageView: UIImageView = {
let imageView = UIImageView(image: UIImage.templateImageNamed("largePrivateMask"))
imageView.tintColor = UIColor.Photon.Grey60
return imageView
}()

override init(frame: CGRect) {
super.init(frame: frame)

titleLabel.text = NSLocalizedString("Private Browsing",
tableName: "PrivateBrowsing", comment: "Title displayed for when there are no open tabs while in private mode")
descriptionLabel.text = NSLocalizedString("Firefox won’t remember any of your history or cookies, but new bookmarks will be saved.",
tableName: "PrivateBrowsing", comment: "Description text displayed when there are no open tabs while in private mode")

addSubview(titleLabel)
addSubview(descriptionLabel)
addSubview(iconImageView)
addSubview(learnMoreButton)

titleLabel.snp.makeConstraints { make in
make.center.equalTo(self)
}

iconImageView.snp.makeConstraints { make in
make.bottom.equalTo(titleLabel.snp.top)
make.height.width.equalTo(120)
make.centerX.equalTo(self)
}

descriptionLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(EmptyPrivateTabsViewUX.TextMargin)
make.centerX.equalTo(self)
}

learnMoreButton.snp.makeConstraints { (make) -> Void in
make.top.equalTo(descriptionLabel.snp.bottom).offset(EmptyPrivateTabsViewUX.LearnMoreMargin).priority(10)
make.bottom.lessThanOrEqualTo(self).offset(-EmptyPrivateTabsViewUX.MinBottomMargin).priority(1000)
make.centerX.equalTo(self)
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
51 changes: 45 additions & 6 deletions Client/Frontend/Browser/Tabs/TabTrayV2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct TabTrayV2ControllerUX {
static let textMarginTopBottom = CGFloat(18.0)
}

class TabTrayV2ViewController: UIViewController{
class TabTrayV2ViewController: UIViewController {
// View Model
lazy var viewModel = TabTrayV2ViewModel(viewController: self)
// Views
Expand All @@ -34,6 +34,14 @@ class TabTrayV2ViewController: UIViewController{
tableView.delegate = self
return tableView
}()
lazy var emptyPrivateTabsView: EmptyPrivateTabsView = {
let emptyView = EmptyPrivateTabsView()
emptyView.titleLabel.textColor = .black
emptyView.descriptionLabel.textColor = .black
emptyView.learnMoreButton.addTarget(self, action: #selector(didTapLearnMore), for: .touchUpInside)
return emptyView
}()

// Constants
fileprivate let sectionHeaderIdentifier = "SectionHeader"

Expand All @@ -42,6 +50,11 @@ class TabTrayV2ViewController: UIViewController{
super.viewDidLoad()
viewSetup()
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
viewModel.addPrivateTab()
}

private func viewSetup() {
// MARK: TODO - Theme setup setup
Expand All @@ -54,7 +67,8 @@ class TabTrayV2ViewController: UIViewController{
// Add Subviews
view.addSubview(toolbar)
view.addSubview(tableView)

view.addSubview(emptyPrivateTabsView)
viewModel.updateTabs()
// Constraints
tableView.snp.makeConstraints { make in
make.left.equalTo(view.safeArea.left)
Expand All @@ -67,13 +81,26 @@ class TabTrayV2ViewController: UIViewController{
make.left.right.bottom.equalTo(view)
make.height.equalTo(UIConstants.BottomToolbarHeight)
}

emptyPrivateTabsView.snp.makeConstraints { make in
make.top.left.right.equalTo(view)
make.bottom.equalTo(self.toolbar.snp.top)
}

emptyPrivateTabsView.isHidden = true
}

func shouldShowPrivateTabsView() {
emptyPrivateTabsView.isHidden = !viewModel.shouldShowPrivateView
}

}

// MARK: Datastore
extension TabTrayV2ViewController: UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
shouldShowPrivateTabsView()
return viewModel.numberOfSections()
}

Expand Down Expand Up @@ -114,9 +141,11 @@ extension TabTrayV2ViewController: UITableViewDataSource {
}

@objc func didTogglePrivateMode(_ sender: UIButton) {
let alert = UIAlertController(title: "🚧 Under construction", message: "Private tabs not available yet.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
self.present(alert, animated: true)
// Toggle private mode
viewModel.togglePrivateMode()

// Reload data
viewModel.updateTabs()
}

func hideDisplayedTabs( completion: @escaping () -> Void) {
Expand All @@ -135,10 +164,20 @@ extension TabTrayV2ViewController: UITableViewDataSource {
completion()
})
}

@objc func dismissTabTray() {
// We check if there is private tab then add one if user dismisses
viewModel.addPrivateTab()
navigationController?.dismiss(animated: true, completion: nil)
}

@objc func didTapLearnMore() {
if let privateBrowsingUrl = SupportUtils.URLForTopic("private-browsing-ios") {
let learnMoreRequest = URLRequest(url: privateBrowsingUrl)
viewModel.addTab(learnMoreRequest)
}
self.dismissTabTray()
}
}

extension TabTrayV2ViewController: UITableViewDelegate {
Expand Down
Loading

0 comments on commit 1ce690c

Please sign in to comment.