Compare commits
No commits in common. "0e60e74a8ac329e7f979c60c995669c1df9f949e" and "576e4aa90d292426effd295cf3bec1e1f10ca439" have entirely different histories.
0e60e74a8a
...
576e4aa90d
|
@ -20,14 +20,6 @@ class MainSplitViewController: UISplitViewController {
|
|||
|
||||
private var tabBarViewController: MainTabBarViewController!
|
||||
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
return .portrait
|
||||
} else {
|
||||
return .all
|
||||
}
|
||||
}
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
|
||||
|
|
|
@ -21,8 +21,19 @@ class MyProfileViewController: ProfileViewController {
|
|||
|
||||
DispatchQueue.main.async {
|
||||
self.accountID = account.id
|
||||
self.setAvatarTabBarImage()
|
||||
}
|
||||
|
||||
_ = ImageCache.avatars.get(account.avatar, completion: { [weak self] (data) in
|
||||
guard let self = self, let data = data, let image = UIImage(data: data) else { return }
|
||||
DispatchQueue.main.async {
|
||||
let size = CGSize(width: 30, height: 30)
|
||||
let tabBarImage = UIGraphicsImageRenderer(size: size).image { (_) in
|
||||
image.draw(in: CGRect(origin: .zero, size: size))
|
||||
}
|
||||
let alwaysOriginalImage = tabBarImage.withRenderingMode(.alwaysOriginal)
|
||||
self.tabBarItem.image = alwaysOriginalImage
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,38 +45,8 @@ class MyProfileViewController: ProfileViewController {
|
|||
super.viewDidLoad()
|
||||
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Preferences", style: .plain, target: self, action: #selector(preferencesPressed))
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||
}
|
||||
|
||||
private func setAvatarTabBarImage() {
|
||||
guard let id = mastodonController.account?.id,
|
||||
let account = mastodonController.persistentContainer.account(for: id) else {
|
||||
return
|
||||
}
|
||||
|
||||
_ = ImageCache.avatars.get(account.avatar, completion: { [weak self] (data) in
|
||||
guard let self = self, let data = data, let image = UIImage(data: data) else { return }
|
||||
DispatchQueue.main.async {
|
||||
let size = CGSize(width: 30, height: 30)
|
||||
let rect = CGRect(origin: .zero, size: size)
|
||||
let tabBarImage = UIGraphicsImageRenderer(size: size).image { (_) in
|
||||
let radius = Preferences.shared.avatarStyle.cornerRadiusFraction * 30
|
||||
UIBezierPath(roundedRect: rect, cornerRadius: radius).addClip()
|
||||
image.draw(in: rect)
|
||||
}
|
||||
let alwaysOriginalImage = tabBarImage.withRenderingMode(.alwaysOriginal)
|
||||
self.tabBarItem.image = alwaysOriginalImage
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@objc private func preferencesChanged() {
|
||||
setAvatarTabBarImage()
|
||||
}
|
||||
|
||||
// MARK: - Interaction
|
||||
|
||||
@objc func preferencesPressed() {
|
||||
present(PreferencesNavigationController(mastodonController: mastodonController), animated: true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue