diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index 5222e65f2..77cfd2fa8 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -158,6 +158,7 @@ D8F0372C29D232730027DE2E /* HashtagIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F0372B29D232730027DE2E /* HashtagIntentHandler.swift */; }; D8F8A03A29CA5C15000195DD /* HashtagWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F8A03929CA5C15000195DD /* HashtagWidgetView.swift */; }; D8F8A03C29CA5CB6000195DD /* HashtagWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F8A03B29CA5CB6000195DD /* HashtagWidget.swift */; }; + D8F917012A4AD8A5008A5370 /* SettingsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F917002A4AD8A4008A5370 /* SettingsTableViewCell.swift */; }; DB0009A626AEE5DC009B9D2D /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = DB0009A926AEE5DC009B9D2D /* Intents.intentdefinition */; settings = {ATTRIBUTES = (codegen, ); }; }; DB0009A726AEE5DC009B9D2D /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = DB0009A926AEE5DC009B9D2D /* Intents.intentdefinition */; }; DB023D26279FFB0A005AC798 /* ShareActivityProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB023D25279FFB0A005AC798 /* ShareActivityProvider.swift */; }; @@ -809,6 +810,7 @@ D8F0372B29D232730027DE2E /* HashtagIntentHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagIntentHandler.swift; sourceTree = ""; }; D8F8A03929CA5C15000195DD /* HashtagWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagWidgetView.swift; sourceTree = ""; }; D8F8A03B29CA5CB6000195DD /* HashtagWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagWidget.swift; sourceTree = ""; }; + D8F917002A4AD8A4008A5370 /* SettingsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTableViewCell.swift; sourceTree = ""; }; DB0009A826AEE5DC009B9D2D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = Base; path = Base.lproj/Intents.intentdefinition; sourceTree = ""; }; DB0009AD26AEE5E4009B9D2D /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Intents.strings; sourceTree = ""; }; DB023D25279FFB0A005AC798 /* ShareActivityProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareActivityProvider.swift; sourceTree = ""; }; @@ -1732,6 +1734,7 @@ 5B90C455262599800002E742 /* Settings */ = { isa = PBXGroup; children = ( + D8F916FF2A4AD898008A5370 /* Settings Overview */, D8318A7E2A4466C900C0FB73 /* Legacy */, D8318A7F2A4466D300C0FB73 /* SettingsCoordinator.swift */, D8318A832A4468A800C0FB73 /* GeneralSettingsViewController.swift */, @@ -1872,6 +1875,14 @@ path = Hashtag; sourceTree = ""; }; + D8F916FF2A4AD898008A5370 /* Settings Overview */ = { + isa = PBXGroup; + children = ( + D8F917002A4AD8A4008A5370 /* SettingsTableViewCell.swift */, + ); + path = "Settings Overview"; + sourceTree = ""; + }; DB01409B25C40BB600F9F3CF /* Onboarding */ = { isa = PBXGroup; children = ( @@ -3755,6 +3766,7 @@ DB023D2827A0FABD005AC798 /* NotificationTableViewCellDelegate.swift in Sources */, DB8AF55025C13703002E6C99 /* MainTabBarController.swift in Sources */, DB023D2C27A10464005AC798 /* NotificationTimelineViewController+DataSourceProvider.swift in Sources */, + D8F917012A4AD8A5008A5370 /* SettingsTableViewCell.swift in Sources */, DB9D6BE925E4F5340051B173 /* SearchViewController.swift in Sources */, D8318A842A4468A800C0FB73 /* GeneralSettingsViewController.swift in Sources */, DBF1D257269DBAC600C1C08A /* SearchDetailViewModel.swift in Sources */, diff --git a/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift b/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift new file mode 100644 index 000000000..02c0f93aa --- /dev/null +++ b/Mastodon/Scene/Settings/Settings Overview/SettingsTableViewCell.swift @@ -0,0 +1,80 @@ +// Copyright © 2023 Mastodon gGmbH. All rights reserved. + +import UIKit + +class SettingsTableViewCell: UITableViewCell { + + static let reuseIdentifier = "SettingsTableViewCell" + + let iconImageView: UIImageView + let iconImageBackgroundView: UIView + let titleLabel: UILabel + + private let contentStackView: UIStackView + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + + iconImageView = UIImageView() + iconImageView.translatesAutoresizingMaskIntoConstraints = false + + iconImageBackgroundView = UIView() + iconImageBackgroundView.addSubview(iconImageView) + + titleLabel = UILabel() + + contentStackView = UIStackView(arrangedSubviews: [iconImageBackgroundView, titleLabel]) + contentStackView.translatesAutoresizingMaskIntoConstraints = false + contentStackView.axis = .horizontal + contentStackView.alignment = .center + contentStackView.spacing = 16 + + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(contentStackView) + setupConstraints() + } + + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + private func setupConstraints() { + let constraints = [ + contentStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), + contentStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16), + contentView.trailingAnchor.constraint(equalTo: contentStackView.trailingAnchor, constant: 8), + contentView.bottomAnchor.constraint(equalTo: contentStackView.bottomAnchor, constant: 8), + + iconImageBackgroundView.heightAnchor.constraint(equalToConstant: 30), + iconImageBackgroundView.widthAnchor.constraint(equalTo: iconImageBackgroundView.heightAnchor), + + iconImageView.centerYAnchor.constraint(equalTo: iconImageBackgroundView.centerYAnchor), + iconImageView.centerXAnchor.constraint(equalTo: iconImageBackgroundView.centerXAnchor), + iconImageView.heightAnchor.constraint(equalToConstant: 22), + iconImageView.widthAnchor.constraint(equalToConstant: 20), + + titleLabel.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 12), + contentView.bottomAnchor.constraint(greaterThanOrEqualTo: titleLabel.bottomAnchor, constant: 12), + ] + + NSLayoutConstraint.activate(constraints) + } + + func update(with entry: SettingsEntry) { + titleLabel.textColor = entry.textColor + titleLabel.text = entry.title + + if let icon = entry.icon { + iconImageView.image = icon + iconImageBackgroundView.isHidden = false + } else { + iconImageBackgroundView.isHidden = true + } + + iconImageBackgroundView.layer.cornerRadius = 5 + iconImageBackgroundView.backgroundColor = entry.iconBackgroundColor + + accessoryType = entry.accessoryType + + } +} + + diff --git a/Mastodon/Scene/Settings/SettingsViewController.swift b/Mastodon/Scene/Settings/SettingsViewController.swift index 0a1376845..7411069ed 100644 --- a/Mastodon/Scene/Settings/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/SettingsViewController.swift @@ -23,7 +23,7 @@ enum SettingsEntry: Hashable { case .aboutMastodon: return "About Mastodon" case .supportMastodon: - return "Suppoprt Mastodon" + return "Support Mastodon" case .logout(let accountName): return "Logout @\(accountName)" } @@ -80,10 +80,6 @@ enum SettingsEntry: Hashable { } } -class SettingsTableViewCell: UITableViewCell { - static let reuseIdentifier = "SettingsTableViewCell" -} - protocol SettingsViewControllerDelegate: AnyObject { func done(_ viewController: UIViewController) func didSelect(_ viewController: UIViewController, entry: SettingsEntry) @@ -117,19 +113,7 @@ class SettingsViewController: UIViewController { else { fatalError("Wrong cell WTF??") } let entry = self.sections[indexPath.section].entries[indexPath.row] - - var content = cell.defaultContentConfiguration() - content.attributedText = NSAttributedString(string: entry.title, attributes: [ - .foregroundColor: entry.textColor - ]) - content.image = entry.icon - content.imageProperties.cornerRadius = 5 -// content.imageProperties.back - // imageproperties -// content.ima - - cell.contentConfiguration = content - cell.accessoryType = entry.accessoryType + cell.update(with: entry) return cell }