ServerRuleSection.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // ServerRuleSection.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK on 2022-1-5.
  6. //
  7. import UIKit
  8. import MastodonAsset
  9. import MastodonLocalization
  10. enum ServerRuleSection: Hashable {
  11. case header
  12. case rules
  13. }
  14. extension ServerRuleSection {
  15. static func tableViewDiffableDataSource(
  16. tableView: UITableView
  17. ) -> UITableViewDiffableDataSource<ServerRuleSection, ServerRuleItem> {
  18. return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in
  19. switch item {
  20. case .header(let domain):
  21. let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: OnboardingHeadlineTableViewCell.self), for: indexPath) as! OnboardingHeadlineTableViewCell
  22. cell.titleLabel.text = L10n.Scene.ServerRules.title
  23. cell.subTitleLabel.text = L10n.Scene.ServerRules.subtitle(domain)
  24. return cell
  25. case .rule(let ruleContext):
  26. let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ServerRulesTableViewCell.self), for: indexPath) as! ServerRulesTableViewCell
  27. cell.indexImageView.image = UIImage(systemName: "\(ruleContext.index + 1).circle.fill") ?? UIImage(systemName: "questionmark.circle.fill")
  28. cell.ruleLabel.text = ruleContext.rule.text
  29. return cell
  30. }
  31. }
  32. }
  33. }