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

Menu 2.0 #1058

Merged
merged 42 commits into from Jun 6, 2019
Merged

Menu 2.0 #1058

Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
57860c2
MVP for iPhone
iccub Apr 2, 2019
d2a4044
Migrate urlbar items to stackview
iccub Apr 3, 2019
0e2a935
Better naming and file separation for toolbar objects
iccub Apr 3, 2019
799f2c7
WIP: menu actions
iccub Apr 6, 2019
1f25420
Long press actions: dismissal and refactor.
iccub Apr 8, 2019
2cb5750
Remove HomeViewController
iccub Apr 8, 2019
191f371
BookmarksVC cleanup: remove unused code
iccub Apr 8, 2019
7926cfe
folder hirerarchy alpha version
iccub Apr 11, 2019
17afd7d
Make separator line work.
iccub Apr 11, 2019
bbdaa80
Add bookmark mvp, can add at root level.
iccub Apr 14, 2019
7d19867
Merge branch 'development' of github.com:brave/brave-ios into feature…
iccub Apr 14, 2019
ea4f0d8
Adding bookmark works.
iccub Apr 15, 2019
c3a737a
Add folders mvp
iccub Apr 15, 2019
ee76b6a
xcode 10.2
iccub Apr 15, 2019
f06a617
Correct buttons when adding a folder.
iccub Apr 16, 2019
02dab4c
Dismiss view when bookmark is selected.
iccub Apr 16, 2019
c0d29cd
Support editing modes in AddEditBookmarkVC
iccub Apr 16, 2019
736fc5e
Edit without saving location mvp.
iccub Apr 16, 2019
5138870
Edit bookmark location mvp
iccub Apr 17, 2019
ada5f14
Fetch favicon to bookmark details
iccub Apr 17, 2019
134d4a9
whitespace
iccub Apr 17, 2019
d68cad8
Add localized strings
iccub Apr 17, 2019
c022eb5
Edit improvements, title for add/edit screen
iccub Apr 17, 2019
7e30962
Remove unused BookmarkEditViewController
iccub Apr 17, 2019
f781004
Update image assets.
iccub Apr 17, 2019
1d5d612
Make folder detail height equal to folder hierarchy cells height.
iccub Apr 17, 2019
e6c7a1c
Harden against sync changes.
iccub Apr 17, 2019
93c9a24
Make updated url bar work with safe area insets
iccub Apr 17, 2019
880de9e
Show share menu popover at correct location.
iccub Apr 17, 2019
40f11b9
Design feedback from James.
iccub Apr 18, 2019
99b171f
Bookmark/folder detail views refactor.
iccub Apr 18, 2019
0bf5ddc
Header view refactor.
iccub Apr 18, 2019
c57f709
AddEditBookmarkTableViewController refactor.
iccub Apr 19, 2019
1d9e0c3
MenuViewController refactor.
iccub Apr 19, 2019
de90bd1
final touches
iccub Apr 19, 2019
32e1e30
Fix unit tests.
iccub Apr 19, 2019
bc45a12
review
iccub Apr 23, 2019
f7fd274
Make folderCellTag private
iccub Apr 23, 2019
839602c
Merge branch 'development' of github.com:brave/brave-ios into feature…
iccub Apr 23, 2019
8ad53f3
Swift 4.2 conformance
iccub Apr 23, 2019
21d08ed
Fix title helper function
iccub Apr 23, 2019
76ab847
Set syncParentUUID when updating location.
iccub Apr 23, 2019
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Long press actions: dismissal and refactor.

  • Loading branch information
