Show privacy-policies, connect screens (#690)

This commit is contained in:
Nathan Mattes 2022-12-16 23:35:09 +01:00
parent c595929c54
commit 7d63eeccaf
5 changed files with 114 additions and 16 deletions

View File

@ -112,6 +112,7 @@
C24C97032922F30500BAE8CB /* RefreshControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = C24C97022922F30500BAE8CB /* RefreshControl.swift */; };
D8099078294BC8A30050219F /* PrivacyTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8099077294BC8A30050219F /* PrivacyTableViewController.swift */; };
D809907A294BC9390050219F /* PrivacyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8099079294BC9390050219F /* PrivacyTableViewCell.swift */; };
D809907C294D25510050219F /* PrivacyViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D809907B294D25510050219F /* PrivacyViewModel.swift */; };
D8363B1629469CE200A74079 /* OnboardingNextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8363B1529469CE200A74079 /* OnboardingNextView.swift */; };
D87BFC8B291D5C6B00FEE264 /* MastodonLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */; };
D87BFC8D291EB81200FEE264 /* MastodonLoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8C291EB81200FEE264 /* MastodonLoginViewModel.swift */; };
@ -663,6 +664,7 @@
D7D7CF93E262178800077512 /* Pods-Mastodon-AppShared.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-AppShared.debug.xcconfig"; path = "Target Support Files/Pods-Mastodon-AppShared/Pods-Mastodon-AppShared.debug.xcconfig"; sourceTree = "<group>"; };
D8099077294BC8A30050219F /* PrivacyTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyTableViewController.swift; sourceTree = "<group>"; };
D8099079294BC9390050219F /* PrivacyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyTableViewCell.swift; sourceTree = "<group>"; };
D809907B294D25510050219F /* PrivacyViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyViewModel.swift; sourceTree = "<group>"; };
D8363B1529469CE200A74079 /* OnboardingNextView.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = OnboardingNextView.swift; sourceTree = "<group>"; tabWidth = 4; };
D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonLoginView.swift; sourceTree = "<group>"; };
D87BFC8C291EB81200FEE264 /* MastodonLoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonLoginViewModel.swift; sourceTree = "<group>"; };
@ -1591,6 +1593,7 @@
children = (
D8099077294BC8A30050219F /* PrivacyTableViewController.swift */,
D8099079294BC9390050219F /* PrivacyTableViewCell.swift */,
D809907B294D25510050219F /* PrivacyViewModel.swift */,
);
path = Privacy;
sourceTree = "<group>";
@ -3537,6 +3540,7 @@
DB1FD45025F26FA1004CFCFC /* MastodonPickServerViewModel+Diffable.swift in Sources */,
DB4F097D26A03A5B00D62E92 /* SearchHistoryItem.swift in Sources */,
DBD5B1FA27BD013700BD6B38 /* DataSourceProvider+StatusTableViewControllerNavigateable.swift in Sources */,
D809907C294D25510050219F /* PrivacyViewModel.swift in Sources */,
DB5B549A2833A60400DEF8B2 /* FamiliarFollowersViewController.swift in Sources */,
DB3E6FE22806A50100B035AE /* DiscoveryHashtagsViewModel+Diffable.swift in Sources */,
DB427DD625BAA00100D1B89D /* AppDelegate.swift in Sources */,

View File

