Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[IB2-233] Settings button to the 3-dot menu and make is accessible in…

… start tab
  • Loading branch information
mahmoud-adam85 committed Aug 2, 2018
1 parent 224500f commit a777849d1706e39328769abd1ba055d0942af3a6
@@ -186,6 +186,7 @@ class URLBarView: UIView {

lazy var actionButtons: [Themeable & UIButton] = [self.tabsButton, self.menuButton, self.forwardButton, self.backButton, self.stopReloadButton]

// Cliqz: Note that this attribute has been overriden in the CliqzUrlBar
var currentURL: URL? {
get {
return locationView.url as URL?
@@ -59,10 +59,50 @@ extension BrowserViewController {
presentableVC: PresentableVC,
isBookmarked: Bool,
success: @escaping (String) -> Void) {
let actions = getTabAlertActions(tab: tab, buttonView: buttonView, presentShareMenu: presentShareMenu, findInPage: findInPage, presentableVC: presentableVC, isBookmarked: isBookmarked, success: success)
self.showActionSheet(title: tab.url?.absoluteString, message: nil, actions: actions)

let actions = getAllactions(tab: tab, buttonView: buttonView, presentShareMenu: presentShareMenu, findInPage: findInPage, presentableVC: presentableVC, isBookmarked: isBookmarked, success: success)
let title = (tab.url?.isAboutURL ?? true) ? nil : tab.url?.absoluteString
self.showActionSheet(title: title, message: nil, actions: actions)
}


private func getAllactions(tab: Tab, buttonView: UIView,
presentShareMenu: @escaping () -> Void,
findInPage: @escaping () -> Void,
presentableVC: PresentableVC,
isBookmarked: Bool,
success: @escaping (String) -> Void) -> [UIAlertAction] {

var actions = [UIAlertAction]()

if !(tab.url?.isAboutURL ?? true) {
let tabActions = getTabAlertActions(tab: tab, buttonView: buttonView, presentShareMenu: presentShareMenu, findInPage: findInPage, presentableVC: presentableVC, isBookmarked: isBookmarked, success: success)
actions.append(contentsOf: tabActions)
}

let cancelAction = UIAlertAction(
title: NSLocalizedString("Cancel", comment: "The cancel button."),
style: .cancel,
handler: nil
)

actions.append(contentsOf: getDefaultActions())

actions.append(cancelAction)

return actions
}

private func getDefaultActions() -> [UIAlertAction] {
var defaultActions = [UIAlertAction]()
let settingsAction = UIAlertAction(title: NSLocalizedString("Settings", tableName: "Cliqz", comment: "Settings"), style: .default) { (action) in
self.openSettings()
}

defaultActions.append(settingsAction)

return defaultActions
}

private func getTabAlertActions(tab: Tab, buttonView: UIView,
presentShareMenu: @escaping () -> Void,
findInPage: @escaping () -> Void,
@@ -170,13 +210,7 @@ extension BrowserViewController {
*/
}

let cancelAction = UIAlertAction(
title: NSLocalizedString("Cancel", comment: "The cancel button."),
style: .cancel,
handler: nil
)

mainActions.append(contentsOf: [findInPageAction, toggleDesktopSite, pinToTopSites, share, cancelAction])
mainActions.append(contentsOf: [findInPageAction, toggleDesktopSite, pinToTopSites, share])

return mainActions
}
@@ -27,6 +27,18 @@ class CliqzURLBar: URLBarView {
static let LineHeight: CGFloat = 0.0
}

override var currentURL: URL? {
get {
return locationView.url as URL?
}

set(newURL) {
locationView.url = newURL
line.isHidden = newURL?.isAboutHomeURL ?? true
pageOptionsButton.alpha = 0
}
}

let ghostyHeight = 54.0
let ghostyWidth = 54.0

@@ -55,11 +67,27 @@ class CliqzURLBar: URLBarView {
return button
}()

lazy var pageOptionsButton: UIButton = {
let pageOptionsButton = UIButton(frame: .zero)
pageOptionsButton.setImage(UIImage.templateImageNamed("menu-More-Options"), for: .normal)
pageOptionsButton.addTarget(self, action: #selector(SELDidPressPageOptionsButton), for: .touchUpInside)
pageOptionsButton.isAccessibilityElement = true
pageOptionsButton.imageView?.contentMode = .left
pageOptionsButton.accessibilityIdentifier = "UrlBar.pageOptionsButton"
pageOptionsButton.tintColor = UIColor.cliqzBluePrimary
return pageOptionsButton
}()

@objc func SELdidClickGhosty(button: UIButton) {
debugPrint("pressed ghosty")
NotificationCenter.default.post(name: Notification.Name.GhosteryButtonPressed, object: self.currentURL?.absoluteString)
}


@objc func SELDidPressPageOptionsButton(button: UIButton) {
self.delegate?.urlBarDidPressCliqzPageOptions(self, from: button)
}

override func commonInit() {
super.commonInit()
helper = CliqzTabToolbarHelper(toolbar: self)
@@ -70,6 +98,9 @@ class CliqzURLBar: URLBarView {
if ghosteryButton.superview == nil {
addSubview(ghosteryButton)
}
if pageOptionsButton.superview == nil {
addSubview(pageOptionsButton)
}

line.snp.makeConstraints { make in
make.bottom.leading.trailing.equalTo(self)
@@ -135,6 +166,12 @@ class CliqzURLBar: URLBarView {
make.trailing.equalTo(self.safeArea.trailing)//.offset(-URLBarViewUX.Padding)
}

pageOptionsButton.snp.makeConstraints { (make) in
make.size.equalTo(TabLocationViewUX.ButtonSize)
make.centerY.equalTo(self)
make.trailing.equalTo(self.ghosteryButton.snp.leading)
}

setStyle()
}

@@ -146,11 +183,17 @@ class CliqzURLBar: URLBarView {
override func prepareOverlayAnimation() {
super.prepareOverlayAnimation()
bringSubview(toFront: ghosteryButton)
bringSubview(toFront: pageOptionsButton)
}

override func transitionToOverlay(_ didCancel: Bool = false) {
super.transitionToOverlay()
ghosteryButton.alpha = inOverlayMode ? 0 : 1
if inOverlayMode {
pageOptionsButton.alpha = 0
} else {
pageOptionsButton.alpha = self.currentURL == nil ? 1 : 0
}
}

override func updateConstraints() {
@@ -214,7 +257,7 @@ class CliqzURLBar: URLBarView {
}

override func tabLocationViewDidTapPageOptions(_ tabLocationView: TabLocationView, from button: UIButton) {
self.delegate?.urlBarDidPressCliqzPageOptions(self, from: tabLocationView.pageOptionsButton)
self.delegate?.urlBarDidPressCliqzPageOptions(self, from: button)
}

// MARK:- keyboard Accessory View

0 comments on commit a777849

Please sign in to comment.