Add avatar style preference

This commit is contained in:
Shadowfacts 2018-08-28 19:49:31 -04:00
parent 7448c6a09e
commit 2d190e46e9
12 changed files with 123 additions and 8 deletions

View File

@ -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 = "<group>"; };
D663626521360DD700C9CBA2 /* Preferences.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Preferences.storyboard; sourceTree = "<group>"; };
D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesTableViewController.swift; sourceTree = "<group>"; };
D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesAdaptive.swift; sourceTree = "<group>"; };
D667E5E02134937B0057A976 /* StatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusTableViewCell.xib; sourceTree = "<group>"; };
D667E5E2213499F70057A976 /* Profile.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = "<group>"; };
D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = "<group>"; };
@ -154,6 +156,7 @@
children = (
D663626121360B1900C9CBA2 /* Preferences.swift */,
D663626321360D2300C9CBA2 /* AvatarStyle.swift */,
D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */,
);
path = Preferences;
sourceTree = "<group>";
@ -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 */,

View File

@ -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
}
}

View File

@ -32,4 +32,6 @@ class Preferences: Codable {
var showRepliesInProfiles = false
var avatarStyle = AvatarStyle.roundRect
}

View File

@ -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()
}

View File

@ -49,6 +49,38 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="RyJ-Y2-ypg">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="CFN-UV-Jyn">
<rect key="frame" x="0.0" y="115" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="CFN-UV-Jyn" id="dcx-Vr-nHa">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Use Circular Avatars" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-z5-4ad">
<rect key="frame" x="16" y="11.5" width="155" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EGF-Yh-zaU">
<rect key="frame" x="310" y="6.5" width="51" height="31"/>
<connections>
<action selector="circularAvatarsChanged:" destination="ArB-e7-yko" eventType="valueChanged" id="ZvM-jR-xgg"/>
</connections>
</switch>
</subviews>
<constraints>
<constraint firstItem="GJd-z5-4ad" firstAttribute="centerY" secondItem="dcx-Vr-nHa" secondAttribute="centerY" id="BWk-p9-4xR"/>
<constraint firstItem="EGF-Yh-zaU" firstAttribute="centerY" secondItem="dcx-Vr-nHa" secondAttribute="centerY" id="KOD-1g-yqy"/>
<constraint firstAttribute="trailing" secondItem="EGF-Yh-zaU" secondAttribute="trailing" constant="16" id="Ncq-4V-0mW"/>
<constraint firstItem="GJd-z5-4ad" firstAttribute="leading" secondItem="dcx-Vr-nHa" secondAttribute="leadingMargin" id="pFh-IN-rcq"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
<connections>
<outlet property="dataSource" destination="ArB-e7-yko" id="Kxa-qc-mae"/>
@ -57,6 +89,7 @@
</tableView>
<navigationItem key="navigationItem" title="Preferences" id="dN7-yl-voz"/>
<connections>
<outlet property="circularAvatarsSwitch" destination="EGF-Yh-zaU" id="jAS-4F-WwG"/>
<outlet property="showRepliesInProfilesSwitch" destination="iCG-F0-6ZK" id="p5E-oK-ZYl"/>
</connections>
</tableViewController>

View File

@ -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] = []

View File

@ -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
}
}

View File

@ -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

View File

@ -60,6 +60,14 @@ class TimelineTableViewController: UITableViewController {
}
}
override func viewWillAppear(_ animated: Bool) {
for cell in tableView.visibleCells {
if let cell = cell as? PreferencesAdaptive {
cell.updateUIForPreferences()
}
}
}
/*
// MARK: - Navigation

View File

@ -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

View File

@ -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)"

View File

@ -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