2021-02-20 13:23:29 +01:00
|
|
|
//
|
|
|
|
// PickServerViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
2021-02-23 15:14:10 +01:00
|
|
|
// Created by BradGao on 2021/2/20.
|
2021-02-20 13:23:29 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2021-02-23 15:14:10 +01:00
|
|
|
import Combine
|
2021-02-20 13:23:29 +01:00
|
|
|
|
2021-02-23 15:14:10 +01:00
|
|
|
final class PickServerViewController: UIViewController, NeedsDependency {
|
|
|
|
|
|
|
|
private var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
|
|
|
|
var viewModel: PickServerViewModel!
|
|
|
|
|
2021-02-20 13:23:29 +01:00
|
|
|
let titleLabel: UILabel = {
|
|
|
|
let label = UILabel()
|
|
|
|
label.font = .boldSystemFont(ofSize: 34)
|
2021-02-23 08:25:48 +01:00
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
2021-02-23 05:41:56 +01:00
|
|
|
label.text = L10n.Scene.ServerPicker.title
|
2021-02-20 13:23:29 +01:00
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
label.numberOfLines = 0
|
|
|
|
return label
|
|
|
|
}()
|
2021-02-23 15:14:10 +01:00
|
|
|
|
|
|
|
let tableView: UITableView = {
|
|
|
|
let tableView = ControlContainableTableView()
|
|
|
|
tableView.register(PickServerTitleCell.self, forCellReuseIdentifier: String(describing: PickServerTitleCell.self))
|
|
|
|
tableView.register(PickServerCategoriesCell.self, forCellReuseIdentifier: String(describing: PickServerCategoriesCell.self))
|
2021-02-24 15:47:42 +01:00
|
|
|
tableView.register(PickServerSearchCell.self, forCellReuseIdentifier: String(describing: PickServerSearchCell.self))
|
|
|
|
tableView.register(PickServerCell.self, forCellReuseIdentifier: String(describing: PickServerCell.self))
|
2021-02-23 15:14:10 +01:00
|
|
|
tableView.rowHeight = UITableView.automaticDimension
|
|
|
|
tableView.separatorStyle = .none
|
|
|
|
tableView.backgroundColor = .clear
|
|
|
|
|
|
|
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
return tableView
|
|
|
|
}()
|
|
|
|
|
|
|
|
let nextStepButton: PrimaryActionButton = {
|
|
|
|
let button = PrimaryActionButton(type: .system)
|
|
|
|
button.setTitle(L10n.Button.signUp, for: .normal)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
return button
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PickServerViewController {
|
|
|
|
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
|
|
return .darkContent
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
view.backgroundColor = Asset.Colors.Background.onboardingBackground.color
|
|
|
|
|
|
|
|
view.addSubview(nextStepButton)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
nextStepButton.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor, constant: 12),
|
|
|
|
view.readableContentGuide.trailingAnchor.constraint(equalTo: nextStepButton.trailingAnchor, constant: 12),
|
|
|
|
view.bottomAnchor.constraint(equalTo: nextStepButton.bottomAnchor, constant: 34),
|
|
|
|
])
|
|
|
|
|
|
|
|
view.addSubview(tableView)
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
tableView.topAnchor.constraint(equalTo: view.topAnchor),
|
|
|
|
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
|
|
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
|
|
nextStepButton.topAnchor.constraint(equalTo: tableView.bottomAnchor, constant: 7)
|
|
|
|
])
|
|
|
|
|
|
|
|
switch viewModel.mode {
|
|
|
|
case .SignIn:
|
|
|
|
nextStepButton.setTitle(L10n.Common.Controls.Actions.signIn, for: .normal)
|
|
|
|
case .SignUp:
|
|
|
|
nextStepButton.setTitle(L10n.Common.Controls.Actions.continue, for: .normal)
|
|
|
|
}
|
|
|
|
|
2021-02-24 15:47:42 +01:00
|
|
|
viewModel.tableView = tableView
|
2021-02-23 15:14:10 +01:00
|
|
|
tableView.delegate = viewModel
|
|
|
|
tableView.dataSource = viewModel
|
2021-02-24 15:47:42 +01:00
|
|
|
|
|
|
|
viewModel.searchedServers
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { completion in
|
|
|
|
print("22")
|
|
|
|
} receiveValue: { [weak self] servers in
|
|
|
|
self?.tableView.reloadSections(IndexSet(integer: 3), with: .automatic)
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
|
|
|
|
|
|
|
|
viewModel.fetchAllServers()
|
2021-02-23 15:14:10 +01:00
|
|
|
}
|
2021-02-20 13:23:29 +01:00
|
|
|
}
|