iccub committed Apr 8, 2019
commit 1f2542073815b26736bf8f0ac22d44811e6d001a
@@ -59,6 +59,7 @@
0A53F3E721E6560A0086E80C /* InMemoryDataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A53F3E621E6560A0086E80C /* InMemoryDataController.swift */; };
0A771D35218C8FDC00336E0D /* Bookmark+Sync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A771D34218C8FDC00336E0D /* Bookmark+Sync.swift */; };
0A83D9F121B7FFD200245EF0 /* ABPFilterParserData.dat in Resources */ = {isa = PBXBuildFile; fileRef = 0A83D9E921B7FFD100245EF0 /* ABPFilterParserData.dat */; };
0A8C6993225BC7B100988715 /* ToolbarUrlActionsProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8C6992225BC7B100988715 /* ToolbarUrlActionsProtocol.swift */; };
0AA029F8222E899400D6B535 /* Bookmark+Reorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA029F7222E899400D6B535 /* Bookmark+Reorder.swift */; };
0AA4FC392109D685000B173A /* CRUDProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AA4FC382109D685000B173A /* CRUDProtocols.swift */; };
0AAAAC972249174A009A8763 /* SyncAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AAAAC962249174A009A8763 /* SyncAlerts.swift */; };
@@ -1177,6 +1178,7 @@
0A6231E32121F761007B429B /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
0A771D34218C8FDC00336E0D /* Bookmark+Sync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bookmark+Sync.swift"; sourceTree = "<group>"; };
0A83D9E921B7FFD100245EF0 /* ABPFilterParserData.dat */ = {isa = PBXFileReference; lastKnownFileType = file; path = ABPFilterParserData.dat; sourceTree = "<group>"; };
0A8C6992225BC7B100988715 /* ToolbarUrlActionsProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarUrlActionsProtocol.swift; sourceTree = "<group>"; };
0A9B6A3420E6453400712BC9 /* Model8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model8.xcdatamodel; sourceTree = "<group>"; };
0AA029F7222E899400D6B535 /* Bookmark+Reorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bookmark+Reorder.swift"; sourceTree = "<group>"; };
0AA4FC382109D685000B173A /* CRUDProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CRUDProtocols.swift; sourceTree = "<group>"; };
@@ -3433,6 +3435,7 @@
A1AD4BCE20BF3E8C007A6EA1 /* BookmarksViewController.swift */,
A198E75020C701ED00334C11 /* HistoryViewController.swift */,
44331DBA22521013007E3E93 /* MenuViewController.swift */,
0A8C6992225BC7B100988715 /* ToolbarUrlActionsProtocol.swift */,
);
path = Menu;
sourceTree = "<group>";
@@ -5816,6 +5819,7 @@
0BA1E02E1B046F1E007675AF /* ErrorPageHelper.swift in Sources */,
D3A9949C1A3686BD008AD1AC /* BrowserViewController.swift in Sources */,
59A681BDFC95A19F05E07223 /* SearchViewController.swift in Sources */,
0A8C6993225BC7B100988715 /* ToolbarUrlActionsProtocol.swift in Sources */,
A1CDF22B20BDD6B8005C6E58 /* POPExtensions.swift in Sources */,
E68E7ADA1CAC207400FDCA76 /* ChangePasscodeViewController.swift in Sources */,
E640E85E1C73A45A00C5F072 /* PasscodeEntryViewController.swift in Sources */,
@@ -221,7 +221,7 @@ class BrowserViewController: UIViewController {
toolbar = nil

if showToolbar {
toolbar = BottomToolbarView()
toolbar = BottomToolbarView() //exc bad access
footer.addSubview(toolbar!)
toolbar?.tabToolbarDelegate = self

@@ -2874,14 +2874,12 @@ extension BrowserViewController: HomeMenuControllerDelegate {
case .copy:
UIPasteboard.general.url = url
case .share:
menu.dismiss(animated: true) {
self.presentActivityViewController(
url,
sourceView: self.view,
sourceRect: self.view.convert(self.urlBar.shareButton.frame, from: self.urlBar.shareButton.superview),
arrowDirection: [.up]
)
}
presentActivityViewController(
url,
sourceView: self.view,
sourceRect: self.view.convert(self.urlBar.shareButton.frame, from: self.urlBar.shareButton.superview),
arrowDirection: [.up]
)
}
}

@@ -101,7 +101,7 @@ class BookmarkEditingViewController: FormViewController {
}
}

class BookmarksViewController: SiteTableViewController {
class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtocol {
/// Called when the bookmarks are updated via some user input (i.e. Delete, edit, etc.)
var bookmarksDidChange: (() -> Void)?

@@ -379,6 +379,37 @@ class BookmarksViewController: SiteTableViewController {
}
}
}

@objc private func longPressedCell(_ gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began,
let cell = gesture.view as? UITableViewCell,
let indexPath = tableView.indexPath(for: cell),
let bookmark = bookmarksFRC?.object(at: indexPath) else {
return
}

presentLongPressActions(gesture, urlString: bookmark.url, isPrivateBrowsing: isPrivateBrowsing,
customActions: bookmark.isFolder ? folderLongPressActions(bookmark) : nil)
}

