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 bookmark mvp, can add at root level.

  • Loading branch information
iccub committed Apr 14, 2019
commit bbdaa80d02922211ee3a6dd88b1273f19a519d8e
@@ -1647,7 +1647,7 @@ extension BrowserViewController: URLBarDelegate {
}

func urlBarDidTapMenuButton(_ urlBar: URLBarView) {
let homePanel = MenuViewController(bvc: self)
let homePanel = MenuViewController(bvc: self, tab: tabManager.selectedTab)
let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize)
popover.present(from: urlBar.menuButton, on: self)
}
@@ -1697,7 +1697,7 @@ extension BrowserViewController: ToolbarDelegate {
}

func tabToolbarDidPressMenu(_ tabToolbar: ToolbarProtocol, button: UIButton) {
let homePanel = MenuViewController(bvc: self)
let homePanel = MenuViewController(bvc: self, tab: tabManager.selectedTab)
let popover = PopoverController(contentController: homePanel, contentSizeBehavior: .preferredContentSize)
popover.present(from: tabToolbar.menuButton, on: self)
}
@@ -15,119 +15,266 @@ class AddEditBookmarkTableViewController: UITableViewController {
case editFolder(folder: Bookmark)
}

enum Action { case add, edit }

enum BookmarkType {
case bookmark(title: String, url: URL)
case folder(title: String)
}

enum Location {
case favorites
case rootLevel
case folder(folder: Bookmark)

static let favoritesTag = 10
static let rootLevelTag = 11
static let folderTag = 12

var getFolder: Bookmark? {
switch self {
case .folder(let folder): return folder
default: return nil
}
}

}

private enum DataSourcePresentationMode {
/// Showing currently selected save location.
case currentSelection
/// Showing a list of folders of which user can save the Bookmark to.
case folderHierarchy

mutating func toggle() {
switch self {
case .currentSelection: self = .folderHierarchy
case .folderHierarchy: self = .currentSelection
}
}
}

let frc: NSFetchedResultsController<Bookmark>

let mode: Mode
let action: AddEditBookmarkTableViewController.Action
let type: AddEditBookmarkTableViewController.BookmarkType

init(mode: AddEditBookmarkTableViewController.Mode) {
frc = Bookmark.foldersFrc()
self.mode = mode
lazy var saveButton: UIBarButtonItem = {
let button = UIBarButtonItem()
button.target = self
button.action = #selector(save)
button.title = "Save"

super.init(style: .grouped)
return button
}()

var location: Location

lazy var bookmarkDetailsView: BookmarkDetailsView = {
let view = BookmarkDetailsView(type: type)
return view
}()

private var presentationMode: DataSourcePresentationMode

init(action: AddEditBookmarkTableViewController.Action,
type: AddEditBookmarkTableViewController.BookmarkType) {
self.action = action
self.type = type

frc = Bookmark.foldersFrc()
location = .rootLevel
presentationMode = .currentSelection

super.init(style: .grouped)
}

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

var sortedFolders = [IndentedFolder]()

override func viewDidLoad() {
super.viewDidLoad()

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem

navigationController?.navigationBar.topItem?.rightBarButtonItem = saveButton

tableView.rowHeight = 44
tableView.cellLayoutMarginsFollowReadableWidth = false

let bookmarkDetailsView = BookmarkDetailsView()
bookmarkDetailsView.translatesAutoresizingMaskIntoConstraints = false

tableView.tableHeaderView = bookmarkDetailsView

bookmarkDetailsView.snp.makeConstraints {
$0.width.equalTo(self.view)
$0.top.equalTo(self.view)
$0.centerX.equalTo(self.view)
}

tableView.contentInset = UIEdgeInsets(top: 36, left: 0, bottom: 0, right: 0)

bookmarkDetailsView.layoutIfNeeded()

//tableView.tableFooterView = UIView()
frc.delegate = self

try? frc.performFetch()
sortedFolders = sortFolders()

tableView.reloadData()


}

var allFolders = [Bookmark]()
var sortedFolders = [IndentedFolder]()

typealias IndentedFolder = (Bookmark, indentationLevel: Int)

func sortFolders(parentID: NSManagedObjectID? = nil, indentationLevel: Int = 0) -> [IndentedFolder] {
/// 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 [] }

var s = [IndentedFolder]()
var result = [IndentedFolder]()

objects.filter { $0.parentFolder?.objectID == parentID }.forEach {
s.append(($0, indentationLevel: indentationLevel))
s.append(contentsOf: sortFolders(parentID: $0.objectID, indentationLevel: indentationLevel + 1))
result.append(($0, indentationLevel: indentationLevel))
result.append(contentsOf: sortFolders(parentID: $0.objectID,
indentationLevel: indentationLevel + 1))
}

return s
return result
}

var testToggle = false

// MARK: - Table view data source
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)
var newFrame = header.frame
header.setNeedsLayout()
header.layoutIfNeeded()
let newSize = header.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
newFrame.size.height = newSize.height
header.frame = newFrame
tableView.tableHeaderView = header
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 16
@objc func save() {
switch location {
case .rootLevel:
let title = bookmarkDetailsView.titleTextField.text
let url = URL(string: bookmarkDetailsView.urlTextField.text!)

Bookmark.add(url: url!, title: title)
case .favorites: break
case .folder(let folder): break
}

dismiss(animated: true)
}

