132 lines
4.2 KiB
Swift
132 lines
4.2 KiB
Swift
//
|
|
// Miniplayer.swift
|
|
// WorkoutsPlus
|
|
//
|
|
// Created by Felix Förtsch on 07.09.24.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftData
|
|
|
|
// Maybe: https://github.com/LeoNatan/LNPopupController/tree/master
|
|
// TODO:The Miniplayer is the same view that we use for the Live Activity
|
|
// .safeAreaInset(edge: .bottom) { }
|
|
struct MiniPlayer: View {
|
|
@Environment(WorkoutStateManager.self) private var workoutStateManager
|
|
|
|
// @Query private var workouts: [Workout]
|
|
|
|
@State private var isFullScreenCoverPresented = false
|
|
@State private var workout = Workout.sampleData
|
|
@State private var workoutSession: WorkoutSession?
|
|
|
|
var body: some View {
|
|
Group {
|
|
if (workoutStateManager.isWorkoutInProgress) {
|
|
Button(action: {
|
|
withAnimation() { isFullScreenCoverPresented.toggle() }}) {
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
Text("8x Push-ups")
|
|
.font(.headline)
|
|
Text("Recommended Routine - 35 minutes")
|
|
.font(.subheadline)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
Spacer()
|
|
// TODO: Maybe replace it with a clock
|
|
Button(action: {
|
|
withAnimation() {
|
|
// TODO: This button has to do something with the workout (pause it, next exercise, etc)
|
|
|
|
}}) {
|
|
Image(systemName: "pause.circle.fill")
|
|
.font(.title)
|
|
.symbolRenderingMode(.palette)
|
|
.foregroundStyle(.white, .orange)
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
.buttonStyle(.plain)
|
|
.fullScreenCover(isPresented: $isFullScreenCoverPresented) {
|
|
// ActiveWorkoutSession(workout: workout, workoutSession: workoutSession)
|
|
}
|
|
} else {
|
|
Button(action: {
|
|
withAnimation() { isFullScreenCoverPresented.toggle() }}) {
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
Text("Start Workout")
|
|
.font(.headline)
|
|
// TODO: Replace this with the upcoming/planned workout
|
|
// Text(selectedWorkoutId)
|
|
// .font(.subheadline)
|
|
// .foregroundColor(.secondary)
|
|
}
|
|
Spacer()
|
|
Button(action: {
|
|
withAnimation() {
|
|
// TODO: This button "quick starts" the workout (skips over the ActiveWorkoutSession fullscreen cover)
|
|
// if let workoutId = selectedWorkoutId {
|
|
// If you selectedWorkoutId is set, get the corresponding workout. This idea is generally okay, but feels off (DRY?)
|
|
// workout = workouts.filter({ $0.id == UUID(uuidString: workoutId) }).first
|
|
// }
|
|
|
|
}}) {
|
|
Image(systemName: "play.circle.fill")
|
|
.font(.title)
|
|
.symbolRenderingMode(.palette)
|
|
.foregroundStyle(.white, .green)
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
.buttonStyle(.plain)
|
|
.fullScreenCover(isPresented: $isFullScreenCoverPresented) {
|
|
// ActiveWorkoutSession(workout: workout, workoutSession: workoutSession)
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
.frame(maxWidth: .infinity, maxHeight: 60)
|
|
.background(Color(.secondarySystemBackground))
|
|
.cornerRadius(12)
|
|
.shadow(radius: 10)
|
|
.padding(.horizontal)
|
|
// .padding(.bottom, 65)
|
|
}
|
|
}
|
|
|
|
|
|
#Preview {
|
|
@Previewable @State var stateManager = WorkoutStateManager(modelContext: SampleData.shared.modelContainer.mainContext)
|
|
|
|
ZStack(alignment: .bottom) {
|
|
TabView {
|
|
List {
|
|
Button(action: {}) {
|
|
Text("Toggle")
|
|
}
|
|
ForEach(0..<20) { _ in
|
|
Text("An item")
|
|
}
|
|
}
|
|
.tabItem {
|
|
Image(systemName: "calendar.badge.clock")
|
|
Text("Plans & Goals")
|
|
}
|
|
Text("Dummy")
|
|
.tabItem {
|
|
Image(systemName: "calendar.badge.clock")
|
|
Text("Plans & Goals")
|
|
}
|
|
}
|
|
}
|
|
.safeAreaInset(edge: .bottom) {
|
|
MiniPlayer()
|
|
}
|
|
.modelContainer(SampleData.shared.modelContainer)
|
|
.environment(stateManager)
|
|
}
|