mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 06:49:12 +00:00
basic settings done!!!
now can set accent color
This commit is contained in:
@@ -21,6 +21,7 @@ enum Tab {
|
|||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@StateObject var viewModel: EventViewModel
|
@StateObject var viewModel: EventViewModel
|
||||||
|
@StateObject var settingsModel: SettingsViewModel
|
||||||
@State private var eventName = ""
|
@State private var eventName = ""
|
||||||
@State private var eventComplete = false
|
@State private var eventComplete = false
|
||||||
@State private var eventCompleteDesc = ""
|
@State private var eventCompleteDesc = ""
|
||||||
@@ -140,7 +141,7 @@ struct ContentView: View {
|
|||||||
Label("Statistics", systemImage: "chart.pie")
|
Label("Statistics", systemImage: "chart.pie")
|
||||||
}
|
}
|
||||||
.focused($focusedTab, equals: Tab.Statistics)
|
.focused($focusedTab, equals: Tab.Statistics)
|
||||||
SettingsView(viewModel: viewModel)
|
SettingsView(viewModel: viewModel, settingsModel: settingsModel)
|
||||||
.tabItem {
|
.tabItem {
|
||||||
Label("Settings", systemImage: "gear")
|
Label("Settings", systemImage: "gear")
|
||||||
}
|
}
|
||||||
@@ -150,7 +151,10 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
ContentView(viewModel: dummyEventViewModel())
|
ContentView(
|
||||||
|
viewModel: dummyEventViewModel(),
|
||||||
|
settingsModel: dummySettingsViewModel()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SearchBar: View {
|
struct SearchBar: View {
|
||||||
|
|||||||
@@ -96,6 +96,40 @@ func daysUntilEvent(_ eventDate: Date) -> (long: String, short: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Settings: Codable, Equatable {
|
||||||
|
var showCompletedInHome: Bool
|
||||||
|
var tint: ColorCodable
|
||||||
|
}
|
||||||
|
|
||||||
|
class SettingsViewModel: ObservableObject {
|
||||||
|
@Published var settings: Settings = Settings(
|
||||||
|
showCompletedInHome: false,
|
||||||
|
tint: ColorCodable(.blue)
|
||||||
|
)
|
||||||
|
|
||||||
|
init(load: Bool = true) {
|
||||||
|
if load {
|
||||||
|
loadSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let appGroupSettingsStore = UserDefaults(suiteName: "group.NearFuture") ?? UserDefaults.standard
|
||||||
|
let icSettStore = NSUbiquitousKeyValueStore.default
|
||||||
|
|
||||||
|
func loadSettings() {
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
if let icSettings = icSettStore.data(forKey: "settings") {
|
||||||
|
if let decodedSetts = try? decoder.decode(Settings.self, from: icSettings) {
|
||||||
|
self.settings = decodedSetts
|
||||||
|
}
|
||||||
|
} else if let savedData = appGroupSettingsStore.data(forKey: "settings") {
|
||||||
|
if let decodedSetts = try? decoder.decode(Settings.self, from: savedData) {
|
||||||
|
self.settings = decodedSetts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class EventViewModel: ObservableObject {
|
class EventViewModel: ObservableObject {
|
||||||
@Published var events: [Event] = []
|
@Published var events: [Event] = []
|
||||||
@Published var icloudData: [Event] = []
|
@Published var icloudData: [Event] = []
|
||||||
@@ -308,6 +342,12 @@ class dummyEventViewModel: EventViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class dummySettingsViewModel: SettingsViewModel {
|
||||||
|
override init(load: Bool = false) {
|
||||||
|
super.init(load: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func describeOccurrence(date: Date, recurrence: Event.RecurrenceType) -> String {
|
func describeOccurrence(date: Date, recurrence: Event.RecurrenceType) -> String {
|
||||||
let dateString = date.formatted(date: .long, time: .omitted)
|
let dateString = date.formatted(date: .long, time: .omitted)
|
||||||
let recurrenceDescription: String
|
let recurrenceDescription: String
|
||||||
|
|||||||
@@ -22,10 +22,14 @@ struct NearFutureApp: App {
|
|||||||
// fatalError("Could not create ModelContainer: \(error)")
|
// fatalError("Could not create ModelContainer: \(error)")
|
||||||
// }
|
// }
|
||||||
// }()
|
// }()
|
||||||
|
@StateObject var settingsModel: SettingsViewModel = SettingsViewModel()
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView(viewModel: EventViewModel())
|
ContentView(
|
||||||
|
viewModel: EventViewModel(),
|
||||||
|
settingsModel: settingsModel
|
||||||
|
)
|
||||||
|
.tint(settingsModel.settings.tint.color)
|
||||||
}
|
}
|
||||||
// .modelContainer(sharedModelContainer)
|
// .modelContainer(sharedModelContainer)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct SettingsView: View {
|
struct SettingsView: View {
|
||||||
@ObservedObject var viewModel: EventViewModel
|
@ObservedObject var viewModel: EventViewModel
|
||||||
|
@ObservedObject var settingsModel: SettingsViewModel
|
||||||
|
|
||||||
@State private var hasUbiquitous: Bool = false
|
@State private var hasUbiquitous: Bool = false
|
||||||
@State private var lastSyncWasSuccessful: Bool = false
|
@State private var lastSyncWasSuccessful: Bool = false
|
||||||
@@ -38,12 +39,33 @@ struct SettingsView: View {
|
|||||||
return .red
|
return .red
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let rainbow = [
|
||||||
|
Color.red,
|
||||||
|
Color.orange,
|
||||||
|
Color.yellow,
|
||||||
|
Color.green,
|
||||||
|
Color.blue,
|
||||||
|
Color.indigo,
|
||||||
|
Color.purple
|
||||||
|
]
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ZStack {
|
ZStack {
|
||||||
backgroundGradient
|
backgroundGradient
|
||||||
List {
|
List {
|
||||||
|
ScrollView(.horizontal) {
|
||||||
|
HStack {
|
||||||
|
ForEach(rainbow, id: \.self) { color in
|
||||||
|
Button() {
|
||||||
|
settingsModel.settings.tint.colorBind = color
|
||||||
|
} label: {
|
||||||
|
Circle()
|
||||||
|
.foregroundStyle(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
NavigationLink() {
|
NavigationLink() {
|
||||||
iCloudSettingsView(
|
iCloudSettingsView(
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
@@ -121,5 +143,8 @@ struct SettingsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
SettingsView(viewModel: dummyEventViewModel())
|
SettingsView(
|
||||||
|
viewModel: dummyEventViewModel(),
|
||||||
|
settingsModel: dummySettingsViewModel()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user