Files
comaps/iphone/Maps/Bookmarks/BookmarksList/Cells/BookmarksListCellStrategy.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

59 lines
2.5 KiB
Swift

final class BookmarksListCellStrategy {
private enum CellId {
static let listItem = "BookmarksListCell"
static let subgroup = "SubgroupCell"
static let sectionHeader = "SectionHeader"
}
typealias CheckHandlerClosure = (IBookmarksListSectionViewModel, Int, Bool) -> Void
var cellCheckHandler: CheckHandlerClosure?
typealias VisibilityHandlerClosure = (IBookmarksListSectionViewModel) -> Void
var cellVisibilityHandler: VisibilityHandlerClosure?
func registerCells(_ tableView: UITableView) {
tableView.register(UINib(nibName: "BookmarksListCell", bundle: nil), forCellReuseIdentifier: CellId.listItem)
tableView.register(UINib(nibName: "SubgroupCell", bundle: nil), forCellReuseIdentifier: CellId.subgroup)
tableView.register(UINib(nibName: "BookmarksListSectionHeader", bundle: nil),
forHeaderFooterViewReuseIdentifier: CellId.sectionHeader)
}
func tableCell(_ tableView: UITableView,
for viewModel: IBookmarksListSectionViewModel,
at indexPath: IndexPath) -> UITableViewCell {
switch viewModel {
case let bookmarksSection as IBookmarksSectionViewModel:
let bookmark = bookmarksSection.bookmarks[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: CellId.listItem, for: indexPath) as! BookmarksListCell
cell.config(bookmark)
return cell
case let tracksSection as ITracksSectionViewModel:
let track = tracksSection.tracks[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: CellId.listItem, for: indexPath) as! BookmarksListCell
cell.config(track)
return cell
case let subgroupsSection as ISubgroupsSectionViewModel:
let subgroup = subgroupsSection.subgroups[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: CellId.subgroup, for: indexPath) as! SubgroupCell
cell.config(subgroup)
cell.checkHandler = { [weak self] checked in
self?.cellCheckHandler?(viewModel, indexPath.row, checked)
}
return cell
default:
fatalError("Unexpected item")
}
}
func headerView(_ tableView: UITableView,
for viewModel: IBookmarksListSectionViewModel) -> UITableViewHeaderFooterView {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: CellId.sectionHeader)
as! BookmarksListSectionHeader
headerView.config(viewModel)
headerView.visibilityHandler = { [weak self] in
self?.cellVisibilityHandler?(viewModel)
}
return headerView
}
}