Skip to content

Commit

Permalink
Refactor FXIOS-6530 [v122] Library panel clean up (#17385)
Browse files Browse the repository at this point in the history
* Clean up library panel references to extra panel VCs. Not needed anymore

* Fix warning
  • Loading branch information
lmarceau authored Nov 21, 2023
1 parent 71ccced commit 6bb9306
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 59 deletions.
1 change: 0 additions & 1 deletion Client/Coordinators/Library/LibraryCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class LibraryCoordinator: BaseCoordinator, LibraryPanelDelegate, LibraryNavigati

func start(with homepanelSection: Route.HomepanelSection) {
libraryViewController.setupOpenPanel(panelType: homepanelSection.libraryPanel)
libraryViewController.resetHistoryPanelPagination()
}

private func makeChildPanels() -> [UINavigationController] {
Expand Down
21 changes: 1 addition & 20 deletions Client/Frontend/Library/LibraryPanelDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,13 @@ import UIKit

/// Data for identifying and constructing a LibraryPanel.
class LibraryPanelDescriptor {
var viewController: UIViewController?
var navigationController: UINavigationController?

private let profile: Profile
private let tabManager: TabManager

let accessibilityLabel: String
let accessibilityIdentifier: String
let panelType: LibraryPanelType

// Returns latest libraryPanel viewController filtering out "details view controllers" from navigationController
// Handles Bookmarks case where BookmarksPanel is used for main folder and subfolder state
var shownPanel: UIViewController? {
let libraryPanel = navigationController?.viewControllers.filter { $0 is LibraryPanel }
return libraryPanel?.last
}

init(viewController: LibraryPanel?,
profile: Profile,
tabManager: TabManager,
accessibilityLabel: String,
init(accessibilityLabel: String,
accessibilityIdentifier: String,
panelType: LibraryPanelType) {
self.viewController = viewController
self.profile = profile
self.tabManager = tabManager
self.accessibilityLabel = accessibilityLabel
self.accessibilityIdentifier = accessibilityIdentifier
self.panelType = panelType
Expand Down
16 changes: 1 addition & 15 deletions Client/Frontend/Library/LibraryPanelHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,31 @@ enum LibraryPanelType: Int, CaseIterable {

class LibraryPanelHelper {
private let profile: Profile
private let tabManager: TabManager

init(profile: Profile, tabManager: TabManager) {
init(profile: Profile) {
self.profile = profile
self.tabManager = tabManager
}

lazy var enabledPanels: [LibraryPanelDescriptor] = {
let bookmarksViewModel = BookmarksPanelViewModel(profile: profile)

return [
LibraryPanelDescriptor(
viewController: BookmarksPanel(viewModel: bookmarksViewModel),
profile: profile,
tabManager: tabManager,
accessibilityLabel: .LibraryPanelBookmarksAccessibilityLabel,
accessibilityIdentifier: AccessibilityIdentifiers.LibraryPanels.bookmarksView,
panelType: .bookmarks),

LibraryPanelDescriptor(
viewController: HistoryPanel(profile: profile, tabManager: tabManager),
profile: profile,
tabManager: tabManager,
accessibilityLabel: .LibraryPanelHistoryAccessibilityLabel,
accessibilityIdentifier: AccessibilityIdentifiers.LibraryPanels.historyView,
panelType: .history),

LibraryPanelDescriptor(
viewController: DownloadsPanel(),
profile: profile,
tabManager: tabManager,
accessibilityLabel: .LibraryPanelDownloadsAccessibilityLabel,
accessibilityIdentifier: AccessibilityIdentifiers.LibraryPanels.downloadsView,
panelType: .downloads),

LibraryPanelDescriptor(
viewController: ReadingListPanel(profile: profile),
profile: profile,
tabManager: tabManager,
accessibilityLabel: .LibraryPanelReadingListAccessibilityLabel,
accessibilityIdentifier: AccessibilityIdentifiers.LibraryPanels.readingListView,
panelType: .readingList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension LibraryViewController {
guard let navController = children.first as? UINavigationController else { return }

navController.popViewController(animated: true)
var panel = getCurrentPanel()
let panel = getCurrentPanel()
panel?.handleLeftTopButton()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LibraryViewController: UIViewController, Themeable {
notificationCenter: NotificationProtocol = NotificationCenter.default,
themeManager: ThemeManager = AppContainer.shared.resolve(),
logger: Logger = DefaultLogger.shared) {
self.viewModel = LibraryViewModel(withProfile: profile, tabManager: tabManager)
self.viewModel = LibraryViewModel(withProfile: profile)
self.notificationCenter = notificationCenter
self.themeManager = themeManager
self.logger = logger
Expand Down Expand Up @@ -126,10 +126,6 @@ class LibraryViewController: UIViewController, Themeable {
LegacyThemeManager.instance.statusBarStyle
}

func resetHistoryPanelPagination() {
viewModel.resetHistoryPanelPagination()
}

func updateViewWithState() {
setupButtons()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Foundation

class LibraryViewModel {
let profile: Profile
let tabManager: TabManager
let panelDescriptors: [LibraryPanelDescriptor]
var selectedPanel: LibraryPanelType?

Expand All @@ -18,17 +17,8 @@ class LibraryViewModel {
UIImage(named: ImageIdentifiers.libraryReadingList) ?? UIImage()]
}

init(withProfile profile: Profile, tabManager: TabManager) {
init(withProfile profile: Profile) {
self.profile = profile
self.tabManager = tabManager
self.panelDescriptors = LibraryPanelHelper(profile: profile, tabManager: tabManager).enabledPanels
}

func resetHistoryPanelPagination() {
// Reset history panel pagination to get latest history visit
if let historyPanel = panelDescriptors.first(where: { $0.panelType == .history }),
let vcPanel = historyPanel.viewController as? HistoryPanel {
vcPanel.viewModel.shouldResetHistory = true
}
self.panelDescriptors = LibraryPanelHelper(profile: profile).enabledPanels
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import Common
class LibraryViewModelTests: XCTestCase {
private var subject: LibraryViewModel!
private var profile: MockProfile!
private var tabManager: TabManager!

override func setUp() {
super.setUp()

DependencyHelperMock().bootstrapDependencies()
profile = MockProfile(databasePrefix: "historyHighlights_tests")
profile.reopen()
tabManager = TabManagerImplementation(profile: profile, imageStore: nil)
LegacyFeatureFlagsManager.shared.initializeDeveloperFeatures(with: profile)
}

Expand All @@ -26,18 +24,17 @@ class LibraryViewModelTests: XCTestCase {
AppContainer.shared.reset()
profile.shutdown()
profile = nil
tabManager = nil
}

func testInitialState_Init() {
subject = LibraryViewModel(withProfile: profile, tabManager: tabManager)
subject = LibraryViewModel(withProfile: profile)
subject.selectedPanel = .bookmarks

XCTAssertEqual(subject.panelDescriptors.count, 4)
}

func testLibraryPanelTitle() {
subject = LibraryViewModel(withProfile: profile, tabManager: tabManager)
subject = LibraryViewModel(withProfile: profile)
subject.selectedPanel = .bookmarks

for panel in subject.panelDescriptors {
Expand Down

0 comments on commit 6bb9306

Please sign in to comment.