2022-12-01 09:05:26 +01:00
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-12-22 10:53:36 +01:00
|
|
|
import Env
|
2022-12-01 09:05:26 +01:00
|
|
|
import Network
|
|
|
|
import Account
|
|
|
|
import Models
|
2022-12-24 14:55:04 +01:00
|
|
|
import DesignSystem
|
2022-12-01 09:05:26 +01:00
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
struct SettingsTabs: View {
|
2022-12-01 09:05:26 +01:00
|
|
|
@EnvironmentObject private var client: Client
|
2022-12-29 06:55:53 +01:00
|
|
|
@EnvironmentObject private var currentAccount: CurrentAccount
|
2022-12-28 08:06:46 +01:00
|
|
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
2022-12-01 09:05:26 +01:00
|
|
|
@EnvironmentObject private var appAccountsManager: AppAccountsManager
|
2022-12-24 14:55:04 +01:00
|
|
|
@EnvironmentObject private var theme: Theme
|
2022-12-01 09:05:26 +01:00
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
@State private var addAccountSheetPresented = false
|
2022-12-01 09:05:26 +01:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationStack {
|
|
|
|
Form {
|
2022-12-04 09:50:25 +01:00
|
|
|
appSection
|
2022-12-29 07:00:00 +01:00
|
|
|
accountsSection
|
2022-12-24 14:55:04 +01:00
|
|
|
themeSection
|
2022-12-04 09:50:25 +01:00
|
|
|
instanceSection
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2022-12-01 09:05:26 +01:00
|
|
|
.navigationTitle(Text("Settings"))
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
}
|
|
|
|
.task {
|
|
|
|
if appAccountsManager.currentAccount.oauthToken != nil {
|
2022-12-29 06:55:53 +01:00
|
|
|
await currentAccount.fetchCurrentAccount()
|
2022-12-28 08:06:46 +01:00
|
|
|
await currentInstance.fetchCurrentInstance()
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-29 07:00:00 +01:00
|
|
|
private var accountsSection: some View {
|
2022-12-04 09:50:25 +01:00
|
|
|
Section("Account") {
|
2022-12-29 06:55:53 +01:00
|
|
|
if let accountData = currentAccount.account {
|
2022-12-29 07:00:00 +01:00
|
|
|
HStack {
|
|
|
|
AvatarView(url: accountData.avatar)
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(appAccountsManager.currentAccount.server)
|
|
|
|
.font(.headline)
|
|
|
|
Text(accountData.displayName)
|
|
|
|
Text(accountData.username)
|
|
|
|
.font(.footnote)
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
signOutButton
|
|
|
|
}
|
2022-12-29 14:07:58 +01:00
|
|
|
addAccountButton
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
|
2022-12-24 14:55:04 +01:00
|
|
|
private var themeSection: some View {
|
|
|
|
Section("Theme") {
|
2022-12-29 10:39:34 +01:00
|
|
|
Toggle("Prefer dark color scheme", isOn: .init(get: {
|
|
|
|
theme.colorScheme == "dark"
|
|
|
|
}, set: { newValue in
|
|
|
|
if newValue {
|
|
|
|
theme.colorScheme = "dark"
|
|
|
|
} else {
|
|
|
|
theme.colorScheme = "light"
|
|
|
|
}
|
|
|
|
}))
|
2022-12-24 14:55:04 +01:00
|
|
|
ColorPicker("Tint color", selection: $theme.tintColor)
|
2022-12-29 10:39:34 +01:00
|
|
|
ColorPicker("Background color", selection: $theme.primaryBackgroundColor)
|
|
|
|
ColorPicker("Secondary Background color", selection: $theme.secondaryBackgroundColor)
|
2022-12-24 14:55:04 +01:00
|
|
|
Button {
|
2022-12-29 10:39:34 +01:00
|
|
|
theme.colorScheme = "dark"
|
2022-12-24 14:55:04 +01:00
|
|
|
theme.tintColor = .brand
|
2022-12-29 10:39:34 +01:00
|
|
|
theme.primaryBackgroundColor = .primaryBackground
|
|
|
|
theme.secondaryBackgroundColor = .secondaryBackground
|
2022-12-24 14:55:04 +01:00
|
|
|
} label: {
|
|
|
|
Text("Restore default")
|
|
|
|
}
|
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-24 14:55:04 +01:00
|
|
|
}
|
|
|
|
|
2022-12-04 09:50:25 +01:00
|
|
|
@ViewBuilder
|
|
|
|
private var instanceSection: some View {
|
2022-12-28 08:06:46 +01:00
|
|
|
if let instanceData = currentInstance.instance {
|
2022-12-29 14:07:58 +01:00
|
|
|
InstanceInfoView(instance: instanceData)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var appSection: some View {
|
|
|
|
Section("App") {
|
|
|
|
NavigationLink(destination: IconSelectorView()) {
|
|
|
|
Label {
|
|
|
|
Text("Icon selector")
|
|
|
|
} icon: {
|
2022-12-27 21:35:41 +01:00
|
|
|
if let icon = IconSelectorView.Icon(rawValue: UIApplication.shared.alternateIconName ?? "AppIcon") {
|
|
|
|
Image(uiImage: .init(named: icon.iconName)!)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-23 16:21:31 +01:00
|
|
|
Link(destination: URL(string: "https://github.com/Dimillian/IceCubesApp")!) {
|
|
|
|
Text("https://github.com/Dimillian/IceCubesApp")
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-29 10:39:34 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
private var addAccountButton: some View {
|
2022-12-01 09:05:26 +01:00
|
|
|
Button {
|
2022-12-29 14:07:58 +01:00
|
|
|
addAccountSheetPresented.toggle()
|
2022-12-01 09:05:26 +01:00
|
|
|
} label: {
|
2022-12-29 14:07:58 +01:00
|
|
|
Text("Add account")
|
|
|
|
}
|
|
|
|
.sheet(isPresented: $addAccountSheetPresented) {
|
|
|
|
AddAccountView()
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var signOutButton: some View {
|
|
|
|
Button {
|
|
|
|
appAccountsManager.delete(account: appAccountsManager.currentAccount)
|
|
|
|
} label: {
|
|
|
|
Text("Sign out").foregroundColor(.red)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|