mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 14:56:15 +00:00
forgot to commit 2.0, but just finished 3.0
3.0: home screen widgets small,med,large they auto refresh! major bug fixes inclluding past date handling past dates are now allowed 2.0: icloud sync ios required is 15, down from 18! auto icloud sync added icloud settings to manually push,pull or sync
This commit is contained in:
@@ -9,11 +9,64 @@ import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
@State var viewModel: EventViewModel
|
||||
@Binding var showSettings: Bool
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
@State private var hasUbiquitous: Bool = false
|
||||
@State private var lastSyncWasSuccessful: Bool = false
|
||||
@State private var lastSyncWasNormalAgo: Bool = false
|
||||
@State private var localCountEqualToiCloud: Bool = false
|
||||
@State private var icloudCountEqualToLocal: Bool = false
|
||||
|
||||
func updateStatus() {
|
||||
let vm = viewModel
|
||||
hasUbiquitous = vm.hasUbiquitousKeyValueStore()
|
||||
lastSyncWasSuccessful = vm.syncStatus.contains("Success")
|
||||
lastSyncWasNormalAgo = vm.lastSync?.timeIntervalSinceNow.isNormal ?? false
|
||||
localCountEqualToiCloud = vm.localEventCount == vm.icloudEventCount
|
||||
icloudCountEqualToLocal = vm.icloudEventCount == vm.localEventCount
|
||||
}
|
||||
|
||||
var iCloudStatusColor: Color {
|
||||
let allTrue = hasUbiquitous && lastSyncWasSuccessful && lastSyncWasNormalAgo && localCountEqualToiCloud && icloudCountEqualToLocal
|
||||
let someTrue = hasUbiquitous || lastSyncWasSuccessful || lastSyncWasNormalAgo || localCountEqualToiCloud || icloudCountEqualToLocal
|
||||
|
||||
if allTrue {
|
||||
return .green
|
||||
} else if someTrue {
|
||||
return .orange
|
||||
} else {
|
||||
return .red
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
NavigationView {
|
||||
List {
|
||||
NavigationLink() {
|
||||
iCloudSettingsView(
|
||||
viewModel: viewModel,
|
||||
hasUbiquitous: $hasUbiquitous,
|
||||
lastSyncWasSuccessful: $lastSyncWasSuccessful,
|
||||
lastSyncWasNormalAgo: $lastSyncWasNormalAgo,
|
||||
localCountEqualToiCloud: $localCountEqualToiCloud,
|
||||
icloudCountEqualToLocal: $icloudCountEqualToLocal,
|
||||
updateStatus: updateStatus
|
||||
)
|
||||
} label: {
|
||||
HStack {
|
||||
Image(systemName: "icloud.fill")
|
||||
Text("iCloud")
|
||||
Spacer()
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(iCloudStatusColor)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.sync()
|
||||
updateStatus()
|
||||
}
|
||||
|
||||
Section("Danger Zone") {
|
||||
Button("Delete local data", role: .destructive) {
|
||||
viewModel.dangerClearLocalData()
|
||||
@@ -40,7 +93,7 @@ struct SettingsView: View {
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button() {
|
||||
showSettings.toggle()
|
||||
dismiss()
|
||||
} label: {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
.symbolRenderingMode(.hierarchical)
|
||||
@@ -51,9 +104,171 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct iCloudSettingsView: View {
|
||||
@State var viewModel: EventViewModel
|
||||
@State var showPushAlert: Bool = false
|
||||
@State var showPullAlert: Bool = false
|
||||
|
||||
@Binding var hasUbiquitous: Bool
|
||||
@Binding var lastSyncWasSuccessful: Bool
|
||||
@Binding var lastSyncWasNormalAgo: Bool
|
||||
@Binding var localCountEqualToiCloud: Bool
|
||||
@Binding var icloudCountEqualToLocal: Bool
|
||||
|
||||
var updateStatus: () -> Void
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack {
|
||||
ZStack {
|
||||
Image(systemName: "icloud")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 75, height: 75)
|
||||
.symbolRenderingMode(.multicolor)
|
||||
Text("\(viewModel.icloudEventCount)")
|
||||
.font(.title2)
|
||||
}
|
||||
HStack {
|
||||
Button(role: .destructive) {
|
||||
showPushAlert.toggle()
|
||||
} label: {
|
||||
Image(systemName: "arrow.up")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 30, height: 40)
|
||||
}
|
||||
.buttonStyle(BorderedButtonStyle())
|
||||
.alert("Warning", isPresented: $showPushAlert) {
|
||||
Button("OK", role: .destructive) {
|
||||
viewModel.replaceiCloudWithLocalData()
|
||||
viewModel.sync()
|
||||
updateStatus()
|
||||
}
|
||||
Button("Cancel", role: .cancel) {}
|
||||
} message: {
|
||||
Text("This will replace Events stored in iCloud with Events stored locally.")
|
||||
}
|
||||
|
||||
Button() {
|
||||
viewModel.sync()
|
||||
updateStatus()
|
||||
} label: {
|
||||
Image(systemName: "arrow.triangle.2.circlepath")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 30, height: 40)
|
||||
.foregroundStyle(Color.accentColor)
|
||||
}
|
||||
.buttonStyle(BorderedButtonStyle())
|
||||
|
||||
Button(role: .destructive) {
|
||||
showPullAlert.toggle()
|
||||
} label: {
|
||||
Image(systemName: "arrow.down")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 30, height: 40)
|
||||
}
|
||||
.buttonStyle(BorderedButtonStyle())
|
||||
.alert("Warning", isPresented: $showPullAlert) {
|
||||
Button("OK", role: .destructive) {
|
||||
viewModel.replaceLocalWithiCloudData()
|
||||
viewModel.sync()
|
||||
updateStatus()
|
||||
}
|
||||
Button("Cancel", role: .cancel) {}
|
||||
} message: {
|
||||
Text("This will replace Events stored locally with Events stored in iCloud.")
|
||||
}
|
||||
}
|
||||
ZStack {
|
||||
Image(systemName: "iphone.gen3")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 75, height: 75)
|
||||
.symbolRenderingMode(.monochrome)
|
||||
Text("\(viewModel.localEventCount)")
|
||||
.font(.headline)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.sync()
|
||||
updateStatus()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(hasUbiquitous ? .green : .red)
|
||||
Text("iCloud Key Value Store:")
|
||||
Text("\(hasUbiquitous ? "" : "Not ")Working")
|
||||
.bold()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(lastSyncWasSuccessful ? .green : .red)
|
||||
Text("Sync Status:")
|
||||
Text("\(viewModel.syncStatus)")
|
||||
.bold()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(lastSyncWasNormalAgo ? .green : .red)
|
||||
Text("Last Sync:")
|
||||
Text("\(viewModel.lastSync?.formatted() ?? "Never")")
|
||||
.bold()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(localCountEqualToiCloud ? .green : .red)
|
||||
Text("\(viewModel.localEventCount)")
|
||||
.bold()
|
||||
Text("Local Events")
|
||||
}
|
||||
|
||||
HStack {
|
||||
Circle()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundStyle(icloudCountEqualToLocal ? .green : .red)
|
||||
Text("\(viewModel.icloudEventCount)")
|
||||
.bold()
|
||||
Text("Events in iCloud")
|
||||
}
|
||||
}
|
||||
.navigationTitle("iCloud")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SettingsView(
|
||||
viewModel: EventViewModel(),
|
||||
showSettings: .constant(true)
|
||||
viewModel: EventViewModel()
|
||||
)
|
||||
}
|
||||
|
||||
#Preview("iCloudSettingsView") {
|
||||
iCloudSettingsView(
|
||||
viewModel: EventViewModel(),
|
||||
hasUbiquitous: .constant(true),
|
||||
lastSyncWasSuccessful: .constant(true),
|
||||
lastSyncWasNormalAgo: .constant(true),
|
||||
localCountEqualToiCloud: .constant(true),
|
||||
icloudCountEqualToLocal: .constant(true),
|
||||
updateStatus: test
|
||||
)
|
||||
}
|
||||
|
||||
func test() -> Void {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user