You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.5 KiB
108 lines
3.5 KiB
//
|
|
// SettingsView.swift
|
|
// LeCountdown
|
|
//
|
|
// Created by Laurent Morvillier on 10/03/2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
import MessageUI
|
|
|
|
struct SettingsView: View {
|
|
|
|
@State var confirmationSound = Preferences.playConfirmationSound
|
|
@State var raiseSoundOnLaunch = Preferences.raiseSoundOnLaunch
|
|
@State var cancellationSound = Preferences.playCancellationSound
|
|
@State var defaultVolume: Float = Preferences.defaultVolume
|
|
|
|
@State var showMailView: Bool = false
|
|
@State var showLogsSheet: Bool = false
|
|
@State var emailCopied: Bool = false
|
|
|
|
var body: some View {
|
|
|
|
Form {
|
|
Toggle("Play confirmation sound", isOn: self.$confirmationSound)
|
|
.onChange(of: self.confirmationSound) { newValue in
|
|
Preferences.playConfirmationSound = newValue
|
|
}
|
|
|
|
Toggle("Adjust volume on launch", isOn: self.$raiseSoundOnLaunch)
|
|
.onChange(of: self.raiseSoundOnLaunch) { newValue in
|
|
Preferences.raiseSoundOnLaunch = newValue
|
|
}
|
|
|
|
if self.raiseSoundOnLaunch {
|
|
HStack {
|
|
Text("Default Volume")
|
|
Spacer()
|
|
Slider(value: self.$defaultVolume)
|
|
.onChange(of: self.defaultVolume, perform: { newValue in
|
|
Preferences.defaultVolume = self.defaultVolume
|
|
})
|
|
.frame(width: 120.0)
|
|
}
|
|
}
|
|
|
|
if MFMailComposeViewController.canSendMail() {
|
|
Button {
|
|
self.showMailView = true
|
|
} label: {
|
|
Label("Contact us", systemImage: "mail")
|
|
}
|
|
} else {
|
|
if self.emailCopied {
|
|
Label("Copied", systemImage: "checkmark")
|
|
} else {
|
|
Button {
|
|
UIPasteboard.general.string = URLs.mail.rawValue
|
|
withAnimation {
|
|
self.emailCopied = true
|
|
}
|
|
} label: {
|
|
LabeledContent("Contact us", value: "tap to copy email")
|
|
}
|
|
}
|
|
}
|
|
ShareLink(item: URLs.appLink.rawValue) {
|
|
Label("Share app", systemImage: "square.and.arrow.up")
|
|
}
|
|
|
|
Button {
|
|
self._requestReview()
|
|
} label: {
|
|
Label("Write a review!", systemImage: "scribble")
|
|
}
|
|
|
|
Button {
|
|
withAnimation {
|
|
self.showLogsSheet.toggle()
|
|
}
|
|
} label: {
|
|
Text("Logs")
|
|
}
|
|
.sheet(isPresented: self.$showLogsSheet, content: {
|
|
NavigationStack {
|
|
LogsView().navigationTitle("Logs")
|
|
}
|
|
})
|
|
}.sheet(isPresented: $showMailView) {
|
|
MailView(isShowing: $showMailView)
|
|
}
|
|
.navigationTitle("Settings")
|
|
|
|
}
|
|
|
|
fileprivate func _requestReview() {
|
|
guard let writeReviewURL = URL(string: "https://apps.apple.com/app/id6446093767?action=write-review")
|
|
else { return }
|
|
UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil)
|
|
}
|
|
|
|
}
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
SettingsView()
|
|
}
|
|
}
|
|
|