diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 6e97253e..5809c0e5 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -158,6 +158,7 @@ D6757A7E2157E02600721E32 /* XCBRequestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6757A7D2157E02600721E32 /* XCBRequestSpec.swift */; }; D6757A822157E8FA00721E32 /* XCBSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6757A812157E8FA00721E32 /* XCBSession.swift */; }; D67895BC24671E6D00D4CD9E /* PKDrawing+Render.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67895BB24671E6D00D4CD9E /* PKDrawing+Render.swift */; }; + D67895C0246870DE00D4CD9E /* LocalAccountAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67895BF246870DE00D4CD9E /* LocalAccountAvatarView.swift */; }; D679C09F215850EF00DA27FE /* XCBActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D679C09E215850EF00DA27FE /* XCBActions.swift */; }; D67C57AD21E265FC00C3118B /* LargeAccountDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67C57AC21E265FC00C3118B /* LargeAccountDetailView.swift */; }; D67C57AF21E28EAD00C3118B /* Array+Uniques.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67C57AE21E28EAD00C3118B /* Array+Uniques.swift */; }; @@ -454,6 +455,7 @@ D6757A7D2157E02600721E32 /* XCBRequestSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBRequestSpec.swift; sourceTree = ""; }; D6757A812157E8FA00721E32 /* XCBSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBSession.swift; sourceTree = ""; }; D67895BB24671E6D00D4CD9E /* PKDrawing+Render.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PKDrawing+Render.swift"; sourceTree = ""; }; + D67895BF246870DE00D4CD9E /* LocalAccountAvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalAccountAvatarView.swift; sourceTree = ""; }; D679C09E215850EF00DA27FE /* XCBActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBActions.swift; sourceTree = ""; }; D67C57AC21E265FC00C3118B /* LargeAccountDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeAccountDetailView.swift; sourceTree = ""; }; D67C57AE21E28EAD00C3118B /* Array+Uniques.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Uniques.swift"; sourceTree = ""; }; @@ -942,6 +944,7 @@ D6BC9DB2232D4C07002CA326 /* WellnessPrefsView.swift */, 0427033922B31269000D31B6 /* AdvancedPrefsView.swift */, 0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */, + D67895BF246870DE00D4CD9E /* LocalAccountAvatarView.swift */, ); path = Preferences; sourceTree = ""; @@ -1743,6 +1746,7 @@ D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */, D627943523A5525100D38C68 /* StatusActivity.swift in Sources */, D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */, + D67895C0246870DE00D4CD9E /* LocalAccountAvatarView.swift in Sources */, D6333B372137838300CE884A /* AttributedString+Helpers.swift in Sources */, D6DFC69E242C490400ACC392 /* TrackpadScrollGestureRecognizer.swift in Sources */, D61AC1D8232EA42D00C54D2D /* InstanceTableViewCell.swift in Sources */, diff --git a/Tusker/Screens/Preferences/LocalAccountAvatarView.swift b/Tusker/Screens/Preferences/LocalAccountAvatarView.swift new file mode 100644 index 00000000..7fbbb4d0 --- /dev/null +++ b/Tusker/Screens/Preferences/LocalAccountAvatarView.swift @@ -0,0 +1,47 @@ +// +// LocalAccountAvatarView.swift +// Tusker +// +// Created by Shadowfacts on 5/10/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import SwiftUI + +struct LocalAccountAvatarView: View { + let localAccountInfo: LocalData.UserAccountInfo + @State + var avatarImage: UIImage? = nil + + var body: some View { + let image: Image + if avatarImage == nil { + image = Image(systemName: "person.crop.square") + } else { + image = Image(uiImage: self.avatarImage!).renderingMode(.original) + } + return image + .resizable() + .frame(width: 30, height: 30) + .onAppear(perform: self.loadImage) + } + + func loadImage() { + let controller = MastodonController.getForAccount(localAccountInfo) + controller.getOwnAccount { (account) in + _ = ImageCache.avatars.get(account.avatar) { (data) in + if let data = data, let image = UIImage(data: data) { + DispatchQueue.main.async { + self.avatarImage = image + } + } + } + } + } +} + +//struct LocalAccountAvatarView_Previews: PreviewProvider { +// static var previews: some View { +// LocalAccountAvatarView() +// } +//} diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index 86896dc8..d74e52c3 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -21,8 +21,14 @@ struct PreferencesView: View { NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account]) }) { HStack { - Text(account.username) - .foregroundColor(.primary) + LocalAccountAvatarView(localAccountInfo: account) + VStack(alignment: .leading) { + Text(verbatim: account.username) + .foregroundColor(.primary) + Text(verbatim: account.instanceURL.host!) + .font(.caption) + .foregroundColor(.primary) + } Spacer() if account == self.localData.getMostRecentAccount() { Image(systemName: "checkmark")