RebloggedByViewController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // RebloggedByViewController.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK on 2022-5-17.
  6. //
  7. import os.log
  8. import UIKit
  9. import GameplayKit
  10. import Combine
  11. import MastodonCore
  12. import MastodonLocalization
  13. final class RebloggedByViewController: UIViewController, NeedsDependency {
  14. let logger = Logger(subsystem: "RebloggedByViewController", category: "ViewController")
  15. weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
  16. weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
  17. var disposeBag = Set<AnyCancellable>()
  18. var viewModel: UserListViewModel!
  19. lazy var tableView: UITableView = {
  20. let tableView = UITableView()
  21. tableView.rowHeight = UITableView.automaticDimension
  22. tableView.separatorStyle = .none
  23. tableView.backgroundColor = .clear
  24. return tableView
  25. }()
  26. deinit {
  27. os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
  28. }
  29. }
  30. extension RebloggedByViewController {
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33. #if DEBUG
  34. switch viewModel.kind {
  35. case .rebloggedBy: break
  36. default: assertionFailure()
  37. }
  38. #endif
  39. title = L10n.Scene.RebloggedBy.title
  40. view.backgroundColor = ThemeService.shared.currentTheme.value.secondarySystemBackgroundColor
  41. ThemeService.shared.currentTheme
  42. .receive(on: DispatchQueue.main)
  43. .sink { [weak self] theme in
  44. guard let self = self else { return }
  45. self.view.backgroundColor = theme.secondarySystemBackgroundColor
  46. }
  47. .store(in: &disposeBag)
  48. tableView.translatesAutoresizingMaskIntoConstraints = false
  49. view.addSubview(tableView)
  50. NSLayoutConstraint.activate([
  51. tableView.topAnchor.constraint(equalTo: view.topAnchor),
  52. tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  53. tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
  54. tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  55. ])
  56. tableView.delegate = self
  57. viewModel.setupDiffableDataSource(
  58. tableView: tableView,
  59. userTableViewCellDelegate: self
  60. )
  61. // setup batch fetch
  62. viewModel.listBatchFetchViewModel.setup(scrollView: tableView)
  63. viewModel.listBatchFetchViewModel.shouldFetch
  64. .receive(on: DispatchQueue.main)
  65. .sink { [weak self] _ in
  66. guard let self = self else { return }
  67. self.viewModel.stateMachine.enter(UserListViewModel.State.Loading.self)
  68. }
  69. .store(in: &disposeBag)
  70. }
  71. override func viewWillAppear(_ animated: Bool) {
  72. super.viewWillAppear(animated)
  73. tableView.deselectRow(with: transitionCoordinator, animated: animated)
  74. }
  75. }
  76. // MARK: - AuthContextProvider
  77. extension RebloggedByViewController: AuthContextProvider {
  78. var authContext: AuthContext { viewModel.authContext }
  79. }
  80. // MARK: - UITableViewDelegate
  81. extension RebloggedByViewController: UITableViewDelegate, AutoGenerateTableViewDelegate {
  82. // sourcery:inline:RebloggedByViewController.AutoGenerateTableViewDelegate
  83. // Generated using Sourcery
  84. // DO NOT EDIT
  85. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  86. aspectTableView(tableView, didSelectRowAt: indexPath)
  87. }
  88. // sourcery:end
  89. }
  90. // MARK: - UserTableViewCellDelegate
  91. extension RebloggedByViewController: UserTableViewCellDelegate { }