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

Add folders mvp

  • Loading branch information
iccub committed Apr 15, 2019
commit c3a737a45581b054eecf674a564b5dad7b170080
@@ -64,6 +64,8 @@
0A8C69AB225CFCAF00988715 /* AddEditBookmarkTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8C69AA225CFCAF00988715 /* AddEditBookmarkTableViewController.swift */; };
0A8C69B5225DE99700988715 /* BookmarkDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8C69B4225DE99700988715 /* BookmarkDetailsView.swift */; };
0A8C69BE225E350300988715 /* IndentedImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A8C69BD225E350300988715 /* IndentedImageTableViewCell.swift */; };
0A93F1802264C2D200A3571B /* FolderDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A93F17F2264C2D200A3571B /* FolderDetailsView.swift */; };
0A93F1892264C72000A3571B /* BookmarkFormFieldsProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A93F1882264C72000A3571B /* BookmarkFormFieldsProtocol.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 */; };
@@ -1186,6 +1188,8 @@
0A8C69AA225CFCAF00988715 /* AddEditBookmarkTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddEditBookmarkTableViewController.swift; sourceTree = "<group>"; };
0A8C69B4225DE99700988715 /* BookmarkDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkDetailsView.swift; sourceTree = "<group>"; };
0A8C69BD225E350300988715 /* IndentedImageTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndentedImageTableViewCell.swift; sourceTree = "<group>"; };
0A93F17F2264C2D200A3571B /* FolderDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderDetailsView.swift; sourceTree = "<group>"; };
0A93F1882264C72000A3571B /* BookmarkFormFieldsProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkFormFieldsProtocol.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>"; };
@@ -3445,6 +3449,8 @@
0A8C69AA225CFCAF00988715 /* AddEditBookmarkTableViewController.swift */,
0A8C69B4225DE99700988715 /* BookmarkDetailsView.swift */,
0A8C69BD225E350300988715 /* IndentedImageTableViewCell.swift */,
0A93F17F2264C2D200A3571B /* FolderDetailsView.swift */,
0A93F1882264C72000A3571B /* BookmarkFormFieldsProtocol.swift */,
);
path = Menu;
sourceTree = "<group>";
@@ -5789,6 +5795,7 @@
E68E7ACB1CAC1D4500FDCA76 /* PagingPasscodeViewController.swift in Sources */,
D04D1B92209790B60074B35F /* Toast.swift in Sources */,
D34DC8531A16C40C00D49B7B /* Profile.swift in Sources */,
0A93F1892264C72000A3571B /* BookmarkFormFieldsProtocol.swift in Sources */,
0A8C699C225BDDC500988715 /* BookmarkEditViewController.swift in Sources */,
4422D4D821BFFB7600BF1855 /* block.cc in Sources */,
E65075541E37F6FC006961AC /* DynamicFontHelper.swift in Sources */,
@@ -5845,6 +5852,7 @@
D0625C98208E87F10081F3B2 /* DownloadQueue.swift in Sources */,
4422D54621BFFB7E00BF1855 /* rune.cc in Sources */,
EB11A1052044A90E0018F749 /* TrackingProtectionPageStats.swift in Sources */,
0A93F1802264C2D200A3571B /* FolderDetailsView.swift in Sources */,
E633E2DA1C21EAF8001FFF6C /* LoginDetailViewController.swift in Sources */,
E65D89181C8647420006EA35 /* AppAuthenticator.swift in Sources */,
28FDFF0C1C1F725800840F86 /* SeparatorTableCell.swift in Sources */,
@@ -6,6 +6,10 @@ import UIKit
import CoreData
import Data

protocol AddEditBookmarkDelegate: class {
func didSelectFolder(/*_ folder: Bookmark*/)
}