@ -145,7 +145,7 @@ extension SceneCoordinator {
case welcome
case mastodonPickServer(viewMode: MastodonPickServerViewModel)
case mastodonRegister(viewModel: MastodonRegisterViewModel)
case mastodonPrivacyPolicies
case mastodonPrivacyPolicies(viewModel: PrivacyViewModel)
case mastodonServerRules(viewModel: MastodonServerRulesViewModel)
case mastodonConfirmEmail(viewModel: MastodonConfirmEmailViewModel)
case mastodonResendEmail(viewModel: MastodonResendEmailViewModel)
@ -414,8 +414,8 @@ private extension SceneCoordinator {
loginViewController.delegate = self
viewController = loginViewController
case .mastodonPrivacyPolicies:
let privacyViewController = PrivacyTableViewController(context: appContext, coordinator: self)
case .mastodonPrivacyPolicies(let viewModel):
let privacyViewController = PrivacyTableViewController(context: appContext, coordinator: self, viewModel: viewModel)
viewController = privacyViewController
case .mastodonResendEmail(let viewModel):
let _viewController = MastodonResendEmailViewController()

View File

@ -8,9 +8,30 @@
import UIKit
import MastodonCore
import MastodonSDK
import SafariServices
// https://joinmastodon.org/ios/privacy
// "\(server.domain)/privacy-policy"
enum PrivacyRow {
case iOSApp
case server(domain: String)
var url: URL? {
switch self {
case .iOSApp:
return URL(string: "https://joinmastodon.org/ios/privacy")
case .server(let domain):
return URL(string: "https://\(domain)/privacy-policy")
}
}
var title: String {
switch self {
case .iOSApp:
return "Privacy Policy - Mastodon for iOS"
case .server(let domain):
return "Privacy Policy - \(domain)"
}
}
}
class PrivacyTableViewController: UIViewController, NeedsDependency {
@ -18,22 +39,29 @@ class PrivacyTableViewController: UIViewController, NeedsDependency {
var coordinator: SceneCoordinator!
private let tableView: UITableView
let viewModel: PrivacyViewModel
init(context: AppContext, coordinator: SceneCoordinator, server: Mastodon.Entity.Server) {
init(context: AppContext, coordinator: SceneCoordinator, viewModel: PrivacyViewModel) {
self.context = context
self.coordinator = coordinator
self.viewModel = viewModel
tableView = UITableView(frame: .zero, style: .insetGrouped)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(PrivacyTableViewCell.self, forCellReuseIdentifier: PrivacyTableViewCell.reuseIdentifier)
tableView.register(OnboardingHeadlineTableViewCell.self, forCellReuseIdentifier: OnboardingHeadlineTableViewCell.reuseIdentifier)
super.init(nibName: nil, bundle: nil)
tableView.delegate = self
tableView.dataSource = self
view.addSubview(tableView)
setupConstraints()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "I agree", style: .done, target: self, action: #selector(PrivacyTableViewController.nextButtonPressed(_:)))
}
required init?(coder: NSCoder) { fatalError("init(coder:) won't been implemented, please don't use Storyboards.") }
@ -54,13 +82,43 @@ class PrivacyTableViewController: UIViewController, NeedsDependency {
}
@objc private func nextButtonPressed(_ sender: UIButton) {
// let viewModel = MastodonRegisterViewModel(
// context: context,
// domain: viewModel.domain,
// authenticateInfo: viewModel.authenticateInfo,
// instance: viewModel.instance,
// applicationToken: viewModel.applicationToken
// )
// _ = coordinator.present(scene: .mastodonRegister(viewModel: viewModel), from: self, transition: .show)
let viewModel = MastodonRegisterViewModel(
context: context,
domain: viewModel.domain,
authenticateInfo: viewModel.authenticateInfo,
instance: viewModel.instance,
applicationToken: viewModel.applicationToken
)
_ = coordinator.present(scene: .mastodonRegister(viewModel: viewModel), from: self, transition: .show)
}
}
extension PrivacyTableViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.rows.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: PrivacyTableViewCell.reuseIdentifier, for: indexPath) as? PrivacyTableViewCell else { fatalError("Wrong cell?") }
let row = viewModel.rows[indexPath.row]
var contentConfiguration = cell.defaultContentConfiguration()
contentConfiguration.text = row.title
cell.contentConfiguration = contentConfiguration
return cell
}
}
extension PrivacyTableViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let row = viewModel.rows[indexPath.row]
guard let url = row.url else { return }
_ = coordinator.present(scene: .safari(url: url), from: self, transition: .safariPresent(animated: true))
}
}

View File

@ -0,0 +1,33 @@
//
// PrivacyViewModel.swift
// Mastodon
//
// Created by Nathan Mattes on 16.12.22.
//
import Foundation
import MastodonSDK
final class PrivacyViewModel {
// input
let domain: String
let authenticateInfo: AuthenticationViewModel.AuthenticateInfo
let rows: [PrivacyRow]
let instance: Mastodon.Entity.Instance
let applicationToken: Mastodon.Entity.Token
init(
domain: String,
authenticateInfo: AuthenticationViewModel.AuthenticateInfo,
rows: [PrivacyRow],
instance: Mastodon.Entity.Instance,
applicationToken: Mastodon.Entity.Token
) {
self.domain = domain
self.authenticateInfo = authenticateInfo
self.rows = rows
self.instance = instance
self.applicationToken = applicationToken
}
}

View File

@ -73,7 +73,10 @@ extension MastodonServerRulesViewController {
}
@objc private func nextButtonPressed(_ sender: UIButton) {
_ = coordinator.present(scene: .mastodonPrivacyPolicies, from: self, transition: .show)
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)
}
}