parent
a23cf012c8
commit
f1e082e3e9
@ -0,0 +1,38 @@ |
|||||||
|
// |
||||||
|
// AppleMusicPlayer.swift |
||||||
|
// LeCountdown |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 13/02/2023. |
||||||
|
// |
||||||
|
|
||||||
|
import Foundation |
||||||
|
import MediaPlayer |
||||||
|
|
||||||
|
@objc class AppleMusicPlayer : NSObject, MPMediaPickerControllerDelegate { |
||||||
|
|
||||||
|
// func play() { |
||||||
|
// |
||||||
|
// let musicPlayer = MPMusicPlayerApplicationController.applicationQueuePlayer |
||||||
|
// musicPlayer.setQueue(with: .songs()) |
||||||
|
// |
||||||
|
// } |
||||||
|
// |
||||||
|
// func showMediaPicker(source: UIView) { |
||||||
|
// let controller = MPMediaPickerController(mediaTypes: .music) |
||||||
|
// controller.allowsPickingMultipleItems = true |
||||||
|
// controller.popoverPresentationController?.sourceView = source |
||||||
|
// controller.delegate = self |
||||||
|
//// present(controller, animated: true) |
||||||
|
// } |
||||||
|
// |
||||||
|
// func mediaPicker(_ mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) { |
||||||
|
// |
||||||
|
// |
||||||
|
//// let p = MPMediaItemCollection(items: [MPMediaItem]) |
||||||
|
// |
||||||
|
// let i = MPMediaItem() |
||||||
|
// i. |
||||||
|
// |
||||||
|
// } |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,67 @@ |
|||||||
|
// |
||||||
|
// NewDataView.swift |
||||||
|
// LeCountdown |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 13/02/2023. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
enum DataTab: Int, Identifiable, CaseIterable { |
||||||
|
|
||||||
|
case countdown |
||||||
|
case stopwatch |
||||||
|
|
||||||
|
var id: Int { return self.rawValue } |
||||||
|
|
||||||
|
var localizedString: String { |
||||||
|
switch self { |
||||||
|
case .countdown: return NSLocalizedString("Coundown", comment: "") |
||||||
|
case .stopwatch: return NSLocalizedString("Stopwatch", comment: "") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
struct NewDataView: View { |
||||||
|
|
||||||
|
@Environment(\.managedObjectContext) private var viewContext |
||||||
|
|
||||||
|
@Binding var isPresented: Bool |
||||||
|
|
||||||
|
@State var selection: Int = 0 |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
|
||||||
|
NavigationStack { |
||||||
|
|
||||||
|
VStack { |
||||||
|
|
||||||
|
Picker("", selection: $selection) { |
||||||
|
ForEach(DataTab.allCases) { tab in |
||||||
|
Text(tab.localizedString) |
||||||
|
} |
||||||
|
} |
||||||
|
.pickerStyle(.segmented) |
||||||
|
.padding() |
||||||
|
|
||||||
|
TabView(selection: $selection) { |
||||||
|
NewCountdownView(isPresented: $isPresented) |
||||||
|
.tag(0) |
||||||
|
.environment(\.managedObjectContext, viewContext) |
||||||
|
NewStopwatchView(isPresented: $isPresented) |
||||||
|
.tag(1) |
||||||
|
.environment(\.managedObjectContext, viewContext) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct NewDataView_Previews: PreviewProvider { |
||||||
|
static var previews: some View { |
||||||
|
NewDataView(isPresented: .constant(true)) |
||||||
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,116 @@ |
|||||||
|
// |
||||||
|
// PresetsView.swift |
||||||
|
// LeCountdown |
||||||
|
// |
||||||
|
// Created by Laurent Morvillier on 13/02/2023. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
enum PresetSection: Int, Identifiable, CaseIterable { |
||||||
|
var id: Int { return self.rawValue } |
||||||
|
|
||||||
|
case cooking |
||||||
|
case workout |
||||||
|
case meditation |
||||||
|
|
||||||
|
var presets: [Preset] { |
||||||
|
switch self { |
||||||
|
case .cooking: return [.softBoiled, .mediumBoiledEggs, .hardBoiledEggs] |
||||||
|
case .workout: return [] |
||||||
|
case .meditation: return [] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var localizedName: String { |
||||||
|
switch self { |
||||||
|
case .cooking: return NSLocalizedString("Cooking", comment: "") |
||||||
|
case .workout: return NSLocalizedString("Workout", comment: "") |
||||||
|
case .meditation: return NSLocalizedString("Meditation", comment: "") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
enum Preset: Int, Identifiable, CaseIterable { |
||||||
|
var id: Int { return self.rawValue } |
||||||
|
|
||||||
|
case softBoiled |
||||||
|
case mediumBoiledEggs |
||||||
|
case hardBoiledEggs |
||||||
|
|
||||||
|
var localizedName: String { |
||||||
|
switch self { |
||||||
|
case .hardBoiledEggs: return NSLocalizedString("Hard boiled eggs", comment: "") |
||||||
|
case .softBoiled: return NSLocalizedString("Soft boiled eggs", comment: "") |
||||||
|
case .mediumBoiledEggs: return NSLocalizedString("Medium boiled eggs", comment: "") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var duration: TimeInterval { |
||||||
|
switch self { |
||||||
|
case .softBoiled: return 3 * 60 |
||||||
|
case .mediumBoiledEggs: return 6 * 60 |
||||||
|
case .hardBoiledEggs: return 10 * 60 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var sound: Set<Sound> { |
||||||
|
switch self { |
||||||
|
case .softBoiled: return [] |
||||||
|
case .mediumBoiledEggs: return [] |
||||||
|
case .hardBoiledEggs: return [] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
class PresetModel : ObservableObject { |
||||||
|
|
||||||
|
@Published var selectedPreset: Preset = Preset.hardBoiledEggs |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
struct PresetsView: View { |
||||||
|
|
||||||
|
@Environment(\.managedObjectContext) private var viewContext |
||||||
|
|
||||||
|
@StateObject var model: PresetModel = PresetModel() |
||||||
|
|
||||||
|
@State var isPresented: Bool = false |
||||||
|
|
||||||
|
var tabSelection: Binding<Int> |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
|
||||||
|
NavigationStack { |
||||||
|
List { |
||||||
|
ForEach(PresetSection.allCases) { section in |
||||||
|
Section(header: Text(section.localizedName)) { |
||||||
|
ForEach(section.presets) { preset in |
||||||
|
|
||||||
|
Button { |
||||||
|
self.model.selectedPreset = preset |
||||||
|
self.isPresented = true |
||||||
|
} label: { |
||||||
|
Text(preset.localizedName) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.sheet(isPresented: $isPresented, content: { |
||||||
|
CountdownEditView(isPresented: $isPresented, preset: self.model.selectedPreset, tabSelection: self.tabSelection) |
||||||
|
.environment(\.managedObjectContext, viewContext) |
||||||
|
}) |
||||||
|
.navigationTitle("Presets") |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct PresetsView_Previews: PreviewProvider { |
||||||
|
static var previews: some View { |
||||||
|
PresetsView(tabSelection: .constant(0)) |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue