Skip to content

Commit

Permalink
Add FXIOS-9766 [Bookmarks Evolution] Update Bookmarks Panel View Edit…
Browse files Browse the repository at this point in the history
… Mode Part 1 (#23676)

* Completed Ticket

* Quick reversion'

* Feature flagged segment control status update on edit

* Swiftlint Fix

* Addressed Comments

* Fixed Swiftlint Violations
  • Loading branch information
DanielDervishi authored Dec 19, 2024
1 parent 15d1f4f commit b19f3e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,6 +132,7 @@ class LibraryViewController: UIViewController, Themeable {

func updateViewWithState() {
setupButtons()
updateSegmentControl()
}

fileprivate func updateTitle() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -361,6 +379,7 @@ extension LibraryViewController: Notifiable {
switch notification.name {
case .LibraryPanelStateDidChange:
setupButtons()
updateSegmentControl()
default: break
}
}
Expand Down

0 comments on commit b19f3e3

Please sign in to comment.