From 7828a7c19308c6978332b9cd9bcd2b93a5de783c Mon Sep 17 00:00:00 2001 From: Ione Souza Junior Date: Mon, 16 Sep 2024 20:33:21 -0300 Subject: [PATCH] Refactor FXIOS-7301 - Remove 1 closure_body_length violation from HistoryPanel.swift (#21974) --- .../Library/HistoryPanel/HistoryPanel.swift | 89 +++++++++++-------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/firefox-ios/Client/Frontend/Library/HistoryPanel/HistoryPanel.swift b/firefox-ios/Client/Frontend/Library/HistoryPanel/HistoryPanel.swift index e8ecc679891a..70f80714428d 100644 --- a/firefox-ios/Client/Frontend/Library/HistoryPanel/HistoryPanel.swift +++ b/firefox-ios/Client/Frontend/Library/HistoryPanel/HistoryPanel.swift @@ -364,53 +364,19 @@ class HistoryPanel: UIViewController, HistoryPanelSections, AnyHashable >(tableView: tableView) { [weak self] (tableView, indexPath, item) -> UITableViewCell? in - guard let self = self else { return nil } + guard let self else { return nil } if var historyActionable = item as? HistoryActionablesModel { historyActionable.configureImage(for: windowUUID) - guard let cell = tableView.dequeueReusableCell( - withIdentifier: OneLineTableViewCell.cellIdentifier, - for: indexPath - ) as? OneLineTableViewCell - else { - self.logger.log("History Panel - cannot create OneLineTableViewCell for historyActionable", - level: .debug, - category: .library) - return nil - } - - let actionableCell = self.configureHistoryActionableCell(historyActionable, cell) - return actionableCell + return getHistoryActionableCell(historyActionable: historyActionable, indexPath: indexPath) } if let site = item as? Site { - guard let cell = tableView.dequeueReusableCell( - withIdentifier: TwoLineImageOverlayCell.accessoryUsageReuseIdentifier, - for: indexPath - ) as? TwoLineImageOverlayCell else { - self.logger.log("History Panel - cannot create TwoLineImageOverlayCell for site", - level: .debug, - category: .library) - return nil - } - - let siteCell = self.configureSiteCell(site, cell) - return siteCell + return getSiteCell(site: site, indexPath: indexPath) } if let searchTermGroup = item as? ASGroup { - guard let cell = tableView.dequeueReusableCell( - withIdentifier: TwoLineImageOverlayCell.cellIdentifier, - for: indexPath - ) as? TwoLineImageOverlayCell else { - self.logger.log("History Panel - cannot create TwoLineImageOverlayCell for STG", - level: .debug, - category: .library) - return nil - } - - let asGroupCell = self.configureASGroupCell(searchTermGroup, cell) - return asGroupCell + return getGroupCell(searchTermGroup: searchTermGroup, indexPath: indexPath) } // This should never happen! You will have an empty row! @@ -418,6 +384,23 @@ class HistoryPanel: UIViewController, } } + private func getHistoryActionableCell(historyActionable: HistoryActionablesModel, + indexPath: IndexPath) -> UITableViewCell? { + guard let cell = tableView.dequeueReusableCell( + withIdentifier: OneLineTableViewCell.cellIdentifier, + for: indexPath + ) as? OneLineTableViewCell + else { + logger.log("History Panel - cannot create OneLineTableViewCell for historyActionable", + level: .debug, + category: .library) + return nil + } + + let actionableCell = configureHistoryActionableCell(historyActionable, cell) + return actionableCell + } + private func configureHistoryActionableCell( _ historyActionable: HistoryActionablesModel, _ cell: OneLineTableViewCell @@ -436,6 +419,21 @@ class HistoryPanel: UIViewController, return cell } + private func getSiteCell(site: Site, indexPath: IndexPath) -> UITableViewCell? { + guard let cell = tableView.dequeueReusableCell( + withIdentifier: TwoLineImageOverlayCell.accessoryUsageReuseIdentifier, + for: indexPath + ) as? TwoLineImageOverlayCell else { + logger.log("History Panel - cannot create TwoLineImageOverlayCell for site", + level: .debug, + category: .library) + return nil + } + + let siteCell = configureSiteCell(site, cell) + return siteCell + } + private func configureSiteCell( _ site: Site, _ cell: TwoLineImageOverlayCell @@ -452,6 +450,21 @@ class HistoryPanel: UIViewController, return cell } + private func getGroupCell(searchTermGroup: ASGroup, indexPath: IndexPath) -> UITableViewCell? { + guard let cell = tableView.dequeueReusableCell( + withIdentifier: TwoLineImageOverlayCell.cellIdentifier, + for: indexPath + ) as? TwoLineImageOverlayCell else { + logger.log("History Panel - cannot create TwoLineImageOverlayCell for Search Term Group", + level: .debug, + category: .library) + return nil + } + + let asGroupCell = configureASGroupCell(searchTermGroup, cell) + return asGroupCell + } + private func configureASGroupCell( _ asGroup: ASGroup, _ cell: TwoLineImageOverlayCell