164 lines
4.6 KiB
Go
164 lines
4.6 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"git.patanix.de/git/kettlebell-app/internal/data"
|
|
"git.patanix.de/git/kettlebell-app/internal/services"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/canvas"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"fyne.io/fyne/v2/theme"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
func MakeTrainingScreen(ts *services.TrainingService, ss *services.SettingsService, parent fyne.Window) fyne.CanvasObject {
|
|
programLabel := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
|
blockDayLabel := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{})
|
|
repsLabel := widget.NewLabelWithStyle("", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
|
|
|
timerLabel := widget.NewLabelWithStyle("00:00", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
|
|
|
progressBar := widget.NewProgressBar()
|
|
progressLabel := widget.NewLabelWithStyle("Fortschritt: 0%", fyne.TextAlignCenter, fyne.TextStyle{})
|
|
|
|
var startButton, setButton, finishButton *widget.Button
|
|
|
|
setHistoryList := widget.NewList(
|
|
func() int {
|
|
return len(ts.State.SetTimes)
|
|
},
|
|
func() fyne.CanvasObject {
|
|
return widget.NewLabel("")
|
|
},
|
|
func(id widget.ListItemID, obj fyne.CanvasObject) {
|
|
t := ts.State.SetTimes[id]
|
|
obj.(*widget.Label).SetText(fmt.Sprintf("#%d um %s (%d Reps)", id+1, t.Format("15:04:05"), ts.State.CurrentReps))
|
|
},
|
|
)
|
|
|
|
var mainTimer, lastSetTimer *time.Ticker
|
|
|
|
updateUI := func() {
|
|
state := ts.State
|
|
programLabel.SetText(state.CurrentProgram)
|
|
blockDayLabel.SetText(fmt.Sprintf("Block Tag: %d", state.CurrentBlockDay))
|
|
repsLabel.SetText(fmt.Sprintf("Reps pro Satz: %d", state.CurrentReps))
|
|
|
|
timerLabel.SetText(formatDuration(int64(state.RemainingSeconds)))
|
|
progressBar.SetValue(state.Progress)
|
|
progressLabel.SetText(fmt.Sprintf("Fortschritt: %.0f%%", state.Progress*100))
|
|
|
|
if state.IsTrainingRunning {
|
|
startButton.Disable()
|
|
setButton.Enable()
|
|
finishButton.Enable()
|
|
} else {
|
|
startButton.Enable()
|
|
setButton.Disable()
|
|
finishButton.Disable()
|
|
}
|
|
setHistoryList.Refresh()
|
|
}
|
|
|
|
stopTimers := func() {
|
|
if mainTimer != nil {
|
|
mainTimer.Stop()
|
|
mainTimer = nil
|
|
}
|
|
if lastSetTimer != nil {
|
|
lastSetTimer.Stop()
|
|
lastSetTimer = nil
|
|
}
|
|
}
|
|
|
|
// startAction := func() {
|
|
// settings := ss.LoadSettings()
|
|
// ts.StartTraining(settings.TrainingTimeMinutes, settings.GoalSets)
|
|
// updateUI()
|
|
//
|
|
// mainTimer = time.NewTicker(time.Second)
|
|
// go func() {
|
|
// for range mainTimer.C {
|
|
// if ts.State.RemainingSeconds <= 0 {
|
|
// stopTimers()
|
|
// fyne.CurrentApp().SendNotification(&fyne.Notification{
|
|
// Title: "Zeit abgelaufen!",
|
|
// Content: "Training wird automatisch gespeichert.",
|
|
// })
|
|
// finishButton.OnTapped()
|
|
// return
|
|
// }
|
|
// ts.Tick()
|
|
// updateUI()
|
|
// }
|
|
// }()
|
|
//
|
|
// lastSetTimer = time.NewTicker(time.Second)
|
|
// go func() {
|
|
// for range lastSetTimer.C {
|
|
// ts.TickLastSetTimer()
|
|
// }
|
|
// }()
|
|
// }
|
|
|
|
setAction := func() {
|
|
ts.CompleteSet()
|
|
fyne.CurrentApp().SendNotification(&fyne.Notification{Title: "Satz gespeichert!", Content: ""})
|
|
updateUI()
|
|
}
|
|
|
|
finishAction := func() {
|
|
stopTimers()
|
|
settings := ss.LoadSettings()
|
|
state := ts.State
|
|
|
|
session := &data.TrainingSession{
|
|
Date: time.Now(),
|
|
Sets: int64(state.SetsDone),
|
|
WeightLeft: settings.WeightLeft,
|
|
WeightRight: settings.WeightRight,
|
|
RepsPerSet: int64(state.RepsPerSet),
|
|
Duration: int64(state.InitialDurationSeconds - state.RemainingSeconds),
|
|
}
|
|
|
|
if err := ts.FinishTraining(session); err != nil {
|
|
dialog.ShowError(err, parent)
|
|
log.Printf("Fehler beim Speichern des Trainings: %v", err)
|
|
} else {
|
|
fyne.CurrentApp().SendNotification(&fyne.Notification{Title: "Training gespeichert!", Content: "Gut gemacht!"})
|
|
}
|
|
|
|
updateUI()
|
|
}
|
|
|
|
timerDisplay := canvas.NewText("00:00", theme.PrimaryColor())
|
|
timerDisplay.TextSize = 48
|
|
timerDisplay.Alignment = fyne.TextAlignCenter
|
|
|
|
exerciseInfo := widget.NewLabel("Aktuelle Übung: Double Clean & Press")
|
|
exerciseInfo.Alignment = fyne.TextAlignCenter
|
|
|
|
progressRing := canvas.NewCircle(theme.BackgroundColor())
|
|
progressRing.StrokeWidth = 5
|
|
progressRing.StrokeColor = theme.PrimaryColor()
|
|
|
|
// Vereinfachte Steuerung
|
|
setBtn := widget.NewButtonWithIcon("Satz", theme.ConfirmIcon(), setAction)
|
|
finishBtn := widget.NewButtonWithIcon("Beenden", theme.CancelIcon(), finishAction)
|
|
actionBar := container.NewGridWithColumns(2, setBtn, finishBtn)
|
|
|
|
// Tastatur-Shortcut
|
|
canvasObj := container.NewVBox(
|
|
container.NewCenter(timerDisplay),
|
|
container.NewCenter(exerciseInfo),
|
|
container.NewCenter(progressRing),
|
|
actionBar,
|
|
)
|
|
|
|
return container.NewPadded(canvasObj)
|
|
}
|