2021-02-22 09:20:44 +01:00
|
|
|
//
|
|
|
|
// MastodonServerRulesViewController.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-2-22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
2021-02-26 11:27:47 +01:00
|
|
|
import Combine
|
2021-03-30 08:31:52 +02:00
|
|
|
import MastodonSDK
|
|
|
|
import SafariServices
|
2021-08-04 08:59:42 +02:00
|
|
|
import MetaTextKit
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonAsset
|
2022-10-08 07:43:06 +02:00
|
|
|
import MastodonCore
|
2022-01-27 14:23:39 +01:00
|
|
|
import MastodonLocalization
|
2021-02-22 09:20:44 +01:00
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
final class MastodonServerRulesViewController: UIViewController, NeedsDependency {
|
2021-02-22 09:20:44 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
let logger = Logger(subsystem: "MastodonServerRulesViewController", category: "ViewController")
|
2021-02-26 11:27:47 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
private var observations = Set<NSKeyValueObservation>()
|
|
|
|
|
2021-02-22 09:20:44 +01:00
|
|
|
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
|
|
|
|
|
|
|
var viewModel: MastodonServerRulesViewModel!
|
2022-12-11 23:57:58 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
let tableView: UITableView = {
|
2022-12-15 22:24:43 +01:00
|
|
|
let tableView = UITableView(frame: .zero, style: .insetGrouped)
|
2022-01-05 08:11:35 +01:00
|
|
|
tableView.register(ServerRulesTableViewCell.self, forCellReuseIdentifier: String(describing: ServerRulesTableViewCell.self))
|
|
|
|
tableView.rowHeight = UITableView.automaticDimension
|
|
|
|
tableView.keyboardDismissMode = .onDrag
|
2022-12-17 20:26:20 +01:00
|
|
|
tableView.sectionHeaderTopPadding = 0
|
2022-01-05 08:11:35 +01:00
|
|
|
return tableView
|
2021-02-22 09:20:44 +01:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
extension MastodonServerRulesViewController {
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2021-02-26 12:52:58 +01:00
|
|
|
setupOnboardingAppearance()
|
|
|
|
defer { setupNavigationBarBackgroundView() }
|
2021-02-22 09:20:44 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
view.addSubview(tableView)
|
2022-11-17 17:45:27 +01:00
|
|
|
tableView.pinToParent()
|
2022-12-11 23:57:58 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
tableView.delegate = self
|
|
|
|
viewModel.setupDiffableDataSource(tableView: tableView)
|
2021-02-22 09:20:44 +01:00
|
|
|
|
2022-12-17 19:50:40 +01:00
|
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(title: L10n.Scene.ServerRules.Button.confirm, style: .done, target: self, action: #selector(MastodonServerRulesViewController.nextButtonPressed(_:)))
|
2022-12-11 23:57:58 +01:00
|
|
|
title = L10n.Scene.ServerRules.title
|
2021-02-26 12:52:58 +01:00
|
|
|
}
|
|
|
|
|
2021-09-27 10:30:36 +02:00
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
tableView.flashScrollIndicators()
|
2021-10-08 12:10:06 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 12:52:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension MastodonServerRulesViewController {
|
2022-01-05 08:11:35 +01:00
|
|
|
@objc private func backButtonPressed(_ sender: UIButton) {
|
|
|
|
navigationController?.popViewController(animated: true)
|
2021-03-30 08:31:52 +02:00
|
|
|
}
|
2022-12-16 21:30:21 +01:00
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
@objc private func nextButtonPressed(_ sender: UIButton) {
|
2022-12-16 23:35:09 +01:00
|
|
|
let domain = viewModel.domain
|
|
|
|
let viewModel = PrivacyViewModel(domain: domain, authenticateInfo: viewModel.authenticateInfo, rows: [.iOSApp, .server(domain: domain)], instance: viewModel.instance, applicationToken: viewModel.applicationToken)
|
|
|
|
|
|
|
|
_ = coordinator.present(scene: .mastodonPrivacyPolicies(viewModel: viewModel), from: self, transition: .show)
|
2021-02-22 09:20:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 09:43:59 +01:00
|
|
|
// MARK: - OnboardingViewControllerAppearance
|
|
|
|
extension MastodonServerRulesViewController: OnboardingViewControllerAppearance { }
|
|
|
|
|
2022-01-05 08:11:35 +01:00
|
|
|
// MARK: - UITableViewDelegate
|
|
|
|
extension MastodonServerRulesViewController: UITableViewDelegate {
|
|
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
2022-12-17 20:14:27 +01:00
|
|
|
let wrapper = UIView()
|
|
|
|
|
|
|
|
let label = UILabel()
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
label.font = MastodonPickServerViewController.subTitleFont
|
|
|
|
label.textColor = Asset.Colors.Label.primary.color
|
|
|
|
label.adjustsFontForContentSizeCategory = true
|
|
|
|
label.numberOfLines = 0
|
|
|
|
label.text = L10n.Scene.ServerRules.subtitle(viewModel.domain)
|
|
|
|
wrapper.addSubview(label)
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
label.topAnchor.constraint(equalTo: wrapper.topAnchor, constant: 16),
|
|
|
|
label.leadingAnchor.constraint(equalTo: wrapper.leadingAnchor),
|
|
|
|
wrapper.trailingAnchor.constraint(equalTo: label.trailingAnchor),
|
|
|
|
wrapper.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 16),
|
|
|
|
])
|
|
|
|
|
|
|
|
return wrapper
|
2021-02-22 09:20:44 +01:00
|
|
|
}
|
|
|
|
}
|