Skip to content

Commit

Permalink
Refactor FXIOS-7301 - Remove 1 closure_body_length violation from His…
Browse files Browse the repository at this point in the history
…toryPanel.swift (#21974)
  • Loading branch information
ionixjunior authored Sep 16, 2024
1 parent 0f7e939 commit 7828a7c
Showing 1 changed file with 51 additions and 38 deletions.
89 changes: 51 additions & 38 deletions firefox-ios/Client/Frontend/Library/HistoryPanel/HistoryPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,60 +364,43 @@ 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<Site> {
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!
return UITableViewCell()
}
}

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
Expand All @@ -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
Expand All @@ -452,6 +450,21 @@ class HistoryPanel: UIViewController,
return cell
}

private func getGroupCell(searchTermGroup: ASGroup<Site>, 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<Site>,
_ cell: TwoLineImageOverlayCell
Expand Down

0 comments on commit 7828a7c

Please sign in to comment.