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 17:22:07 +01:00
|
|
|
struct SettingsTabs: View {
|
2022-12-01 09:05:26 +01:00
|
|
|
@EnvironmentObject private var client: Client
|
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
|
|
|
|
2023-01-01 09:19:00 +01:00
|
|
|
@StateObject private var routeurPath = RouterPath()
|
|
|
|
|
2022-12-29 14:07:58 +01:00
|
|
|
@State private var addAccountSheetPresented = false
|
2023-01-03 14:42:09 +01:00
|
|
|
@State private var isThemeSelectorPresented = false
|
2022-12-01 09:05:26 +01:00
|
|
|
|
|
|
|
var body: some View {
|
2023-01-04 12:50:57 +01:00
|
|
|
NavigationStack(path: $routeurPath.path) {
|
2022-12-01 09:05:26 +01:00
|
|
|
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)
|
2023-01-02 17:18:16 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor, for: .navigationBar)
|
2022-12-01 09:05:26 +01:00
|
|
|
}
|
2023-01-01 09:19:00 +01:00
|
|
|
.onAppear {
|
|
|
|
routeurPath.client = client
|
|
|
|
}
|
2022-12-01 09:05:26 +01:00
|
|
|
.task {
|
|
|
|
if appAccountsManager.currentAccount.oauthToken != nil {
|
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-30 10:11:05 +01:00
|
|
|
Section("Accounts") {
|
2022-12-30 08:36:22 +01:00
|
|
|
ForEach(appAccountsManager.availableAccounts) { account in
|
2022-12-29 07:00:00 +01:00
|
|
|
HStack {
|
2022-12-30 08:36:22 +01:00
|
|
|
AppAccountView(viewModel: .init(appAccount: account))
|
|
|
|
}
|
|
|
|
.onTapGesture {
|
|
|
|
withAnimation {
|
|
|
|
appAccountsManager.currentAccount = account
|
2022-12-29 07:00:00 +01:00
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
2022-12-30 08:36:22 +01:00
|
|
|
}
|
|
|
|
.onDelete { indexSet in
|
|
|
|
if let index = indexSet.first {
|
|
|
|
let account = appAccountsManager.availableAccounts[index]
|
|
|
|
appAccountsManager.delete(account: account)
|
|
|
|
}
|
2022-12-04 09:50:25 +01:00
|
|
|
}
|
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") {
|
2023-01-03 14:42:09 +01:00
|
|
|
themeSelectorButton
|
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-31 12:29:19 +01:00
|
|
|
Picker("Avatar position", selection: $theme.avatarPosition) {
|
|
|
|
ForEach(Theme.AvatarPosition.allCases, id: \.rawValue) { position in
|
|
|
|
Text(position.description).tag(position)
|
|
|
|
}
|
|
|
|
}
|
2022-12-24 14:55:04 +01:00
|
|
|
Button {
|
2023-01-02 17:18:16 +01:00
|
|
|
theme.selectedSet = .iceCubeDark
|
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-31 14:01:00 +01:00
|
|
|
if let icon = IconSelectorView.Icon(string: UIApplication.shared.alternateIconName ?? "AppIcon") {
|
2022-12-27 21:35:41 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 14:42:09 +01:00
|
|
|
private var themeSelectorButton: some View {
|
|
|
|
NavigationLink(destination: ThemePreviewView()) {
|
|
|
|
Button {
|
|
|
|
isThemeSelectorPresented.toggle()
|
|
|
|
} label: {
|
|
|
|
HStack {
|
|
|
|
Text("Theme")
|
|
|
|
Spacer()
|
|
|
|
Text(theme.selectedSet.rawValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|