|
|
|
|
@ -17,16 +17,16 @@ class BoringContext : ObservableObject { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct ContentView: View { |
|
|
|
|
struct ContentView<T : AbstractTimer>: View { |
|
|
|
|
|
|
|
|
|
@EnvironmentObject var boringContext: BoringContext |
|
|
|
|
@StateObject var boringContext: BoringContext = BoringContext() |
|
|
|
|
|
|
|
|
|
@Environment(\.managedObjectContext) private var viewContext |
|
|
|
|
|
|
|
|
|
@FetchRequest( |
|
|
|
|
sortDescriptors: [NSSortDescriptor(keyPath: \AbstractTimer.order, ascending: true)], |
|
|
|
|
sortDescriptors: [NSSortDescriptor(keyPath: \T.order, ascending: true)], |
|
|
|
|
animation: .default) |
|
|
|
|
private var timers: FetchedResults<AbstractTimer> |
|
|
|
|
private var timers: FetchedResults<T> |
|
|
|
|
|
|
|
|
|
fileprivate let itemSpacing: CGFloat = 10.0 |
|
|
|
|
|
|
|
|
|
@ -35,7 +35,7 @@ struct ContentView: View { |
|
|
|
|
GridItem(spacing: 10.0), |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
var timersArray: [AbstractTimer] { |
|
|
|
|
var timersArray: [T] { |
|
|
|
|
return Array(timers) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -61,7 +61,7 @@ struct ContentView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}.padding(itemSpacing) |
|
|
|
|
.navigationTitle("Youpi") |
|
|
|
|
.navigationTitle("\(String(describing: T.self))") |
|
|
|
|
.alert(boringContext.error?.localizedDescription ?? "missing error", isPresented: $boringContext.showDefaultAlert) { |
|
|
|
|
Button("OK", role: .cancel) { } |
|
|
|
|
} |
|
|
|
|
@ -69,23 +69,23 @@ struct ContentView: View { |
|
|
|
|
PermissionAlertView() |
|
|
|
|
} |
|
|
|
|
.sheet(isPresented: $boringContext.isShowingNewData, content: { |
|
|
|
|
NewCountdownView(isPresented: $boringContext.isShowingNewData) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
}) |
|
|
|
|
.sheet(isPresented: $boringContext.isShowingNewData, content: { |
|
|
|
|
NewStopwatchView(isPresented: $boringContext.isShowingNewData) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
}) |
|
|
|
|
.sheet(isPresented: $boringContext.isShowingNewData, content: { |
|
|
|
|
NewAlarmView(isPresented: $boringContext.isShowingNewData) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
self._newView(isPresented: $boringContext.isShowingNewData) |
|
|
|
|
.environment(\.managedObjectContext, viewContext) |
|
|
|
|
}) |
|
|
|
|
// .sheet(isPresented: $boringContext.isShowingNewData, content: { |
|
|
|
|
// NewStopwatchView(isPresented: $boringContext.isShowingNewData) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
// }) |
|
|
|
|
// .sheet(isPresented: $boringContext.isShowingNewData, content: { |
|
|
|
|
// NewAlarmView(isPresented: $boringContext.isShowingNewData) .environment(\.managedObjectContext, viewContext) |
|
|
|
|
// }) |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItemGroup(placement: .bottomBar) { |
|
|
|
|
MainToolbarView(isShowingNewData: $boringContext.isShowingNewData) |
|
|
|
|
} |
|
|
|
|
ToolbarItem(placement: .navigationBarTrailing) { |
|
|
|
|
NavigationLink { |
|
|
|
|
RecordsView() |
|
|
|
|
Button { |
|
|
|
|
self.boringContext.isShowingNewData = true |
|
|
|
|
} label: { |
|
|
|
|
Image(systemName: "chart.bar.fill") |
|
|
|
|
HStack { |
|
|
|
|
Image(systemName: "plus") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) { |
|
|
|
|
@ -102,6 +102,21 @@ struct ContentView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ViewBuilder |
|
|
|
|
fileprivate func _newView(isPresented: Binding<Bool>) -> some View { |
|
|
|
|
switch T.self { |
|
|
|
|
case is Countdown.Type: |
|
|
|
|
NewCountdownView(isPresented: isPresented) |
|
|
|
|
case is Alarm.Type: |
|
|
|
|
NewAlarmView(isPresented: isPresented) |
|
|
|
|
case is Stopwatch.Type: |
|
|
|
|
NewStopwatchView(isPresented: isPresented) |
|
|
|
|
default: |
|
|
|
|
Text("missing new view") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _reorder(from: IndexSet, to: Int) { |
|
|
|
|
var timers: [AbstractTimer] = self.timersArray |
|
|
|
|
@ -207,6 +222,6 @@ fileprivate extension Countdown { |
|
|
|
|
|
|
|
|
|
struct ContentView_Previews: PreviewProvider { |
|
|
|
|
static var previews: some View { |
|
|
|
|
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
|
|
|
|
ContentView<Countdown>().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|