Data creation is moved to the presets

release
Laurent 3 years ago
parent 5681991ece
commit 2dfa0c9e9b
  1. 50
      LeCountdown/Views/ContentView.swift
  2. 13
      LeCountdown/Views/Countdown/NewCountdownView.swift
  3. 2
      LeCountdown/Views/DialView.swift
  4. 40
      LeCountdown/Views/HomeView.swift
  5. 9
      LeCountdown/Views/NewDataView.swift
  6. 44
      LeCountdown/Views/PresetsView.swift
  7. 21
      LeCountdown/Views/Stopwatch/NewStopwatchView.swift

@ -143,19 +143,19 @@ struct ContentView<T : AbstractTimer>: View {
PermissionAlertView()
}
.sheet(isPresented: $boringContext.isShowingNewData, content: {
self._newView(isPresented: $boringContext.isShowingNewData)
.environment(\.managedObjectContext, viewContext)
// self._newView(isPresented: $boringContext.isShowingNewData)
// .environment(\.managedObjectContext, viewContext)
})
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
self.boringContext.isShowingNewData = true
} label: {
HStack {
Image(systemName: "plus")
}
}
}
// ToolbarItem(placement: .navigationBarTrailing) {
// Button {
// self.boringContext.isShowingNewData = true
// } label: {
// HStack {
// Image(systemName: "plus")
// }
// }
// }
ToolbarItem(placement: .navigationBarLeading) {
Button {
withAnimation {
@ -232,20 +232,20 @@ struct ContentView<T : AbstractTimer>: View {
// MARK: - Subviews
@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:
NewDataView(isPresented: isPresented)
}
}
// @ViewBuilder
// fileprivate func _newView(isPresented: Binding<Bool>) -> some View {
// switch T.self {
// case is Countdown.Type:
// NewCountdownView(isPresented: isPresented, tabSelection: self.tabse)
// case is Alarm.Type:
// NewAlarmView(isPresented: isPresented)
// case is Stopwatch.Type:
// NewStopwatchView(isPresented: isPresented, tabSelection: <#Binding<Int>#>)
// default:
// NewDataView(isPresented: isPresented, tabSelection: <#Binding<Int>#>)
// }
//
// }
// MARK: - Business

@ -14,9 +14,15 @@ struct NewCountdownView : View {
@Environment(\.managedObjectContext) private var viewContext
@Binding var isPresented: Bool
var tabSelection: Binding<Int>
init(isPresented: Binding<Bool>, tabSelection: Binding<Int>) {
_isPresented = isPresented
self.tabSelection = tabSelection
}
var body: some View {
CountdownEditView(isPresented: $isPresented)
CountdownEditView(isPresented: $isPresented, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext)
.navigationTitle("New countdown")
}
@ -61,9 +67,10 @@ struct CountdownEditView : View {
@Environment(\.isPresented) var envIsPresented
init(isPresented: Binding<Bool>, countdown: Countdown? = nil) {
init(isPresented: Binding<Bool>, countdown: Countdown? = nil, tabSelection: Binding<Int>? = nil) {
_isPresented = isPresented
self.countdown = countdown
self.tabSelection = tabSelection
}
init(isPresented: Binding<Bool>, preset: Preset, tabSelection: Binding<Int>) {
@ -320,7 +327,7 @@ struct CountdownEditView : View {
struct NewCountdownView_Previews: PreviewProvider {
static var previews: some View {
NewCountdownView(isPresented: .constant(true))
NewCountdownView(isPresented: .constant(true), tabSelection: .constant(0))
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}

@ -117,7 +117,7 @@ struct DialView: View {
AlarmEditView(alarm: alarm, isPresented: isPresented)
.environment(\.managedObjectContext, viewContext)
case let stopwatch as Stopwatch:
StopwatchEditView(stopwatch: stopwatch, isPresented: isPresented)
StopwatchEditView(isPresented: isPresented, stopwatch: stopwatch)
.environment(\.managedObjectContext, viewContext)
default:
Text("missing edit view")

@ -11,31 +11,45 @@ struct CompactHomeView: View {
@Environment(\.managedObjectContext) private var viewContext
@State private var tabSelection: Int = 1
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \AbstractTimer.order, ascending: true)],
animation: .default)
private var timers: FetchedResults<AbstractTimer>
@State private var tabSelection: Int = 0
var body: some View {
NavigationStack {
TabView(selection: $tabSelection) {
PresetsView(tabSelection: $tabSelection)
.environment(\.managedObjectContext, viewContext)
.tabItem { Label("Presets", systemImage: "globe") }
NavigationStack {
PresetsView(tabSelection: $tabSelection)
.environment(\.managedObjectContext, viewContext)
.tabItem { Label("Presets", systemImage: "globe") }
.tag(0)
ContentView<AbstractTimer>()
.environment(\.managedObjectContext, viewContext)
.environmentObject(Conductor.maestro)
.tabItem { Label("Home", systemImage: "clock.fill") }
}
NavigationStack {
ContentView<AbstractTimer>()
.environment(\.managedObjectContext, viewContext)
.environmentObject(Conductor.maestro)
.tabItem { Label("Home", systemImage: "clock.fill") }
.tag(1)
ActivitiesView()
.environment(\.managedObjectContext, viewContext)
.tabItem { Label("Stats", systemImage: "chart.bar.fill") }
}
NavigationStack {
ActivitiesView()
.environment(\.managedObjectContext, viewContext)
.tabItem { Label("Stats", systemImage: "chart.bar.fill") }
.tag(2)
}
}
.tabViewStyle(.page)
.onAppear {
if self.timers.count > 0 {
self.tabSelection = 1
}
}
.onOpenURL { _ in
self.tabSelection = 1
}
}
}
}

@ -28,7 +28,8 @@ struct NewDataView: View {
@Environment(\.managedObjectContext) private var viewContext
@Binding var isPresented: Bool
var tabSelection: Binding<Int>
@State var selection: Int = 0
var body: some View {
@ -46,10 +47,10 @@ struct NewDataView: View {
.padding(.horizontal)
TabView(selection: $selection) {
NewCountdownView(isPresented: $isPresented)
NewCountdownView(isPresented: $isPresented, tabSelection: self.tabSelection)
.tag(0)
.environment(\.managedObjectContext, viewContext)
NewStopwatchView(isPresented: $isPresented)
NewStopwatchView(isPresented: $isPresented, tabSelection: self.tabSelection)
.tag(1)
.environment(\.managedObjectContext, viewContext)
}.tabViewStyle(.page(indexDisplayMode: .never))
@ -61,7 +62,7 @@ struct NewDataView: View {
struct NewDataView_Previews: PreviewProvider {
static var previews: some View {
NewDataView(isPresented: .constant(true))
NewDataView(isPresented: .constant(true), tabSelection: .constant(0))
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}

@ -153,6 +153,9 @@ struct PresetsView: View {
@State var isPresented: Bool = false
@State var isShowingNewCountdown = false
@State var isShowingNewStopwatch = false
var tabSelection: Binding<Int>
fileprivate func _columnCount() -> Int {
@ -175,9 +178,34 @@ struct PresetsView: View {
ScrollView {
Text("You can edit the duration, sound and label before adding")
.padding()
.font(.callout)
VStack(alignment: .leading, spacing: 0.0) {
Button {
self.isShowingNewCountdown = true
} label: {
Text(".create countdown")
.font(.system(.title, weight: .heavy))
Spacer()
}.frame(height: 40.0)
Button {
self.isShowingNewStopwatch = true
} label: {
Text(".create stopwatch")
.font(.system(.title, weight: .heavy))
Spacer()
}.frame(height: 40.0)
Text("You can ask Siri to create and launch countdowns and stopwatches")
.font(.callout)
.padding(.vertical)
Text("Presets")
.font(.system(.title, weight: .heavy))
Text("You can edit the duration, sound and label before adding")
.font(.callout)
}.padding(.horizontal)
LazyVGrid(
columns: self._columns(),
@ -209,11 +237,19 @@ struct PresetsView: View {
Spacer()
}
.sheet(isPresented: $isShowingNewStopwatch, content: {
NewStopwatchView(isPresented: $isShowingNewStopwatch, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext)
})
.sheet(isPresented: $isShowingNewCountdown, content: {
NewCountdownView(isPresented: $isShowingNewCountdown, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext)
})
.sheet(isPresented: $isPresented, content: {
CountdownEditView(isPresented: $isPresented, preset: self.model.selectedPreset, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext)
})
.navigationTitle("Presets")
.navigationTitle("Create")
}
}

@ -14,9 +14,15 @@ struct NewStopwatchView: View {
@Environment(\.managedObjectContext) private var viewContext
@Binding var isPresented: Bool
var tabSelection: Binding<Int>
init(isPresented: Binding<Bool>, tabSelection: Binding<Int>) {
_isPresented = isPresented
self.tabSelection = tabSelection
}
var body: some View {
StopwatchEditView(isPresented: $isPresented)
StopwatchEditView(isPresented: $isPresented, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext)
.navigationTitle("New stopwatch")
}
@ -52,10 +58,18 @@ struct StopwatchEditView: View {
@State var _isAdding: Bool = false
@Environment(\.isPresented) var envIsPresented
var tabSelection: Binding<Int>? = nil
@FetchRequest(sortDescriptors: [])
private var timers: FetchedResults<AbstractTimer>
init(isPresented: Binding<Bool>, stopwatch: Stopwatch? = nil, tabSelection: Binding<Int>? = nil) {
_isPresented = isPresented
self.stopwatch = stopwatch
self.tabSelection = tabSelection
}
var body: some View {
NavigationStack {
Rectangle()
@ -270,6 +284,9 @@ struct StopwatchEditView: View {
} else {
dismiss()
}
self.tabSelection?.wrappedValue = 1
}
fileprivate func _delete() {
@ -300,7 +317,7 @@ struct StopwatchEditView: View {
struct NewStopwatchView_Previews: PreviewProvider {
static var previews: some View {
NewStopwatchView(isPresented: .constant(true))
NewStopwatchView(isPresented: .constant(true), tabSelection: .constant(0))
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}

Loading…
Cancel
Save