From 7ce49ca074f79e221ceb074d9bc3e90223887247 Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Sat, 24 Nov 2018 22:22:12 -0800 Subject: [PATCH] Fix the avatar UIBarButtonItem --- elpha-ios/AlertManager.swift | 2 +- elpha-ios/AlertView.swift | 16 +-- elpha-ios/Base.lproj/Main.storyboard | 47 ++++----- elpha-ios/TimelineTableViewController.swift | 108 +++++++++++--------- 4 files changed, 94 insertions(+), 79 deletions(-) diff --git a/elpha-ios/AlertManager.swift b/elpha-ios/AlertManager.swift index b8f8854..a7a246e 100644 --- a/elpha-ios/AlertManager.swift +++ b/elpha-ios/AlertManager.swift @@ -9,7 +9,7 @@ import UIKit enum AlertCategory { - case normal, newStatuses, favorited, boosted, noConnection, error + case normal, newStatuses, favorited, boosted, toot, noConnection, error } class Alert { diff --git a/elpha-ios/AlertView.swift b/elpha-ios/AlertView.swift index 2c5a66f..eb23894 100644 --- a/elpha-ios/AlertView.swift +++ b/elpha-ios/AlertView.swift @@ -34,14 +34,14 @@ import UIKit public func setAlert(_ alert: Alert) { switch alert.category { - case .newStatuses: - alertImageView.image = UIImage(named: "Comments") - case .favorited: - alertImageView.image = UIImage(named: "Star Filled") - case .boosted: - alertImageView.image = UIImage(named: "Boost Bold") - default: - alertImageView.image = UIImage(named: "Alert") + case .newStatuses, .toot: + alertImageView.image = UIImage(named: "Comments") + case .favorited: + alertImageView.image = UIImage(named: "Star Filled") + case .boosted: + alertImageView.image = UIImage(named: "Boost Bold") + default: + alertImageView.image = UIImage(named: "Alert") } alertLabel.text = alert.message diff --git a/elpha-ios/Base.lproj/Main.storyboard b/elpha-ios/Base.lproj/Main.storyboard index c86cdce..b742625 100644 --- a/elpha-ios/Base.lproj/Main.storyboard +++ b/elpha-ios/Base.lproj/Main.storyboard @@ -116,7 +116,7 @@ - + @@ -250,7 +250,7 @@ - + @@ -473,21 +473,21 @@ - + - + - + - + @@ -513,7 +513,7 @@ - + - + - + - + @@ -603,10 +603,10 @@ - + - + @@ -615,7 +615,7 @@ - + @@ -676,7 +676,7 @@ - + @@ -696,7 +696,7 @@ - + @@ -725,6 +725,7 @@ + @@ -747,7 +748,7 @@ - + @@ -793,7 +794,7 @@ - + @@ -990,7 +991,7 @@ - + @@ -1090,7 +1091,7 @@ - + @@ -1290,7 +1291,7 @@ - + @@ -1343,7 +1344,7 @@ - + @@ -1879,7 +1880,7 @@ - + @@ -1905,7 +1906,7 @@ - + diff --git a/elpha-ios/TimelineTableViewController.swift b/elpha-ios/TimelineTableViewController.swift index 8d19e66..cafe72e 100644 --- a/elpha-ios/TimelineTableViewController.swift +++ b/elpha-ios/TimelineTableViewController.swift @@ -21,16 +21,16 @@ class TimelineTableViewController: AbstractStatusTableViewController { } switch TimelineCategory(rawValue: categoryString)! { - case .home: - return "timeline:home" - case .local: - return "timeline:local" - case .federated: - return "timeline:federated" - case .tag: - return "timeline:tag:\(timeline.subcategory!)" - case .favorites: - return "timeline:favorites" + case .home: + return "timeline:home" + case .local: + return "timeline:local" + case .federated: + return "timeline:federated" + case .tag: + return "timeline:tag:\(timeline.subcategory!)" + case .favorites: + return "timeline:favorites" } } } @@ -41,18 +41,32 @@ class TimelineTableViewController: AbstractStatusTableViewController { feedbackGenerator = UINotificationFeedbackGenerator() initializeFetchedResultsController() + let scale = UIScreen.main.scale + let avatarButtonSize: CGFloat = 30 + let avatarButtonScaledSize = avatarButtonSize * scale + let moreButtonItem = UIBarButtonItem(image: UIImage(named: "More"), style: .plain, target: self, action: #selector(more)) let composeButtonItem = UIBarButtonItem(image: UIImage(named: "Compose"), style: .plain, target: self, action: #selector(compose)) - let avatarButtonItem = UIBarButtonItem(image: UIImage(named: "Account"), style: .plain, target: self, action: #selector(self.openSettings)) + + let avatarButton = UIButton() + avatarButton.setBackgroundImage(UIImage(named: "Account"), for: .normal) + avatarButton.addTarget(self, action: #selector(self.openSettings), for: .touchUpInside) + + NSLayoutConstraint.activate([ + avatarButton.widthAnchor.constraint(equalToConstant: avatarButtonSize), + avatarButton.heightAnchor.constraint(equalToConstant: avatarButtonSize) + ]) + + let avatarButtonItem = UIBarButtonItem(customView: avatarButton) navigationItem.leftBarButtonItems = [avatarButtonItem, moreButtonItem] navigationItem.rightBarButtonItems = [composeButtonItem] if let account = AuthenticationManager.session?.account { - let processor = ResizingImageProcessor(referenceSize: CGSize(width: 30, height: 30), mode: .aspectFill) >> RoundCornerImageProcessor(cornerRadius: 10) + let processor = ResizingImageProcessor(referenceSize: CGSize(width: avatarButtonScaledSize, height: avatarButtonScaledSize), mode: .aspectFill) >> RoundCornerImageProcessor(cornerRadius: avatarButtonScaledSize / 2) ImageDownloader.default.downloadImage(with: account.avatarURL!, retrieveImageTask: nil, options: [.processor(processor)], progressBlock: nil) { image, error, url, data in if let image = image { - avatarButtonItem.image = image.withRenderingMode(.alwaysOriginal) + avatarButton.setBackgroundImage(image.withRenderingMode(.alwaysOriginal), for: .normal) } } } @@ -252,40 +266,40 @@ class TimelineTableViewController: AbstractStatusTableViewController { loading = true switch TimelineCategory(rawValue: timeline.category!)! { - case .home: - MastodonAPI.homeTimeline( - limit: fetchLimit, - pagination: pagination, - completion: requestCompletion - ) - case .local: - MastodonAPI.publicTimeline( - local: true, - limit: fetchLimit, - pagination: pagination, - completion: requestCompletion - ) - case .federated: - MastodonAPI.publicTimeline( - local: false, - limit: fetchLimit, - pagination: pagination, - completion: requestCompletion - ) - case .tag: - MastodonAPI.tagTimeline( - tag: timeline.subcategory!, - local: false, - limit: fetchLimit, - pagination: pagination, - completion: requestCompletion - ) - case .favorites: - MastodonAPI.favorites( - limit: fetchLimit, - pagination: pagination, - completion: requestCompletion - ) + case .home: + MastodonAPI.homeTimeline( + limit: fetchLimit, + pagination: pagination, + completion: requestCompletion + ) + case .local: + MastodonAPI.publicTimeline( + local: true, + limit: fetchLimit, + pagination: pagination, + completion: requestCompletion + ) + case .federated: + MastodonAPI.publicTimeline( + local: false, + limit: fetchLimit, + pagination: pagination, + completion: requestCompletion + ) + case .tag: + MastodonAPI.tagTimeline( + tag: timeline.subcategory!, + local: false, + limit: fetchLimit, + pagination: pagination, + completion: requestCompletion + ) + case .favorites: + MastodonAPI.favorites( + limit: fetchLimit, + pagination: pagination, + completion: requestCompletion + ) } } }