class AddEditBookmarkTableViewController: UITableViewController {

enum Mode {
@@ -30,6 +34,7 @@ class AddEditBookmarkTableViewController: UITableViewController {
static let favoritesTag = 10
static let rootLevelTag = 11
static let folderTag = 12
static let newFolderTag = 13

var getFolder: Bookmark? {
switch self {
@@ -70,13 +75,19 @@ class AddEditBookmarkTableViewController: UITableViewController {

var location: Location

lazy var bookmarkDetailsView: BookmarkDetailsView = {
let view = BookmarkDetailsView(type: type)
return view
lazy var bookmarkDetailsView: BookmarkFormFieldsProtocol = {
switch type {
case .bookmark(let title, let url):
return BookmarkDetailsView(title: title, url: url)
case .folder(let title):
return FolderDetailsViewTableViewCell(title: title)
}
}()

private var presentationMode: DataSourcePresentationMode

weak var delegate: AddEditBookmarkDelegate?

init(action: AddEditBookmarkTableViewController.Action,
type: AddEditBookmarkTableViewController.BookmarkType) {
self.action = action
@@ -98,7 +109,7 @@ class AddEditBookmarkTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()

navigationController?.navigationBar.topItem?.rightBarButtonItem = saveButton
navigationItem.rightBarButtonItem = saveButton

tableView.rowHeight = 44
tableView.contentInset = UIEdgeInsets(top: 36, left: 0, bottom: 0, right: 0)
@@ -110,16 +121,22 @@ class AddEditBookmarkTableViewController: UITableViewController {
tableView.reloadData()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

typealias IndentedFolder = (Bookmark, indentationLevel: Int)

/// Indentation level starts with 0, but this level is designed for arbitrary folders
/// (root level bookamrks, favorites)
func sortFolders(parentID: NSManagedObjectID? = nil, indentationLevel: Int = 1) -> [IndentedFolder] {
guard let objects = frc.fetchedObjects else { return [] }

let sortedObjects = objects.sorted(by: { $0.order < $1.order })

var result = [IndentedFolder]()

objects.filter { $0.parentFolder?.objectID == parentID }.forEach {
sortedObjects.filter { $0.parentFolder?.objectID == parentID }.forEach {
result.append(($0, indentationLevel: indentationLevel))
result.append(contentsOf: sortFolders(parentID: $0.objectID,
indentationLevel: indentationLevel + 1))
@@ -131,13 +148,12 @@ class AddEditBookmarkTableViewController: UITableViewController {
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if tableView.tableHeaderView != nil { return }

let header = bookmarkDetailsView
header.delegate = self

header.setNeedsUpdateConstraints()
header.updateConstraintsIfNeeded()
header.frame = CGRect(x: 0, y: 0, width: tableView.bounds.width, height: CGFloat.greatestFiniteMagnitude)
header.frame = CGRect(x: 0, y: 0, width: tableView.bounds.width, height: tableView.bounds.height)
var newFrame = header.frame
header.setNeedsLayout()
header.layoutIfNeeded()
@@ -148,22 +164,46 @@ class AddEditBookmarkTableViewController: UITableViewController {
}

@objc func save() {
guard let title = bookmarkDetailsView.titleTextField.text, let urlString = bookmarkDetailsView.urlTextField.text, let url = URL(string: urlString) else {
func earlyReturn() {
assertionFailure()
dismiss(animated: true)
return
}

switch location {
case .rootLevel:
Bookmark.add(url: url, title: title)
case .favorites:
Bookmark.addFavorite(url: url, title: title)
case .folder(let folder):
Bookmark.add(url: url, title: title, parentFolder: folder)
guard let title = bookmarkDetailsView.titleTextField.text else { return earlyReturn() }

switch type {
case .bookmark(_, _):
guard let urlString = bookmarkDetailsView.urlTextField?.text,
let url = URL(string: urlString) else {
return earlyReturn()
}

switch location {
case .rootLevel:
Bookmark.add(url: url, title: title)
case .favorites:
Bookmark.addFavorite(url: url, title: title)
case .folder(let folder):
Bookmark.add(url: url, title: title, parentFolder: folder)
}
case .folder(_):
switch location {
case .rootLevel:
Bookmark.addFolder(title: title)
case .favorites:
fatalError("Folders can't be saved to favorites")
case .folder(let folder):
Bookmark.addFolder(title: title, parentFolder: folder)
}

delegate?.didSelectFolder()
}

dismiss(animated: true)
if let nc = navigationController, nc.childViewControllers.count > 1 {
navigationController?.popViewController(animated: true)
} else {
dismiss(animated: true)
}
}

var totalCount: Int { return sortedFolders.count + 3 }
@@ -188,6 +228,7 @@ class AddEditBookmarkTableViewController: UITableViewController {
switch tag {
case Location.favoritesTag: location = .favorites
case Location.rootLevelTag: location = .rootLevel
case Location.newFolderTag: showNewFolderVC()
case Location.folderTag:
let folder = sortedFolders[indexPath.row - 3].0
location = .folder(folder: folder)
@@ -202,6 +243,12 @@ class AddEditBookmarkTableViewController: UITableViewController {
tableView.reloadSections(IndexSet(integer: 0), with: .automatic)
}

func showNewFolderVC() {
let vc = AddEditBookmarkTableViewController(action: .add, type: .folder(title: "New folder"))
vc.delegate = self
navigationController?.pushViewController(vc, animated: true)
}

var rootLevelFolderCell: IndentedImageTableViewCell {
let cell = IndentedImageTableViewCell().then {
$0.folderName.text = "Bookmarks"
@@ -245,6 +292,7 @@ class AddEditBookmarkTableViewController: UITableViewController {
let cell = IndentedImageTableViewCell(image: #imageLiteral(resourceName: "add_tab"))
cell.folderName.text = "New Folder"
cell.accessoryType = .disclosureIndicator
cell.tag = Location.newFolderTag

return cell
}
@@ -280,6 +328,24 @@ extension AddEditBookmarkTableViewController: BookmarkDetailsViewDelegate {
}
}

extension AddEditBookmarkTableViewController: AddEditBookmarkDelegate {
func didSelectFolder(/*_ folder: Bookmark*/) {
// FIXME: Does not work, saving folder is async
//try? frc.performFetch()
//sortedFolders = sortFolders()
//tableView.reloadData()
}
}

// TODO: add frc to see when folders from sync come, do a manual reconfiguration
extension AddEditBookmarkTableViewController: NSFetchedResultsControllerDelegate {
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {

// Possible performance bottleneck
try? frc.performFetch()
sortedFolders = sortFolders()

tableView.reloadData()
}
}
@@ -9,7 +9,7 @@ protocol BookmarkDetailsViewDelegate: class {
func correctValues(validationPassed: Bool)
}

class BookmarkDetailsView: UIView {
class BookmarkDetailsView: UIView, BookmarkFormFieldsProtocol {

let mainStackView = UIStackView().then {
$0.axis = .vertical
@@ -40,7 +40,7 @@ class BookmarkDetailsView: UIView {
$0.tag = 22
}

let urlTextField = UITextField().then {
let urlTextField: UITextField? = UITextField().then {
$0.placeholder = "Address"
$0.keyboardType = .webSearch
$0.autocorrectionType = .no
@@ -63,9 +63,11 @@ class BookmarkDetailsView: UIView {

weak var delegate: BookmarkDetailsViewDelegate?

convenience init(type: AddEditBookmarkTableViewController.BookmarkType) {
convenience init(title: String, url: URL) {
self.init(frame: .zero)

guard let urlTextField = urlTextField else { fatalError() }

mainStackView.addArrangedSubview(spacerLine)
mainStackView.addArrangedSubview(contentStackView)
mainStackView.addArrangedSubview(spacerLine)
@@ -79,13 +81,8 @@ class BookmarkDetailsView: UIView {

faviconImageView.setContentHuggingPriority(.defaultHigh, for: .horizontal)

switch type {
case .bookmark(let title, let url):
titleTextField.text = title
urlTextField.text = url.absoluteString
default:
break
}
titleTextField.text = title
urlTextField.text = url.absoluteString

mainStackView.snp.makeConstraints {
$0.edges.equalTo(self)
@@ -96,33 +93,22 @@ class BookmarkDetailsView: UIView {
super.init(frame: frame)

backgroundColor = .white

addSubview(mainStackView)

setupTextFieldTargets()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

func setupTextFieldTargets() {
[titleTextField, urlTextField].forEach {
$0.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
$0?.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
}
}

@objc func textFieldDidChange(_ textField: UITextField) {
delegate?.correctValues(validationPassed: correctValues)
}

var correctValues: Bool {
guard let title = titleTextField.text, let url = urlTextField.text else { return false }

if title.isEmpty || url.isEmpty { return false }

// Must be valid URL
if URL(string: url) == nil { return false }

return true
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
delegate?.correctValues(validationPassed: validateFields())
}
}
@@ -0,0 +1,40 @@
// 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 Shared

protocol BookmarkFormFieldsProtocol where Self: UIView {
var titleTextField: UITextField { get }
/// Nil by default
var urlTextField: UITextField? { get }

var delegate: BookmarkDetailsViewDelegate? { get set }

func validateFields() -> Bool
}

extension BookmarkFormFieldsProtocol {
var urlTextField: UITextField? { return nil }

func validateFields() -> Bool {
// Only title field is implemented
if urlTextField == nil {
guard let titleText = titleTextField.text else { return false }
return validateTitle(titleText)
}

guard let title = titleTextField.text, let url = urlTextField?.text else { return false }

return validateTitle(title) && validateUrl(url)
}

private func validateTitle(_ title: String) -> Bool {
return !title.isEmpty
}

private func validateUrl(_ urlString: String) -> Bool {
return URL(string: urlString)?.schemeIsValid == true
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.