IceCubesApp/IceCubesApp/App/Tabs/Settings/AboutView.swift

168 lines
4.8 KiB
Swift
Raw Normal View History

2023-12-18 07:22:59 +00:00
import Account
import DesignSystem
2023-02-04 16:17:38 +00:00
import Env
2023-12-08 07:04:35 +00:00
import Models
2023-12-18 07:22:59 +00:00
import Network
import SwiftUI
2023-09-18 19:03:52 +00:00
@MainActor
struct AboutView: View {
@Environment(RouterPath.self) private var routerPath
2023-09-18 19:03:52 +00:00
@Environment(Theme.self) private var theme
2023-12-08 07:04:35 +00:00
@Environment(Client.self) private var client
2023-12-08 07:04:35 +00:00
@State private var dimillianAccount: AccountsListRowViewModel?
@State private var iceCubesAccount: AccountsListRowViewModel?
2023-12-18 07:22:59 +00:00
2023-02-04 16:17:38 +00:00
let versionNumber: String
init() {
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
2023-02-04 16:17:38 +00:00
versionNumber = version + " "
} else {
versionNumber = ""
}
}
2023-02-04 16:17:38 +00:00
var body: some View {
2023-03-12 11:58:00 +00:00
List {
Section {
HStack {
Spacer()
Image("icon0")
.resizable()
.frame(width: 50, height: 50)
.cornerRadius(4)
Image("icon14")
.resizable()
.frame(width: 50, height: 50)
.cornerRadius(4)
Image("icon17")
.resizable()
.frame(width: 50, height: 50)
.cornerRadius(4)
Image("icon23")
.resizable()
.frame(width: 50, height: 50)
.cornerRadius(4)
Spacer()
}
2023-03-12 11:58:00 +00:00
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp/blob/main/PRIVACY.MD")!) {
Label("settings.support.privacy-policy", systemImage: "lock")
}
2023-03-13 12:38:28 +00:00
2023-03-12 11:58:00 +00:00
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp/blob/main/TERMS.MD")!) {
Label("settings.support.terms-of-use", systemImage: "checkmark.shield")
}
} footer: {
Text("\(versionNumber)©2023 Thomas Ricouard")
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-03-12 11:58:00 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-03-13 12:38:28 +00:00
2023-12-08 07:04:35 +00:00
followAccountsSection
2023-03-12 11:58:00 +00:00
Section {
Text("""
2023-02-04 16:17:38 +00:00
[EmojiText](https://github.com/divadretlaw/EmojiText)
2023-02-04 16:17:38 +00:00
[HTML2Markdown](https://gitlab.com/mflint/HTML2Markdown)
2023-02-04 16:17:38 +00:00
[KeychainSwift](https://github.com/evgenyneu/keychain-swift)
2023-02-04 16:17:38 +00:00
[LRUCache](https://github.com/nicklockwood/LRUCache)
2023-02-12 15:29:41 +00:00
[Bodega](https://github.com/mergesort/Bodega)
2023-02-04 16:17:38 +00:00
[Nuke](https://github.com/kean/Nuke)
2023-02-04 16:17:38 +00:00
[SwiftSoup](https://github.com/scinfu/SwiftSoup.git)
2023-02-04 16:17:38 +00:00
[Atkinson Hyperlegible](https://github.com/googlefonts/atkinson-hyperlegible)
2023-02-04 16:17:38 +00:00
[OpenDyslexic](http://opendyslexic.org)
[SwiftUI-Introspect](https://github.com/siteline/SwiftUI-Introspect)
[RevenueCat](https://github.com/RevenueCat/purchases-ios)
2023-09-16 12:15:03 +00:00
[SFSafeSymbols](https://github.com/SFSafeSymbols/SFSafeSymbols)
2023-02-04 16:17:38 +00:00
""")
.multilineTextAlignment(.leading)
.font(.scaledSubheadline)
2023-12-04 14:49:44 +00:00
.foregroundStyle(.secondary)
2023-03-12 11:58:00 +00:00
} header: {
Text("settings.about.built-with")
.textCase(nil)
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-03-12 11:58:00 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
}
2023-12-08 07:04:35 +00:00
.task {
await fetchAccounts()
}
2023-03-12 11:58:00 +00:00
.listStyle(.insetGrouped)
2023-12-18 15:51:02 +00:00
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
2023-12-18 15:51:02 +00:00
#endif
.navigationTitle(Text("settings.about.title"))
.navigationBarTitleDisplayMode(.large)
.environment(\.openURL, OpenURLAction { url in
routerPath.handle(url: url)
})
}
2023-12-18 07:22:59 +00:00
2023-12-08 07:04:35 +00:00
@ViewBuilder
private var followAccountsSection: some View {
if let iceCubesAccount, let dimillianAccount {
Section {
AccountsListRow(viewModel: iceCubesAccount)
AccountsListRow(viewModel: dimillianAccount)
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-12-08 07:04:35 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-12-08 07:04:35 +00:00
} else {
Section {
ProgressView()
}
2023-12-19 08:48:12 +00:00
#if !os(visionOS)
2023-12-08 07:04:35 +00:00
.listRowBackground(theme.primaryBackgroundColor)
2023-12-19 08:48:12 +00:00
#endif
2023-12-08 07:04:35 +00:00
}
}
private func fetchAccounts() async {
await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
let viewModel = try await fetchAccountViewModel(account: "dimillian@mastodon.social")
await MainActor.run {
2023-12-18 07:22:59 +00:00
dimillianAccount = viewModel
2023-12-08 07:04:35 +00:00
}
}
group.addTask {
let viewModel = try await fetchAccountViewModel(account: "icecubesapp@mastodon.online")
await MainActor.run {
2023-12-18 07:22:59 +00:00
iceCubesAccount = viewModel
2023-12-08 07:04:35 +00:00
}
}
}
}
2023-12-18 07:22:59 +00:00
2023-12-08 07:04:35 +00:00
private func fetchAccountViewModel(account: String) async throws -> AccountsListRowViewModel {
let dimillianAccount: Account = try await client.get(endpoint: Accounts.lookup(name: account))
let rel: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [dimillianAccount.id]))
return .init(account: dimillianAccount, relationShip: rel.first)
}
}
struct AboutView_Previews: PreviewProvider {
2023-02-04 16:17:38 +00:00
static var previews: some View {
AboutView()
2023-09-18 19:03:52 +00:00
.environment(Theme.shared)
2023-02-04 16:17:38 +00:00
}
}