2021-04-21 08:46:31 +02:00
|
|
|
//
|
|
|
|
// SuggestionAccountViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Foundation
|
|
|
|
import UIKit
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-10-10 13:14:52 +02:00
|
|
|
import MastodonUI
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonLocalization
|
2021-04-21 08:46:31 +02:00
|
|
|
|
|
|
|
class SuggestionAccountViewController: UIViewController, NeedsDependency {
|
2023-05-12 21:04:47 +02:00
|
|
|
|
2021-04-21 08:46:31 +02:00
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
2021-04-21 11:58:56 +02:00
|
|
|
|
2021-04-21 08:46:31 +02:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
var viewModel: SuggestionAccountViewModel!
|
2021-04-21 11:58:56 +02:00
|
|
|
|
2021-04-21 08:46:31 +02:00
|
|
|
let tableView: UITableView = {
|
2023-05-12 22:06:44 +02:00
|
|
|
let tableView = UITableView(frame: .zero, style: .insetGrouped)
|
2023-05-19 14:51:22 +02:00
|
|
|
tableView.register(SuggestionAccountTableViewCell.self, forCellReuseIdentifier: SuggestionAccountTableViewCell.reuseIdentifier)
|
|
|
|
// we're lazy, that's why we don't put the Footer in tableViewFooter
|
|
|
|
tableView.register(SuggestionAccountTableViewFooter.self, forHeaderFooterViewReuseIdentifier: SuggestionAccountTableViewFooter.reuseIdentifier)
|
2023-05-19 16:34:21 +02:00
|
|
|
tableView.contentInset.top = 16
|
2021-04-21 08:46:31 +02:00
|
|
|
return tableView
|
|
|
|
}()
|
2021-04-21 11:58:56 +02:00
|
|
|
|
2021-04-21 08:46:31 +02:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2022-01-27 14:23:39 +01:00
|
|
|
|
2023-05-23 12:36:23 +02:00
|
|
|
setupNavigationBarAppearance()
|
|
|
|
defer { setupNavigationBarBackgroundView() }
|
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
title = L10n.Scene.SuggestionAccount.title
|
|
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
|
|
|
barButtonSystemItem: UIBarButtonItem.SystemItem.done,
|
|
|
|
target: self,
|
|
|
|
action: #selector(SuggestionAccountViewController.doneButtonDidClick(_:))
|
|
|
|
)
|
2021-04-21 11:58:56 +02:00
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(tableView)
|
2021-04-21 08:46:31 +02:00
|
|
|
NSLayoutConstraint.activate([
|
2023-05-12 22:06:44 +02:00
|
|
|
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
2022-02-10 12:30:41 +01:00
|
|
|
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
|
|
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
|
|
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
2021-04-21 08:46:31 +02:00
|
|
|
])
|
2022-02-10 12:30:41 +01:00
|
|
|
|
|
|
|
tableView.delegate = self
|
|
|
|
viewModel.setupDiffableDataSource(
|
|
|
|
tableView: tableView,
|
|
|
|
suggestionAccountTableViewCellDelegate: self
|
|
|
|
)
|
2023-05-12 22:06:44 +02:00
|
|
|
|
|
|
|
view.backgroundColor = .secondarySystemBackground
|
|
|
|
tableView.backgroundColor = .secondarySystemBackground
|
2022-02-10 12:30:41 +01:00
|
|
|
}
|
2021-04-22 13:58:42 +02:00
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
2023-05-23 12:28:00 +02:00
|
|
|
|
|
|
|
navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
|
navigationItem.largeTitleDisplayMode = .automatic
|
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
tableView.deselectRow(with: transitionCoordinator, animated: animated)
|
2023-11-13 15:48:45 +01:00
|
|
|
|
|
|
|
viewModel.updateSuggestions()
|
2021-04-22 13:58:42 +02:00
|
|
|
}
|
2023-05-22 11:41:42 +02:00
|
|
|
|
|
|
|
//MARK: - Actions
|
|
|
|
|
|
|
|
@objc func doneButtonDidClick(_ sender: UIButton) {
|
2023-05-23 13:13:34 +02:00
|
|
|
viewModel.delegate?.homeTimelineNeedRefresh.send()
|
2023-05-22 11:41:42 +02:00
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
2021-04-22 13:58:42 +02:00
|
|
|
}
|
2021-04-21 11:58:56 +02:00
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
// MARK: - UITableViewDelegate
|
2021-04-22 13:58:42 +02:00
|
|
|
extension SuggestionAccountViewController: UITableViewDelegate {
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
2023-11-13 14:44:26 +01:00
|
|
|
|
2022-02-10 12:30:41 +01:00
|
|
|
guard let tableViewDiffableDataSource = viewModel.tableViewDiffableDataSource else { return }
|
|
|
|
guard let item = tableViewDiffableDataSource.itemIdentifier(for: indexPath) else { return }
|
|
|
|
switch item {
|
2023-11-13 14:44:26 +01:00
|
|
|
case .account(let account, _):
|
2023-11-13 14:55:42 +01:00
|
|
|
Task { await DataSourceFacade.coordinateToProfileScene(provider: self, account: account) }
|
2021-04-22 13:58:42 +02:00
|
|
|
}
|
2023-11-13 14:44:26 +01:00
|
|
|
|
|
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
2021-04-21 08:46:31 +02:00
|
|
|
}
|
2023-05-19 14:51:22 +02:00
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
|
|
guard let footerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: SuggestionAccountTableViewFooter.reuseIdentifier) as? SuggestionAccountTableViewFooter else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-13 14:44:26 +01:00
|
|
|
footerView.followAllButton.isEnabled = viewModel.accounts.isNotEmpty
|
2023-09-26 14:26:16 +02:00
|
|
|
|
2023-05-19 14:51:22 +02:00
|
|
|
footerView.delegate = self
|
|
|
|
return footerView
|
|
|
|
}
|
2021-04-21 08:46:31 +02:00
|
|
|
}
|
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
// MARK: - AuthContextProvider
|
|
|
|
extension SuggestionAccountViewController: AuthContextProvider {
|
|
|
|
var authContext: AuthContext { viewModel.authContext }
|
|
|
|
}
|
|
|
|
|
2023-05-22 11:41:42 +02:00
|
|
|
// MARK: - UserTableViewCellDelegate
|
|
|
|
extension SuggestionAccountViewController: UserTableViewCellDelegate {}
|
|
|
|
|
2022-10-09 14:07:57 +02:00
|
|
|
// MARK: - SuggestionAccountTableViewCellDelegate
|
2023-05-22 11:41:42 +02:00
|
|
|
extension SuggestionAccountViewController: SuggestionAccountTableViewCellDelegate { }
|
2021-04-21 08:46:31 +02:00
|
|
|
|
2023-05-19 14:51:22 +02:00
|
|
|
|
|
|
|
extension SuggestionAccountViewController: SuggestionAccountTableViewFooterDelegate {
|
|
|
|
func followAll(_ footerView: SuggestionAccountTableViewFooter) {
|
2023-11-13 15:48:45 +01:00
|
|
|
viewModel.followAllSuggestedAccounts(self, presentedOn: self.navigationController) {
|
2023-05-25 15:31:03 +02:00
|
|
|
DispatchQueue.main.async {
|
2023-11-13 15:48:45 +01:00
|
|
|
self.coordinator.hideLoading(on: self.navigationController)
|
2023-05-23 12:55:24 +02:00
|
|
|
self.dismiss(animated: true)
|
|
|
|
}
|
|
|
|
}
|
2023-05-19 14:51:22 +02:00
|
|
|
}
|
|
|
|
}
|
2023-05-23 12:36:23 +02:00
|
|
|
|
|
|
|
extension SuggestionAccountViewController: OnboardingViewControllerAppearance { }
|