Mixonomer-iOS/Mixonomer/Views/Settings/SettingsList.swift

134 lines
4.7 KiB
Swift
Raw Normal View History

//
// SettingsList.swift
2022-08-07 13:31:15 +01:00
// Mixonomer
//
// Created by Andy Pack on 20/02/2020.
// Copyright © 2020 Sarsoo. All rights reserved.
//
import SwiftUI
import KeychainAccess
struct SettingsList: View {
@EnvironmentObject var liveUser: LiveUser
2022-08-11 20:53:09 +01:00
@State private var deleteAlertShowing = false
var body: some View {
2022-08-16 18:01:17 +01:00
let spotify_link_bind = Binding<Bool>(get: { liveUser.user?.spotify_linked ?? false},
set: { newVal in liveUser.user?.spotify_linked = newVal })
// let lastfm_bind = Binding<String>(get: { liveUser.user?.lastfm_username ?? ""},
// set: { newVal in liveUser.user?.lastfm_username = newVal })
2022-08-16 18:01:17 +01:00
return NavigationView {
List{
Section {
Button(action: {
2022-08-07 19:34:14 +01:00
if let url = URL(string: "https://mixonomer.sarsoo.xyz") {
UIApplication.shared.open(url)
}
}) {
Text("Launch Web Version")
}
2022-08-12 11:21:54 +01:00
Button(action: {
if let url = URL(string: "https://mixonomer.sarsoo.xyz/privacy") {
UIApplication.shared.open(url)
}
}) {
Text("Privacy Policy")
}
Button(action: {
2022-08-11 20:53:09 +01:00
self.liveUser.logout()
}) {
Text("Log out")
}
}
Section(header: Text("Integrations")) {
2022-08-16 18:01:17 +01:00
Toggle(isOn: spotify_link_bind) {
Text("Spotify Link")
}
2022-08-16 18:01:17 +01:00
.disabled(true)
// NavigationLink("Last.fm Username") {
// List{
// TextField("Username", text: lastfm_bind)
// }
// }
2022-08-16 18:01:17 +01:00
}
// Section(header: Text("Last.fm")) {
// TextField("Last.fm Username", text: lastfm_bind)
// }
2022-08-11 20:53:09 +01:00
Section {
Button(action: {
deleteAlertShowing = true
}) {
Text("Delete Account")
.foregroundColor(.red)
}
.alert("Delete Account", isPresented: $deleteAlertShowing, actions: {
Button("Delete", role: .destructive) {
2022-08-11 20:53:09 +01:00
let api = UserApi.deleteUser
RequestBuilder.buildRequest(apiRequest: api).responseJSON{ response in
if self.liveUser.check_network_response(response: response) {
2022-08-11 20:53:09 +01:00
self.liveUser.logout()
}
else {
2022-08-11 20:53:09 +01:00
}
}
2022-08-11 20:53:09 +01:00
}
}, message: {
Text("This is irreversible, are you sure you want to delete your account?")
})
}
Section(
header:
Text("Development"),
footer:
HStack{
Spacer()
Image("APFooter")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 100.0)
Spacer()
}
) {
Button(action: {
2022-08-07 13:31:15 +01:00
if let url = URL(string: "https://github.com/sarsoo/Mixonomer") {
UIApplication.shared.open(url)
}
}) {
Text("Server Source")
}
Button(action: {
2022-08-07 13:31:15 +01:00
if let url = URL(string: "https://github.com/sarsoo/Mixonomer-ios") {
UIApplication.shared.open(url)
}
}) {
Text("iOS Source")
}
}
}
.listStyle(GroupedListStyle())
2022-08-11 20:53:09 +01:00
.navigationBarTitle(Text("Settings ⚡️"))
}
}
}
struct SettingsList_Previews: PreviewProvider {
static var previews: some View {
SettingsList()
2022-08-11 20:53:09 +01:00
.environmentObject(LiveUser(playlists: [], tags: [], username: "user", loggedIn: false))
}
}