From afd90d62e848e5df7b7338dd2d689e96a48e82e0 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 27 Sep 2023 22:32:22 +0200 Subject: [PATCH] Add settings-entry for server-details (IOS-14, IOS-20) --- .../input/Base.lproj/app.json | 1 + .../StringsConvertor/input/en.lproj/app.json | 1 + Localization/app.json | 1 + Mastodon.xcodeproj/project.pbxproj | 12 +++ .../ServerDetailsViewController.swift | 20 +++++ .../Settings/Settings Overview/Settings.swift | 76 +++++++++++-------- .../SettingsTableViewCell.swift | 25 +++++- .../SettingsViewController.swift | 4 +- .../Scene/Settings/SettingsCoordinator.swift | 13 +++- .../Generated/Strings.swift | 2 + .../Resources/Base.lproj/Localizable.strings | 1 + .../Resources/en.lproj/Localizable.strings | 1 + 12 files changed, 119 insertions(+), 38 deletions(-) create mode 100644 Mastodon/Scene/Settings/Server Details/ServerDetailsViewController.swift diff --git a/Localization/StringsConvertor/input/Base.lproj/app.json b/Localization/StringsConvertor/input/Base.lproj/app.json index b57f0f4e4..30630361f 100644 --- a/Localization/StringsConvertor/input/Base.lproj/app.json +++ b/Localization/StringsConvertor/input/Base.lproj/app.json @@ -715,6 +715,7 @@ "notifications": "Notifications", "support_mastodon": "Support Mastodon", "about_mastodon": "About Mastodon", + "server_details": "Server Details", "logout": "Logout %@" } diff --git a/Localization/StringsConvertor/input/en.lproj/app.json b/Localization/StringsConvertor/input/en.lproj/app.json index b57f0f4e4..30630361f 100644 --- a/Localization/StringsConvertor/input/en.lproj/app.json +++ b/Localization/StringsConvertor/input/en.lproj/app.json @@ -715,6 +715,7 @@ "notifications": "Notifications", "support_mastodon": "Support Mastodon", "about_mastodon": "About Mastodon", + "server_details": "Server Details", "logout": "Logout %@" } diff --git a/Localization/app.json b/Localization/app.json index b57f0f4e4..30630361f 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -715,6 +715,7 @@ "notifications": "Notifications", "support_mastodon": "Support Mastodon", "about_mastodon": "About Mastodon", + "server_details": "Server Details", "logout": "Logout %@" } diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index adb7dc3c4..7c90c594a 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -129,6 +129,7 @@ D807C6C029DE197900A4E17C /* EducationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D807C6BF29DE197900A4E17C /* EducationViewController.swift */; }; D808B94C296ECFDC0031EB1E /* StatusEditHistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D808B94B296ECFDC0031EB1E /* StatusEditHistoryViewModel.swift */; }; D808B94E296EFBBA0031EB1E /* StatusEditHistoryTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D808B94D296EFBBA0031EB1E /* StatusEditHistoryTableViewCell.swift */; }; + D80911082AC4BFDE00EB4D15 /* ServerDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D80911072AC4BFDE00EB4D15 /* ServerDetailsViewController.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 */; }; @@ -775,6 +776,7 @@ D807C6BF29DE197900A4E17C /* EducationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EducationViewController.swift; sourceTree = ""; }; D808B94B296ECFDC0031EB1E /* StatusEditHistoryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusEditHistoryViewModel.swift; sourceTree = ""; }; D808B94D296EFBBA0031EB1E /* StatusEditHistoryTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusEditHistoryTableViewCell.swift; sourceTree = ""; }; + D80911072AC4BFDE00EB4D15 /* ServerDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerDetailsViewController.swift; sourceTree = ""; }; D8099077294BC8A30050219F /* PrivacyTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyTableViewController.swift; sourceTree = ""; }; D8099079294BC9390050219F /* PrivacyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyTableViewCell.swift; sourceTree = ""; }; D809907B294D25510050219F /* PrivacyViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyViewModel.swift; sourceTree = ""; }; @@ -1756,6 +1758,7 @@ D8F916FF2A4AD898008A5370 /* Settings Overview */, D8F917042A4B0657008A5370 /* General Settings */, D81D12432A4E181C005009D4 /* Notification Settings */, + D80911062AC4BFD100EB4D15 /* Server Details */, D8F917092A4B2AFF008A5370 /* About Mastodon */, D8318A7F2A4466D300C0FB73 /* SettingsCoordinator.swift */, ); @@ -1783,6 +1786,14 @@ path = Bookmark; sourceTree = ""; }; + D80911062AC4BFD100EB4D15 /* Server Details */ = { + isa = PBXGroup; + children = ( + D80911072AC4BFDE00EB4D15 /* ServerDetailsViewController.swift */, + ); + path = "Server Details"; + sourceTree = ""; + }; D8099076294BC2BA0050219F /* Privacy */ = { isa = PBXGroup; children = ( @@ -3615,6 +3626,7 @@ DB023D26279FFB0A005AC798 /* ShareActivityProvider.swift in Sources */, 5D0393962612D266007FE196 /* WebViewModel.swift in Sources */, 5B24BBDA262DB14800A9381B /* ReportViewModel.swift in Sources */, + D80911082AC4BFDE00EB4D15 /* ServerDetailsViewController.swift in Sources */, 2D5A3D3825CF8D9F002347D6 /* ScrollViewContainer.swift in Sources */, DB6180EF26391CA50018D199 /* MediaPreviewImageViewController.swift in Sources */, DB1E347825F519300079D7DF /* PickServerItem.swift in Sources */, diff --git a/Mastodon/Scene/Settings/Server Details/ServerDetailsViewController.swift b/Mastodon/Scene/Settings/Server Details/ServerDetailsViewController.swift new file mode 100644 index 000000000..dbb947112 --- /dev/null +++ b/Mastodon/Scene/Settings/Server Details/ServerDetailsViewController.swift @@ -0,0 +1,20 @@ +// Copyright © 2023 Mastodon gGmbH. All rights reserved. + +import UIKit + +protocol ServerDetailsViewControllerDelegate: AnyObject { + +} + +class ServerDetailsViewController: UIViewController { + weak var delegate: ServerDetailsViewControllerDelegate? + + init() { + super.init(nibName: nil, bundle: nil) + + view.backgroundColor = .systemGroupedBackground + } + + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } +} + diff --git a/Mastodon/Scene/Settings/Settings Overview/Settings.swift b/Mastodon/Scene/Settings/Settings Overview/Settings.swift index bf3fba0bd..64c4c3ad3 100644 --- a/Mastodon/Scene/Settings/Settings Overview/Settings.swift +++ b/Mastodon/Scene/Settings/Settings Overview/Settings.swift @@ -10,62 +10,78 @@ struct SettingsSection: Hashable { enum SettingsEntry: Hashable { case general case notifications + case serverDetails(domain: String) case aboutMastodon case logout(accountName: String) var title: String { switch self { - case .general: - return L10n.Scene.Settings.Overview.general - case .notifications: - return L10n.Scene.Settings.Overview.notifications - case .aboutMastodon: - return L10n.Scene.Settings.Overview.aboutMastodon - case .logout(let accountName): - return L10n.Scene.Settings.Overview.logout(accountName) + case .general: + return L10n.Scene.Settings.Overview.general + case .notifications: + return L10n.Scene.Settings.Overview.notifications + case .serverDetails(_): + return L10n.Scene.Settings.Overview.serverDetails + case .aboutMastodon: + return L10n.Scene.Settings.Overview.aboutMastodon + case .logout(let accountName): + return L10n.Scene.Settings.Overview.logout(accountName) + } + } + + var secondaryTitle: String? { + switch self { + case .serverDetails(domain: let domain): + return domain + case .general, .notifications, .aboutMastodon, .logout(_): + return nil } } var accessoryType: UITableViewCell.AccessoryType { switch self { - case .general, .notifications, .aboutMastodon, .logout(_): - return .disclosureIndicator + case .general, .notifications, .serverDetails(_), .aboutMastodon, .logout(_): + return .disclosureIndicator } } var icon: UIImage? { switch self { - case .general: - return UIImage(systemName: "gear") - case .notifications: - return UIImage(systemName: "bell.badge") - case .aboutMastodon: - return UIImage(systemName: "info.circle.fill") - case .logout(_): - return nil + case .general: + return UIImage(systemName: "gear") + case .notifications: + return UIImage(systemName: "bell.badge") + case .serverDetails(_): + return UIImage(systemName: "server.rack") + case .aboutMastodon: + return UIImage(systemName: "info.circle.fill") + case .logout(_): + return nil } } var iconBackgroundColor: UIColor? { switch self { - case .general: - return .systemGray - case .notifications: - return .systemRed - case .aboutMastodon: - return .systemPurple - case .logout(_): - return nil + case .general: + return .systemGray + case .notifications: + return .systemRed + case .serverDetails(_): + return .systemTeal + case .aboutMastodon: + return .systemPurple + case .logout(_): + return nil } } var textColor: UIColor { switch self { - case .general, .notifications, .aboutMastodon: - return .label - case .logout(_): - return .red + case .general, .notifications, .aboutMastodon, .serverDetails(_): + return .label + case .logout(_): + return .red } } diff --git a/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift b/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift index 7e09f0fce..fcb181320 100644 --- a/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift +++ b/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift @@ -9,7 +9,9 @@ class SettingsTableViewCell: UITableViewCell { let iconImageView: UIImageView let iconImageBackgroundView: UIView let titleLabel: UILabel + let secondaryLabel: UILabel + private let labelStackView: UIStackView private let contentStackView: UIStackView override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { @@ -21,8 +23,17 @@ class SettingsTableViewCell: UITableViewCell { iconImageBackgroundView.addSubview(iconImageView) titleLabel = UILabel() + titleLabel.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17, weight: .regular)) + secondaryLabel = UILabel() + secondaryLabel.font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 12, weight: .regular)) + secondaryLabel.textColor = .secondaryLabel - contentStackView = UIStackView(arrangedSubviews: [iconImageBackgroundView, titleLabel]) + labelStackView = UIStackView(arrangedSubviews: [titleLabel, secondaryLabel]) + labelStackView.axis = .vertical + labelStackView.spacing = 2 + labelStackView.alignment = .leading + + contentStackView = UIStackView(arrangedSubviews: [iconImageBackgroundView, labelStackView]) contentStackView.translatesAutoresizingMaskIntoConstraints = false contentStackView.axis = .horizontal contentStackView.alignment = .center @@ -50,8 +61,8 @@ class SettingsTableViewCell: UITableViewCell { iconImageView.centerXAnchor.constraint(equalTo: iconImageBackgroundView.centerXAnchor), iconImageView.widthAnchor.constraint(equalToConstant: 20), - titleLabel.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 12), - contentView.bottomAnchor.constraint(greaterThanOrEqualTo: titleLabel.bottomAnchor, constant: 12), + labelStackView.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 12), + contentView.bottomAnchor.constraint(greaterThanOrEqualTo: labelStackView.bottomAnchor, constant: 12), ] NSLayoutConstraint.activate(constraints) @@ -61,6 +72,13 @@ class SettingsTableViewCell: UITableViewCell { titleLabel.textColor = entry.textColor titleLabel.text = entry.title + if let secondaryTitle = entry.secondaryTitle { + secondaryLabel.isHidden = false + secondaryLabel.text = secondaryTitle + } else { + secondaryLabel.isHidden = true + } + if let icon = entry.icon { iconImageView.image = icon iconImageView.tintColor = .white @@ -73,7 +91,6 @@ class SettingsTableViewCell: UITableViewCell { iconImageBackgroundView.backgroundColor = entry.iconBackgroundColor accessoryType = entry.accessoryType - } } diff --git a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift index 5c8727110..8dab17a63 100644 --- a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift @@ -16,11 +16,11 @@ class SettingsViewController: UIViewController { var tableViewDataSource: UITableViewDiffableDataSource? let tableView: UITableView - init(accountName: String) { + init(accountName: String, domain: String) { sections = [ .init(entries: [.general, .notifications]), - .init(entries: [.aboutMastodon]), + .init(entries: [.serverDetails(domain: domain), .aboutMastodon]), .init(entries: [.logout(accountName: accountName)]) ] diff --git a/Mastodon/Scene/Settings/SettingsCoordinator.swift b/Mastodon/Scene/Settings/SettingsCoordinator.swift index 93059ed91..2b3524655 100644 --- a/Mastodon/Scene/Settings/SettingsCoordinator.swift +++ b/Mastodon/Scene/Settings/SettingsCoordinator.swift @@ -34,7 +34,7 @@ class SettingsCoordinator: NSObject, Coordinator { self.appContext = appContext self.authContext = authContext - settingsViewController = SettingsViewController(accountName: accountName) + settingsViewController = SettingsViewController(accountName: accountName, domain: authContext.mastodonAuthenticationBox.domain) } func start() { @@ -65,8 +65,12 @@ extension SettingsCoordinator: SettingsViewControllerDelegate { let notificationViewController = NotificationSettingsViewController(currentSetting: currentSetting, notificationsEnabled: notificationsEnabled) notificationViewController.delegate = self - self.navigationController.pushViewController(notificationViewController, animated: true) + navigationController.pushViewController(notificationViewController, animated: true) + case .serverDetails(_): + let serverDetailsViewController = ServerDetailsViewController() + serverDetailsViewController.delegate = self + navigationController.pushViewController(serverDetailsViewController, animated: true) case .aboutMastodon: let aboutViewController = AboutViewController() aboutViewController.delegate = self @@ -183,3 +187,8 @@ extension SettingsCoordinator: PolicySelectionViewControllerDelegate { try? self.appContext.managedObjectContext.save() } } + +//MARK: - ServerDetailsViewControllerDelegate +extension SettingsCoordinator: ServerDetailsViewControllerDelegate { + +} diff --git a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift index 05ea58f05..701c9c045 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift +++ b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift @@ -1509,6 +1509,8 @@ public enum L10n { } /// Notifications public static let notifications = L10n.tr("Localizable", "Scene.Settings.Overview.Notifications", fallback: "Notifications") + /// Server Details + public static let serverDetails = L10n.tr("Localizable", "Scene.Settings.Overview.ServerDetails", fallback: "Server Details") /// Support Mastodon public static let supportMastodon = L10n.tr("Localizable", "Scene.Settings.Overview.SupportMastodon", fallback: "Support Mastodon") /// Settings diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings index ab6fef20f..348906f0b 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings @@ -527,6 +527,7 @@ uploaded to Mastodon."; "Scene.Settings.Overview.General" = "General"; "Scene.Settings.Overview.Notifications" = "Notifications"; "Scene.Settings.Overview.SupportMastodon" = "Support Mastodon"; +"Scene.Settings.Overview.ServerDetails" = "Server Details"; "Scene.Settings.Overview.AboutMastodon" = "About Mastodon"; "Scene.Settings.Overview.Logout" = "Logout %@"; diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings index ab6fef20f..348906f0b 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings @@ -527,6 +527,7 @@ uploaded to Mastodon."; "Scene.Settings.Overview.General" = "General"; "Scene.Settings.Overview.Notifications" = "Notifications"; "Scene.Settings.Overview.SupportMastodon" = "Support Mastodon"; +"Scene.Settings.Overview.ServerDetails" = "Server Details"; "Scene.Settings.Overview.AboutMastodon" = "About Mastodon"; "Scene.Settings.Overview.Logout" = "Logout %@";