add Miniplayer, ActiveWorkoutSession skeleton
This commit is contained in:
60
WorkoutsPlus/ActiveWorkout/ActiveWorkoutSession.swift
Normal file
60
WorkoutsPlus/ActiveWorkout/ActiveWorkoutSession.swift
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// ActiveWorkout.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 07.09.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ActiveWorkoutSession: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State var workout: Workout
|
||||
|
||||
@State var workoutSession: WorkoutSession?
|
||||
@State var currentExercise: Int = 0
|
||||
|
||||
let startDate = Date() - 100
|
||||
|
||||
@State private var currentTime = Date()
|
||||
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
||||
|
||||
var body: some View {
|
||||
Button("Close") { dismiss() }
|
||||
Text("\(workout.name)")
|
||||
Text("Elapsed Time: \(elapsedTimeText(startDate: startDate))")
|
||||
.onReceive(timer) { time in
|
||||
currentTime = time // Updates the current time every second
|
||||
}
|
||||
List {
|
||||
// TODO: Unwrap Sets
|
||||
ForEach(workout.workoutItems) { workoutItem in
|
||||
HStack {
|
||||
Text("\(workoutItem.reps)")
|
||||
Text("\(workoutItem.name)")
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
Image(systemName: "play.circle.fill")
|
||||
.resizable()
|
||||
.frame(width: 100, height: 100)
|
||||
.font(.title)
|
||||
.symbolRenderingMode(.palette)
|
||||
.foregroundStyle(.white, .green)
|
||||
|
||||
}
|
||||
|
||||
private func elapsedTimeText(startDate: Date) -> String {
|
||||
let elapsedTime = currentTime.timeIntervalSince(startDate)
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.allowedUnits = [.hour, .minute, .second]
|
||||
formatter.unitsStyle = .positional // For HH:mm:ss format
|
||||
return formatter.string(from: elapsedTime) ?? "00:00:00"
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ActiveWorkoutSession(workout: Workout.sampleData)
|
||||
}
|
||||
Reference in New Issue
Block a user