diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index a711cfee..71db6e2d 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ D663626421360D2300C9CBA2 /* AvatarStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626321360D2300C9CBA2 /* AvatarStyle.swift */; }; D663626621360DD700C9CBA2 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D663626521360DD700C9CBA2 /* Preferences.storyboard */; }; D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */; }; + D663626A2136163000C9CBA2 /* PreferencesAdaptive.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */; }; D667E5E12134937B0057A976 /* StatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E02134937B0057A976 /* StatusTableViewCell.xib */; }; D667E5E3213499F70057A976 /* Profile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E2213499F70057A976 /* Profile.storyboard */; }; D667E5E721349D4C0057A976 /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */; }; @@ -92,6 +93,7 @@ D663626321360D2300C9CBA2 /* AvatarStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarStyle.swift; sourceTree = ""; }; D663626521360DD700C9CBA2 /* Preferences.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = ""; }; D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTableViewController.swift; sourceTree = ""; }; + D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesAdaptive.swift; sourceTree = ""; }; D667E5E02134937B0057A976 /* StatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusTableViewCell.xib; sourceTree = ""; }; D667E5E2213499F70057A976 /* Profile.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = ""; }; D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = ""; }; @@ -154,6 +156,7 @@ children = ( D663626121360B1900C9CBA2 /* Preferences.swift */, D663626321360D2300C9CBA2 /* AvatarStyle.swift */, + D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */, ); path = Preferences; sourceTree = ""; @@ -430,6 +433,7 @@ D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */, D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */, D6F953EC212519E700CF0F2B /* TimelineTableViewController.swift in Sources */, + D663626A2136163000C9CBA2 /* PreferencesAdaptive.swift in Sources */, D667E5EB21349EF80057A976 /* ProfileHeaderTableViewCell.swift in Sources */, D64A0CD32132153900640E3B /* HTMLContentLabel.swift in Sources */, D667E5F12134D5050057A976 /* UIViewController+StatusTableViewCellDelegate.swift in Sources */, diff --git a/Tusker/Preferences/AvatarStyle.swift b/Tusker/Preferences/AvatarStyle.swift index ab840fc4..1cace394 100644 --- a/Tusker/Preferences/AvatarStyle.swift +++ b/Tusker/Preferences/AvatarStyle.swift @@ -6,8 +6,23 @@ // Copyright © 2018 Shadowfacts. All rights reserved. // -import Foundation +import UIKit enum AvatarStyle: String, Codable { case roundRect, circle } + +extension AvatarStyle { + var cornerRadiusFraction: CGFloat { + switch self { + case .roundRect: + return 0.1 + case .circle: + return 0.5 + } + } + + func cornerRadius(for view: UIView) -> CGFloat { + return cornerRadiusFraction * view.frame.width + } +} diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 5af83cf8..65965d71 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -32,4 +32,6 @@ class Preferences: Codable { var showRepliesInProfiles = false + var avatarStyle = AvatarStyle.roundRect + } diff --git a/Tusker/Preferences/PreferencesAdaptive.swift b/Tusker/Preferences/PreferencesAdaptive.swift new file mode 100644 index 00000000..6d0393a7 --- /dev/null +++ b/Tusker/Preferences/PreferencesAdaptive.swift @@ -0,0 +1,15 @@ +// +// PreferencesAdaptive.swift +// Tusker +// +// Created by Shadowfacts on 8/28/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import Foundation + +protocol PreferencesAdaptive { + + func updateUIForPreferences() + +} diff --git a/Tusker/Storyboards/Preferences.storyboard b/Tusker/Storyboards/Preferences.storyboard index 726fdc0b..114459bc 100644 --- a/Tusker/Storyboards/Preferences.storyboard +++ b/Tusker/Storyboards/Preferences.storyboard @@ -49,6 +49,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,6 +89,7 @@ + diff --git a/Tusker/View Controllers/ConversationViewController.swift b/Tusker/View Controllers/ConversationViewController.swift index 506d5860..1de4b231 100644 --- a/Tusker/View Controllers/ConversationViewController.swift +++ b/Tusker/View Controllers/ConversationViewController.swift @@ -54,6 +54,14 @@ class ConversationViewController: UIViewController, UITableViewDataSource, UITab } } + override func viewWillAppear(_ animated: Bool) { + for cell in tableView.visibleCells { + if let cell = cell as? PreferencesAdaptive { + cell.updateUIForPreferences() + } + } + } + func getDirectParents(of status: Status, from statuses: [Status]) -> [Status] { var statuses = statuses var parents: [Status] = [] diff --git a/Tusker/View Controllers/PreferencesTableViewController.swift b/Tusker/View Controllers/PreferencesTableViewController.swift index 400a27f0..dd8027fd 100644 --- a/Tusker/View Controllers/PreferencesTableViewController.swift +++ b/Tusker/View Controllers/PreferencesTableViewController.swift @@ -16,11 +16,13 @@ class PreferencesTableViewController: UITableViewController { } @IBOutlet weak var showRepliesInProfilesSwitch: UISwitch! + @IBOutlet weak var circularAvatarsSwitch: UISwitch! override func viewDidLoad() { super.viewDidLoad() showRepliesInProfilesSwitch.setOn(Preferences.shared.showRepliesInProfiles, animated: false) + circularAvatarsSwitch.setOn(Preferences.shared.avatarStyle == .circle, animated: false) } /* @@ -37,4 +39,8 @@ class PreferencesTableViewController: UITableViewController { Preferences.shared.showRepliesInProfiles = showRepliesInProfilesSwitch.isOn } + @IBAction func circularAvatarsChanged(_ sender: Any) { + Preferences.shared.avatarStyle = circularAvatarsSwitch.isOn ? .circle : .roundRect + } + } diff --git a/Tusker/View Controllers/ProfileTableViewController.swift b/Tusker/View Controllers/ProfileTableViewController.swift index 9b5abcec..7a098579 100644 --- a/Tusker/View Controllers/ProfileTableViewController.swift +++ b/Tusker/View Controllers/ProfileTableViewController.swift @@ -55,6 +55,14 @@ class ProfileTableViewController: UITableViewController { } } + override func viewWillAppear(_ animated: Bool) { + for cell in tableView.visibleCells { + if let cell = cell as? PreferencesAdaptive { + cell.updateUIForPreferences() + } + } + } + /* // MARK: - Navigation diff --git a/Tusker/View Controllers/TimelineTableViewController.swift b/Tusker/View Controllers/TimelineTableViewController.swift index 3da87cf9..1d33b155 100644 --- a/Tusker/View Controllers/TimelineTableViewController.swift +++ b/Tusker/View Controllers/TimelineTableViewController.swift @@ -59,6 +59,14 @@ class TimelineTableViewController: UITableViewController { self.older = pagination?.next } } + + override func viewWillAppear(_ animated: Bool) { + for cell in tableView.visibleCells { + if let cell = cell as? PreferencesAdaptive { + cell.updateUIForPreferences() + } + } + } /* // MARK: - Navigation diff --git a/Tusker/Views/ConversationMainStatusTableViewCell.swift b/Tusker/Views/ConversationMainStatusTableViewCell.swift index 51570f90..713e0f0c 100644 --- a/Tusker/Views/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/ConversationMainStatusTableViewCell.swift @@ -9,7 +9,7 @@ import UIKit import MastodonKit -class ConversationMainStatusTableViewCell: UITableViewCell { +class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive { var delegate: StatusTableViewCellDelegate? @@ -30,10 +30,13 @@ class ConversationMainStatusTableViewCell: UITableViewCell { usernameLabel.isUserInteractionEnabled = true avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed))) avatarImageView.isUserInteractionEnabled = true - avatarImageView.layer.cornerRadius = 5 avatarImageView.layer.masksToBounds = true } + func updateUIForPreferences() { + avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) + } + func updateUI(for status: Status) { self.status = status @@ -45,6 +48,8 @@ class ConversationMainStatusTableViewCell: UITableViewCell { } self.account = account + updateUIForPreferences() + displayNameLabel.text = account.displayName usernameLabel.text = "@\(account.acct)" avatarImageView.image = nil diff --git a/Tusker/Views/ProfileHeaderTableViewCell.swift b/Tusker/Views/ProfileHeaderTableViewCell.swift index a9292779..98c5ef05 100644 --- a/Tusker/Views/ProfileHeaderTableViewCell.swift +++ b/Tusker/Views/ProfileHeaderTableViewCell.swift @@ -15,7 +15,7 @@ protocol ProfileHeaderTableViewCellDelegate: StatusTableViewCellDelegate { } -class ProfileHeaderTableViewCell: UITableViewCell { +class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { var delegate: ProfileHeaderTableViewCellDelegate? @@ -33,15 +33,20 @@ class ProfileHeaderTableViewCell: UITableViewCell { var headerImageDownloadTask: URLSessionDataTask? override func awakeFromNib() { - avatarContainerView.layer.cornerRadius = 12 avatarContainerView.layer.masksToBounds = true - avatarImageView.layer.cornerRadius = 11.6 avatarImageView.layer.masksToBounds = true } + func updateUIForPreferences() { + avatarContainerView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarContainerView) + avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) + } + func updateUI(for account: Account) { self.account = account + updateUIForPreferences() + displayNameLabel.text = account.displayName usernameLabel.text = "@\(account.acct)" diff --git a/Tusker/Views/StatusTableViewCell.swift b/Tusker/Views/StatusTableViewCell.swift index bf5c1edc..ea5e759a 100644 --- a/Tusker/Views/StatusTableViewCell.swift +++ b/Tusker/Views/StatusTableViewCell.swift @@ -23,7 +23,7 @@ protocol StatusTableViewCellDelegate { } -class StatusTableViewCell: UITableViewCell { +class StatusTableViewCell: UITableViewCell, PreferencesAdaptive { var delegate: StatusTableViewCellDelegate? @@ -44,10 +44,13 @@ class StatusTableViewCell: UITableViewCell { usernameLabel.isUserInteractionEnabled = true avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed))) avatarImageView.isUserInteractionEnabled = true - avatarImageView.layer.cornerRadius = 5 avatarImageView.layer.masksToBounds = true } + func updateUIForPreferences() { + avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) + } + func updateUI(for status: Status) { self.status = status @@ -59,6 +62,9 @@ class StatusTableViewCell: UITableViewCell { } self.account = account + + updateUIForPreferences() + displayNameLabel.text = account.displayName usernameLabel.text = "@\(account.acct)" avatarImageView.image = nil