private func folderLongPressActions(_ folder: Bookmark) -> [UIAlertAction] {
let children = Bookmark.getChildren(forFolder: folder, includeFolders: false) ?? []

let urls: [URL] = children.compactMap { b in
guard let url = b.url else { return nil }
return URL(string: url)
}

return [
UIAlertAction(
title: String(format: Strings.Open_All_Bookmarks, children.count),
style: .default,
handler: { [weak self] _ in
self?.toolbarUrlActionsDelegate?.batchOpen(urls)
}
)
]
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
@@ -606,86 +637,3 @@ extension BookmarksViewController: NSFetchedResultsControllerDelegate {
}
}

private let ActionSheetTitleMaxLength = 120

extension BookmarksViewController {

@objc private func longPressedCell(_ gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began,
let cell = gesture.view as? UITableViewCell,
let indexPath = tableView.indexPath(for: cell),
let bookmark = bookmarksFRC?.object(at: indexPath) else {
return
}

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

if bookmark.isFolder {
actionsForFolder(bookmark).forEach { alert.addAction($0) }
} else {
alert.title = bookmark.url?.replacingOccurrences(of: "mailto:", with: "").ellipsize(maxLength: ActionSheetTitleMaxLength)
actionsForBookmark(bookmark, currentTabIsPrivate: isPrivateBrowsing).forEach { alert.addAction($0) }
}

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)
alert.addAction(cancelAction)

// If we're showing an arrow popup, set the anchor to the long press location.
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = view
popoverPresentationController.sourceRect = CGRect(origin: gesture.location(in: view), size: CGSize(width: 0, height: 16))
popoverPresentationController.permittedArrowDirections = .any
}

present(alert, animated: true)
}

private func actionsForFolder(_ folder: Bookmark) -> [UIAlertAction] {
let children = Bookmark.getChildren(forFolder: folder, includeFolders: false) ?? []

let urls: [URL] = children.compactMap { b in
guard let url = b.url else { return nil }
return URL(string: url)
}

return [
UIAlertAction(
title: String(format: Strings.Open_All_Bookmarks, children.count),
style: .default,
handler: { [weak self] _ in
self?.toolbarUrlActionsDelegate?.batchOpen(urls)
}
)
]
}

private func actionsForBookmark(_ bookmark: Bookmark, currentTabIsPrivate: Bool) -> [UIAlertAction] {
guard let urlString = bookmark.url, let url = URL(string: urlString) else { return [] }

var items: [UIAlertAction] = []
// New Tab
items.append(UIAlertAction(title: Strings.OpenNewTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: currentTabIsPrivate)
}))
if !currentTabIsPrivate {
// New Private Tab
items.append(UIAlertAction(title: Strings.OpenNewPrivateTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: true)
}))
}
// Copy
items.append(UIAlertAction(title: Strings.CopyLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.copy(url)
}))
// Share
items.append(UIAlertAction(title: Strings.ShareLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.share(url)
}))

return items
}
}
@@ -15,7 +15,7 @@ private struct HistoryViewControllerUX {
static let WelcomeScreenItemWidth = 170
}

class HistoryViewController: SiteTableViewController {
class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol {
weak var toolbarUrlActionsDelegate: ToolbarUrlActionsDelegate?
fileprivate lazy var emptyStateOverlayView: UIView = self.createEmptyStateOverview()
var frc: NSFetchedResultsController<History>?
@@ -129,10 +129,23 @@ class HistoryViewController: SiteTableViewController {
let site = frc?.object(at: indexPath)

if let u = site?.url, let url = URL(string: u) {
toolbarUrlActionsDelegate?.select(url: url, visitType: .typed)
dismiss(animated: true) {
self.toolbarUrlActionsDelegate?.select(url: url, visitType: .typed)
}
}
tableView.deselectRow(at: indexPath, animated: true)
}

@objc private func longPressedCell(_ gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began,
let cell = gesture.view as? UITableViewCell,
let indexPath = tableView.indexPath(for: cell),
let urlString = frc?.object(at: indexPath).url else {
return
}

presentLongPressActions(gesture, urlString: urlString, isPrivateBrowsing: isPrivateBrowsing)
}

func numberOfSections(in tableView: UITableView) -> Int {
return frc?.sections?.count ?? 0
@@ -208,64 +221,3 @@ extension HistoryViewController: NSFetchedResultsControllerDelegate {
updateEmptyPanelState()
}
}

private let ActionSheetTitleMaxLength = 120

extension HistoryViewController {

@objc private func longPressedCell(_ gesture: UILongPressGestureRecognizer) {
guard gesture.state == .began,
let cell = gesture.view as? UITableViewCell,
let indexPath = tableView.indexPath(for: cell),
let history = frc?.object(at: indexPath) else {
return
}

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

alert.title = history.url?.replacingOccurrences(of: "mailto:", with: "").ellipsize(maxLength: ActionSheetTitleMaxLength)
actionsForHistory(history, currentTabIsPrivate: isPrivateBrowsing).forEach { alert.addAction($0) }

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)
alert.addAction(cancelAction)

// If we're showing an arrow popup, set the anchor to the long press location.
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = view
popoverPresentationController.sourceRect = CGRect(origin: gesture.location(in: view), size: CGSize(width: 0, height: 16))
popoverPresentationController.permittedArrowDirections = .any
}

present(alert, animated: true)
}

private func actionsForHistory(_ history: History, currentTabIsPrivate: Bool) -> [UIAlertAction] {
guard let urlString = history.url, let url = URL(string: urlString) else { return [] }

var items: [UIAlertAction] = []
// New Tab
items.append(UIAlertAction(title: Strings.OpenNewTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: currentTabIsPrivate)
}))
if !currentTabIsPrivate {
// New Private Tab
items.append(UIAlertAction(title: Strings.OpenNewPrivateTabButtonTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.openInNewTab(url, isPrivate: true)
}))
}
// Copy
items.append(UIAlertAction(title: Strings.CopyLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.copy(url)
}))
// Share
items.append(UIAlertAction(title: Strings.ShareLinkActionTitle, style: .default, handler: { [weak self] _ in
guard let `self` = self else { return }
self.toolbarUrlActionsDelegate?.share(url)
}))

