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. 20
      LeCountdown/Views/HomeView.swift
  5. 7
      LeCountdown/Views/NewDataView.swift
  6. 40
      LeCountdown/Views/PresetsView.swift
  7. 21
      LeCountdown/Views/Stopwatch/NewStopwatchView.swift

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

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

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

@ -11,31 +11,45 @@ struct CompactHomeView: View {
@Environment(\.managedObjectContext) private var viewContext @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 { var body: some View {
NavigationStack {
TabView(selection: $tabSelection) { TabView(selection: $tabSelection) {
NavigationStack {
PresetsView(tabSelection: $tabSelection) PresetsView(tabSelection: $tabSelection)
.environment(\.managedObjectContext, viewContext) .environment(\.managedObjectContext, viewContext)
.tabItem { Label("Presets", systemImage: "globe") } .tabItem { Label("Presets", systemImage: "globe") }
.tag(0) .tag(0)
}
NavigationStack {
ContentView<AbstractTimer>() ContentView<AbstractTimer>()
.environment(\.managedObjectContext, viewContext) .environment(\.managedObjectContext, viewContext)
.environmentObject(Conductor.maestro) .environmentObject(Conductor.maestro)
.tabItem { Label("Home", systemImage: "clock.fill") } .tabItem { Label("Home", systemImage: "clock.fill") }
.tag(1) .tag(1)
}
NavigationStack {
ActivitiesView() ActivitiesView()
.environment(\.managedObjectContext, viewContext) .environment(\.managedObjectContext, viewContext)
.tabItem { Label("Stats", systemImage: "chart.bar.fill") } .tabItem { Label("Stats", systemImage: "chart.bar.fill") }
.tag(2) .tag(2)
} }
}
.tabViewStyle(.page) .tabViewStyle(.page)
.onOpenURL { _ in .onAppear {
if self.timers.count > 0 {
self.tabSelection = 1 self.tabSelection = 1
} }
} }
.onOpenURL { _ in
self.tabSelection = 1
}
} }
} }

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

@ -153,6 +153,9 @@ struct PresetsView: View {
@State var isPresented: Bool = false @State var isPresented: Bool = false
@State var isShowingNewCountdown = false
@State var isShowingNewStopwatch = false
var tabSelection: Binding<Int> var tabSelection: Binding<Int>
fileprivate func _columnCount() -> Int { fileprivate func _columnCount() -> Int {
@ -175,10 +178,35 @@ struct PresetsView: View {
ScrollView { ScrollView {
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") Text("You can edit the duration, sound and label before adding")
.padding()
.font(.callout) .font(.callout)
}.padding(.horizontal)
LazyVGrid( LazyVGrid(
columns: self._columns(), columns: self._columns(),
spacing: 10.0 spacing: 10.0
@ -209,11 +237,19 @@ struct PresetsView: View {
Spacer() 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: { .sheet(isPresented: $isPresented, content: {
CountdownEditView(isPresented: $isPresented, preset: self.model.selectedPreset, tabSelection: self.tabSelection) CountdownEditView(isPresented: $isPresented, preset: self.model.selectedPreset, tabSelection: self.tabSelection)
.environment(\.managedObjectContext, viewContext) .environment(\.managedObjectContext, viewContext)
}) })
.navigationTitle("Presets") .navigationTitle("Create")
} }
} }

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

Loading…
Cancel
Save