Skip to content

Commit

Permalink
Add FXIOS-9765/FXIOS-10496 [Bookmarks Evolution] Edit bookmark action…
Browse files Browse the repository at this point in the history
… for legacy menu (#23826)
  • Loading branch information
MattLichtenstein authored Dec 20, 2024
1 parent a0c1d81 commit 3e1fc42
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,8 @@ extension BrowserViewController: ToolBarActionMenuDelegate, UIDocumentPickerDele
documentPicker.modalPresentationStyle = .formSheet
showViewController(viewController: documentPicker)
}

func showEditBookmark() {
openBookmarkEditPanel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1690,35 +1690,57 @@ class BrowserViewController: UIViewController,
}

/// This function will open a view separate from the bookmark edit panel found in the
/// Library Panel - Bookmarks section. In order to get the correct information, it needs
/// to fetch the last added bookmark in the mobile folder, which is the default
/// location for all bookmarks added on mobile.
/// Library Panel - Bookmarks section.
internal func openBookmarkEditPanel() {
TelemetryWrapper.recordEvent(
category: .action,
method: .change,
object: .bookmark,
value: .addBookmarkToast
)
if profile.isShutdown { return }
profile.places.getBookmarksTree(
rootGUID: BookmarkRoots.MobileFolderGUID,
recursive: false
).uponQueue(.main) { result in
guard let bookmarkFolder = result.successValue as? BookmarkFolderData,
let bookmarkNode = bookmarkFolder.children?.first as? FxBookmarkNode
else { return }
guard !profile.isShutdown else { return }

// Open refactored bookmark edit view
if isBookmarkRefactorEnabled {
guard let url = tabManager.selectedTab?.url else { return }
profile.places.getBookmarksWithURL(url: url.absoluteString).uponQueue(.main) { result in
guard let bookmarkItem = result.successValue?.first,
let parentGuid = bookmarkItem.parentGUID else { return }
self.profile.places.getBookmark(guid: parentGuid).uponQueue(.main) { result in
guard let parentFolder = result.successValue as? BookmarkFolderData else { return }
let viewModel = EditBookmarkViewModel(parentFolder: parentFolder,
node: bookmarkItem,
profile: self.profile)
let controller = EditBookmarkViewController(viewModel: viewModel,
windowUUID: self.windowUUID)
let navigationController = DismissableNavigationViewController(rootViewController: controller)
self.present(navigationController, animated: true, completion: nil)
}
}
// Open legacy bookmark edit view
} else {
TelemetryWrapper.recordEvent(
category: .action,
method: .change,
object: .bookmark,
value: .addBookmarkToast
)

let detailController = LegacyBookmarkDetailPanel(profile: self.profile,
windowUUID: self.windowUUID,
bookmarkNode: bookmarkNode,
parentBookmarkFolder: bookmarkFolder,
presentedFromToast: true) { [weak self] in
self?.showBookmarkToast(action: .remove)
// Fetch the last added bookmark in the mobile folder, which is the default location for all bookmarks
// added on mobile when the bookmark refactor is not enabled
profile.places.getBookmarksTree(
rootGUID: BookmarkRoots.MobileFolderGUID,
recursive: false
).uponQueue(.main) { result in
guard let bookmarkFolder = result.successValue as? BookmarkFolderData,
let bookmarkNode = bookmarkFolder.children?.first as? FxBookmarkNode
else { return }

let detailController = LegacyBookmarkDetailPanel(profile: self.profile,
windowUUID: self.windowUUID,
bookmarkNode: bookmarkNode,
parentBookmarkFolder: bookmarkFolder,
presentedFromToast: true) { [weak self] in
self?.showBookmarkToast(action: .remove)
}
let controller: DismissableNavigationViewController
controller = DismissableNavigationViewController(rootViewController: detailController)
self.present(controller, animated: true, completion: nil)
}
let controller: DismissableNavigationViewController
controller = DismissableNavigationViewController(rootViewController: detailController)
self.present(controller, animated: true, completion: nil)
}
}

Expand Down
14 changes: 12 additions & 2 deletions firefox-ios/Client/Frontend/Browser/MainMenuActionHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protocol ToolBarActionMenuDelegate: AnyObject {
func showCreditCardSettings()
func showSignInView(fxaParameters: FxASignInViewParameters)
func showFilePicker(fileURL: URL)
func showEditBookmark()
}

extension ToolBarActionMenuDelegate {
Expand Down Expand Up @@ -56,7 +57,8 @@ enum MenuButtonToastAction {
class MainMenuActionHelper: PhotonActionSheetProtocol,
FeatureFlaggable,
CanRemoveQuickActionBookmark,
AppVersionUpdateCheckerProtocol {
AppVersionUpdateCheckerProtocol,
BookmarksRefactorFeatureFlagProvider {
typealias SendToDeviceDelegate = InstructionsViewDelegate & DevicePickerViewControllerDelegate

private let isHomePage: Bool
Expand Down Expand Up @@ -720,7 +722,8 @@ class MainMenuActionHelper: PhotonActionSheetProtocol,
}

private func getBookmarkAction() -> SingleActionViewModel {
return isBookmarked ? getRemoveBookmarkAction() : getAddBookmarkAction()
guard isBookmarked else { return getAddBookmarkAction() }
return isBookmarkRefactorEnabled ? getEditBookmarkAction() : getRemoveBookmarkAction()
}

private func getAddBookmarkAction() -> SingleActionViewModel {
Expand Down Expand Up @@ -764,6 +767,13 @@ class MainMenuActionHelper: PhotonActionSheetProtocol,
}
}

private func getEditBookmarkAction() -> SingleActionViewModel {
return SingleActionViewModel(title: .LegacyAppMenu.EditBookmarkLabel,
iconString: StandardImageIdentifiers.Large.bookmarkFill) { _ in
self.delegate?.showEditBookmark()
}
}

// MARK: Shortcut

private func getShortcutAction() -> PhotonRowActions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class EditBookmarkViewController: UIViewController,
size: CGSize(width: 0, height: UX.bookmarkCellTopPadding)))
view.tableHeaderView = headerSpacerView
}

private lazy var saveBarButton: UIBarButtonItem = {
let button = UIBarButtonItem(
title: String.Bookmarks.Menu.EditBookmarkSave,
style: .done,
target: self,
action: #selector(saveButtonAction)
)
return button
}()

var onViewWillDisappear: (() -> Void)?
var onViewWillAppear: (() -> Void)?
private let viewModel: EditBookmarkViewModel
Expand Down Expand Up @@ -68,6 +79,8 @@ class EditBookmarkViewController: UIViewController,
viewModel.onFolderStatusUpdate = { [weak self] in
self?.tableView.reloadSections(IndexSet(integer: Section.folder.rawValue), with: .automatic)
}

navigationItem.rightBarButtonItem = saveBarButton
// The back button title sometimes doesn't allign with the chevron, force navigation bar layout
navigationController?.navigationBar.layoutIfNeeded()
setupSubviews()
Expand Down Expand Up @@ -95,8 +108,11 @@ class EditBookmarkViewController: UIViewController,
if let isDragging = transitionCoordinator?.isInteractive, !isDragging {
navigationController?.setNavigationBarHidden(true, animated: true)
}
// Save when popping the view off the navigation stack
if isMovingFromParent {
viewModel.saveBookmark()
}
onViewWillDisappear?()
viewModel.saveBookmark()
}

// MARK: - Setup
Expand All @@ -111,6 +127,20 @@ class EditBookmarkViewController: UIViewController,
])
}

// MARK: - Actions

@objc
func saveButtonAction() {
// Check if this is the root view controller so we can save before dismissing
if navigationController?.viewControllers.first == self {
viewModel.saveBookmark()
self.dismiss(animated: true)
} else {
// Save will happen in viewWillDisappear
navigationController?.popViewController(animated: true)
}
}

// MARK: - Themeable

func applyTheme() {
Expand Down

0 comments on commit 3e1fc42

Please sign in to comment.