return items
}
}
@@ -0,0 +1,70 @@
// 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 Shared

protocol ToolbarUrlActionsProtocol where Self: UIViewController {

This comment has been minimized.

Copy link
@iccub

iccub Apr 19, 2019

Author Contributor

No changes here, moved it to its own file

var toolbarUrlActionsDelegate: ToolbarUrlActionsDelegate? { get }

func presentLongPressActions(_ gesture: UILongPressGestureRecognizer, urlString: String?,
isPrivateBrowsing: Bool, customActions: [UIAlertAction]?)
}

extension ToolbarUrlActionsProtocol {
func presentLongPressActions(_ gesture: UILongPressGestureRecognizer, urlString: String?,
isPrivateBrowsing: Bool, customActions: [UIAlertAction]? = nil) {

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.title = urlString?.replacingOccurrences(of: "mailto:", with: "").ellipsize(maxLength: 120)

let alertActions = customActions ?? actions(forUrl: URL(string: urlString ?? ""),
currentTabIsPrivate: isPrivateBrowsing)
alertActions.forEach { alert.addAction($0) }

if alertActions.isEmpty {
assertionFailure("Alert actions should not be empty")
return
}

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)
alert.addAction(cancelAction)

// If we're showing an arrow popup, set the anchor to the long press location.
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = view
popoverPresentationController.sourceRect = CGRect(origin: gesture.location(in: view), size: CGSize(width: 0, height: 16))
popoverPresentationController.permittedArrowDirections = .any
}

present(alert, animated: true)
}

private func actions(forUrl url: URL?, currentTabIsPrivate: Bool) -> [UIAlertAction] {
guard let url = url, let delegate = toolbarUrlActionsDelegate else { return [] }

typealias Action = (title: String, action: () -> Void)

let newTabAction = Action(title: Strings.OpenNewTabButtonTitle,
action: { delegate.openInNewTab(url, isPrivate: currentTabIsPrivate) })

let newPrivateTabAction = currentTabIsPrivate ? nil :
Action(title: Strings.OpenNewPrivateTabButtonTitle, action: {
delegate.openInNewTab(url, isPrivate: currentTabIsPrivate)
})

let copyAction = Action(title: Strings.CopyLinkActionTitle,
action: { delegate.copy(url) })

let shareAction = Action(title: Strings.ShareLinkActionTitle,
action: { delegate.share(url) })

return [newTabAction, newPrivateTabAction, copyAction, shareAction].compactMap { $0 }.map { action in
UIAlertAction(title: action.title, style: .default) { _ in
self.dismiss(animated: true, completion: action.action)
}
}
}

}
@@ -15,7 +15,7 @@ class ToolbarButton: UIButton {
selectedTintColor = tintColor
unselectedTintColor = tintColor
disabledTintColor = UIColor.Photon.Grey50
imageView?.contentMode = .scaleAspectFit
imageView?.contentMode = .scaleAspectFit //exc bad access
}

required init?(coder aDecoder: NSCoder) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.