var totalCount: Int { return sortedFolders.count + 3 }

// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sortedFolders.count
switch presentationMode {
case .currentSelection: return 1
case .folderHierarchy: return sortedFolders.count + 3
}
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Location"
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
testToggle = !testToggle
tableView.deselectRow(at: indexPath, animated: true)
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = IndentedImageTableViewCell()
if presentationMode == .folderHierarchy {
guard let tag = tableView.cellForRow(at: indexPath)?.tag else { return }

switch tag {
case Location.favoritesTag: location = .favorites
case Location.rootLevelTag: location = .rootLevel
case Location.folderTag:
let folder = sortedFolders[indexPath.row - 3].0
location = .folder(folder: folder)
default: assertionFailure("not supported tag was selected: \(tag)")

}
}

let indentedFolder = sortedFolders[indexPath.row]
presentationMode.toggle()

cell.folderName.text = indentedFolder.0.displayTitle
// This gives us an animation while switching between presentation modes.
tableView.reloadSections(IndexSet(integer: 0), with: .automatic)
}

var rootLevelFolderCell: IndentedImageTableViewCell {
let cell = IndentedImageTableViewCell().then {
$0.folderName.text = "Bookmarks"
$0.tag = Location.rootLevelTag
if case .rootLevel = location, presentationMode == .folderHierarchy {
$0.accessoryType = .checkmark
}
}

//cell.textLabel?.text = indentedFolder.0.displayTitle
//cell.imageView?.image = #imageLiteral(resourceName: "bookmarks_folder_hollow")
cell.indentationLevel = indentedFolder.indentationLevel
return cell
}

var favoritesCell: IndentedImageTableViewCell {
let cell = IndentedImageTableViewCell(image: #imageLiteral(resourceName: "bookmark"))
cell.folderName.text = "Favorites"
cell.tag = Location.favoritesTag
if case .favorites = location, presentationMode == .folderHierarchy {
cell.accessoryType = .checkmark
}

return cell
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

switch presentationMode {
case .currentSelection:
switch location {
case .rootLevel: return rootLevelFolderCell
case .favorites: return favoritesCell
case .folder(let folder):
let cell = IndentedImageTableViewCell()
cell.folderName.text = folder.displayTitle
cell.tag = Location.folderTag
return cell
}
case .folderHierarchy:
let row = indexPath.row

if row == 0 {
let cell = IndentedImageTableViewCell(image: #imageLiteral(resourceName: "add_tab"))
cell.folderName.text = "New Folder"
cell.accessoryType = .disclosureIndicator

return cell
}

if row == 1 {
return favoritesCell
}

if row == 2 {
return rootLevelFolderCell
}

let cell = IndentedImageTableViewCell()

let indentedFolder = sortedFolders[row - 3]

cell.folderName.text = indentedFolder.0.displayTitle
cell.indentationLevel = indentedFolder.indentationLevel
cell.tag = Location.folderTag

if let folder = location.getFolder, folder.objectID == indentedFolder.0.objectID {
cell.accessoryType = .checkmark
}

return cell
}
}
}

return cell
extension AddEditBookmarkTableViewController: BookmarkDetailsViewDelegate {
func correctValues(validationPassed: Bool) {
navigationController?.navigationBar.topItem?.rightBarButtonItem?.isEnabled = validationPassed
}


}

// TODO: add frc to see when folders from sync come, do a manual reconfiguration
extension AddEditBookmarkTableViewController: NSFetchedResultsControllerDelegate {
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.