From b19f3e399e19fbc6039f5e4f845c6b5ba2870598 Mon Sep 17 00:00:00 2001 From: Daniel Dervishi <58835213+DanielDervishi@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:08:01 -0500 Subject: [PATCH] Add FXIOS-9766 [Bookmarks Evolution] Update Bookmarks Panel View Edit Mode Part 1 (#23676) * Completed Ticket * Quick reversion' * Feature flagged segment control status update on edit * Swiftlint Fix * Addressed Comments * Fixed Swiftlint Violations --- .../Bookmarks/BookmarksViewController.swift | 61 +++---------------- .../LibraryViewController.swift | 21 ++++++- 2 files changed, 27 insertions(+), 55 deletions(-) diff --git a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift index 7863ea99dd21..4e70c348105e 100644 --- a/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift +++ b/firefox-ios/Client/Frontend/Library/Bookmarks/BookmarksViewController.swift @@ -61,7 +61,7 @@ class BookmarksViewController: SiteTableViewController, private lazy var bottomLeftButton: UIBarButtonItem = { let button = UIBarButtonItem( - image: UIImage.templateImageNamed(StandardImageIdentifiers.Large.plus), + title: .BookmarksNewFolder, style: .plain, target: self, action: #selector(bottomLeftButtonAction) @@ -153,58 +153,6 @@ class BookmarksViewController: SiteTableViewController, } } - // MARK: - Actions - - func presentInFolderActions() { - let viewModel = PhotonActionSheetViewModel(actions: [[getNewFolderAction(), - getNewSeparatorAction()]], - modalStyle: .overFullScreen) - let sheet = PhotonActionSheet(viewModel: viewModel, windowUUID: windowUUID) - sheet.modalTransitionStyle = .crossDissolve - present(sheet, animated: true) - } - - private func getNewFolderAction() -> PhotonRowActions { - return SingleActionViewModel( - title: .BookmarksNewFolder, - iconString: StandardImageIdentifiers.Large.folder, - tapHandler: { _ in - guard let bookmarkFolder = self.viewModel.bookmarkFolder else { return } - - self.bookmarkCoordinatorDelegate?.showBookmarkDetail( - bookmarkType: .folder, - parentBookmarkFolder: bookmarkFolder - ) - }).items - } - - private func getNewSeparatorAction() -> PhotonRowActions { - return SingleActionViewModel(title: .BookmarksNewSeparator, - iconString: StandardImageIdentifiers.Large.appMenu, - tapHandler: { _ in - let centerVisibleRow = self.centerVisibleRow() - - self.profile.places.createSeparator(parentGUID: self.viewModel.bookmarkFolderGUID, - position: UInt32(centerVisibleRow)) >>== { guid in - self.profile.places.getBookmark(guid: guid).uponQueue(.main) { result in - guard let bookmarkNode = result.successValue, - let bookmarkSeparator = bookmarkNode as? BookmarkSeparatorData - else { return } - - let indexPath = IndexPath(row: centerVisibleRow, - section: BookmarksPanelViewModel.BookmarksSection.bookmarks.rawValue) - self.tableView.beginUpdates() - self.viewModel.bookmarkNodes.insert(bookmarkSeparator, at: centerVisibleRow) - self.tableView.insertRows(at: [indexPath], with: .automatic) - self.tableView.endUpdates() - - self.updateEmptyState() - self.flashRow(at: indexPath) - } - } - }).items - } - private func centerVisibleRow() -> Int { let visibleCells = tableView.visibleCells if let middleCell = visibleCells[safe: visibleCells.count / 2], @@ -651,7 +599,12 @@ extension BookmarksViewController: Notifiable { extension BookmarksViewController { func bottomLeftButtonAction() { if state == .bookmarks(state: .inFolderEditMode) { - presentInFolderActions() + guard let bookmarkFolder = viewModel.bookmarkFolder else { return } + + bookmarkCoordinatorDelegate?.showBookmarkDetail( + bookmarkType: .folder, + parentBookmarkFolder: bookmarkFolder + ) } } diff --git a/firefox-ios/Client/Frontend/Library/LibraryViewController/LibraryViewController.swift b/firefox-ios/Client/Frontend/Library/LibraryViewController/LibraryViewController.swift index 4b612036af99..267cbce670bb 100644 --- a/firefox-ios/Client/Frontend/Library/LibraryViewController/LibraryViewController.swift +++ b/firefox-ios/Client/Frontend/Library/LibraryViewController/LibraryViewController.swift @@ -12,7 +12,7 @@ extension LibraryViewController: UIToolbarDelegate { } } -class LibraryViewController: UIViewController, Themeable { +class LibraryViewController: UIViewController, Themeable, BookmarksRefactorFeatureFlagProvider { struct UX { struct NavigationMenu { static let height: CGFloat = 32 @@ -132,6 +132,7 @@ class LibraryViewController: UIViewController, Themeable { func updateViewWithState() { setupButtons() + updateSegmentControl() } fileprivate func updateTitle() { @@ -324,6 +325,23 @@ class LibraryViewController: UIViewController, Themeable { navigationController?.toolbar.tintColor = theme.colors.actionPrimary } + private func updateSegmentControl() { + guard isBookmarkRefactorEnabled else { return } + let panelState = getCurrentPanelState() + + switch panelState { + case .bookmarks(state: .inFolderEditMode): + let affectedOptions: [LibraryPanelType] = [.history, .downloads, .readingList] + affectedOptions.forEach { librarySegmentOption in + self.librarySegmentControl.setEnabled(false, forSegmentAt: librarySegmentOption.rawValue) + } + default: + LibraryPanelType.allCases.forEach { librarySegmentOption in + self.librarySegmentControl.setEnabled(true, forSegmentAt: librarySegmentOption.rawValue) + } + } + } + func applyTheme() { // There is an ANNOYING bar in the nav bar above the segment control. These are the // UIBarBackgroundShadowViews. We must set them to be clear images in order to @@ -361,6 +379,7 @@ extension LibraryViewController: Notifiable { switch notification.name { case .LibraryPanelStateDidChange: setupButtons() + updateSegmentControl() default: break } }