refactor: show finish Button only if time elapsed and center training card on home screen
This commit is contained in:
parent
16b2409ae8
commit
059db8f2fb
3 changed files with 48 additions and 17 deletions
|
|
@ -221,26 +221,26 @@ type TrainingState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateStateByDayCount(totalDays int) (program string, blockDay, reps int) {
|
func calculateStateByDayCount(totalDays int) (program string, blockDay, reps int) {
|
||||||
program = "giant_1.0"
|
program = "clean_1.0"
|
||||||
blockDay = 1
|
blockDay = 1
|
||||||
reps = 5
|
reps = 5
|
||||||
|
|
||||||
if totalDays > 0 {
|
if totalDays > 0 {
|
||||||
cycleIndex := (totalDays / 12) % 6
|
cycleIndex := (totalDays / 12) % 6
|
||||||
|
|
||||||
programs := []string{"giant_1.0", "ksk_1.0", "giant_1.1", "ksk_1.1", "giant_1.2", "ksk_1.2"}
|
programs := []string{"clean_1.0", "snatch_1.0", "clean_1.1", "snatch_1.1", "clean_1.2", "snatch_1.2"}
|
||||||
program = programs[cycleIndex]
|
program = programs[cycleIndex]
|
||||||
|
|
||||||
blockDay = (totalDays % 3) + 1
|
blockDay = (totalDays % 3) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
repsMap := map[string][]int{
|
repsMap := map[string][]int{
|
||||||
"giant_1.0": {5, 6, 4},
|
"clean_1.0": {5, 6, 4},
|
||||||
"giant_1.1": {6, 8, 7},
|
"clean_1.1": {6, 8, 7},
|
||||||
"giant_1.2": {7, 9, 8},
|
"clean_1.2": {7, 9, 8},
|
||||||
"ksk_1.0": {5, 6, 4},
|
"snatch_1.0": {5, 6, 4},
|
||||||
"ksk_1.1": {6, 8, 7},
|
"snatch_1.1": {6, 8, 7},
|
||||||
"ksk_1.2": {7, 9, 8},
|
"snatch_1.2": {7, 9, 8},
|
||||||
}
|
}
|
||||||
|
|
||||||
if r, ok := repsMap[program]; ok && len(r) >= blockDay {
|
if r, ok := repsMap[program]; ok && len(r) >= blockDay {
|
||||||
|
|
@ -339,7 +339,6 @@ func (s *TrainingService) FinishTraining(session *data.TrainingSession) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// s.sendToBackend(session)
|
|
||||||
go s.apiService.SendTrainingData(session)
|
go s.apiService.SendTrainingData(session)
|
||||||
|
|
||||||
s.ResetTraining()
|
s.ResetTraining()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package ui
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.patanix.de/git/kettlebell-app/internal/data"
|
"git.patanix.de/git/kettlebell-app/internal/data"
|
||||||
"git.patanix.de/git/kettlebell-app/internal/services"
|
"git.patanix.de/git/kettlebell-app/internal/services"
|
||||||
|
|
@ -22,18 +23,23 @@ func MakeHomeScreen(ts *services.TrainingService, db *data.DatabaseService, onSt
|
||||||
headerTitle.TextStyle.Bold = true
|
headerTitle.TextStyle.Bold = true
|
||||||
|
|
||||||
header := container.NewCenter(
|
header := container.NewCenter(
|
||||||
|
widget.NewSeparator(),
|
||||||
headerTitle,
|
headerTitle,
|
||||||
)
|
)
|
||||||
|
|
||||||
state := ts.State
|
state := ts.State
|
||||||
|
startButton := widget.NewButton("Training starten", onStart)
|
||||||
|
startButton.Importance = widget.HighImportance
|
||||||
|
|
||||||
nextTrainingCard := widget.NewCard(
|
nextTrainingCard := widget.NewCard(
|
||||||
"Nächstes Training",
|
"Nächstes Training",
|
||||||
fmt.Sprintf("%s - Tag %d", state.CurrentProgram, state.CurrentBlockDay),
|
fmt.Sprintf("%s - Tag %d", state.CurrentProgram, state.CurrentBlockDay),
|
||||||
container.NewVBox(
|
container.NewVBox(
|
||||||
widget.NewLabel(fmt.Sprintf("Ziel: %d Wiederholungen pro Satz", state.CurrentReps)),
|
widget.NewLabel(fmt.Sprintf("Ziel: %d Wiederholungen pro Satz", state.CurrentReps)),
|
||||||
widget.NewButton("Training starten", onStart),
|
startButton,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
centerContent := container.NewCenter(nextTrainingCard)
|
||||||
|
|
||||||
setsValue := widget.NewLabelWithStyle("–", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
setsValue := widget.NewLabelWithStyle("–", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
||||||
durationValue := widget.NewLabelWithStyle("–", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
durationValue := widget.NewLabelWithStyle("–", fyne.TextAlignCenter, fyne.TextStyle{Bold: true})
|
||||||
|
|
@ -55,20 +61,32 @@ func MakeHomeScreen(ts *services.TrainingService, db *data.DatabaseService, onSt
|
||||||
setsValue.SetText(fmt.Sprintf("%d", lastSession.Sets))
|
setsValue.SetText(fmt.Sprintf("%d", lastSession.Sets))
|
||||||
durationValue.SetText(utils.FormatDuration(lastSession.Duration))
|
durationValue.SetText(utils.FormatDuration(lastSession.Duration))
|
||||||
weightValue.SetText(fmt.Sprintf("%.1fkg", lastSession.WeightLeft))
|
weightValue.SetText(fmt.Sprintf("%.1fkg", lastSession.WeightLeft))
|
||||||
|
trainedToday := false
|
||||||
|
trainedToday = EqualDate(lastSession.Date, time.Now())
|
||||||
|
if trainedToday {
|
||||||
|
startButton.Disabled()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layout := container.NewVBox(
|
borderLayout := container.NewBorder(
|
||||||
header,
|
header,
|
||||||
widget.NewSeparator(),
|
|
||||||
nextTrainingCard,
|
|
||||||
statsCard,
|
statsCard,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
centerContent,
|
||||||
)
|
)
|
||||||
|
|
||||||
paddedLayout := container.NewPadded(layout)
|
paddedLayout := container.NewPadded(borderLayout)
|
||||||
if paddedLayout.Visible() {
|
if paddedLayout.Visible() {
|
||||||
loadLastPerformance()
|
loadLastPerformance()
|
||||||
}
|
}
|
||||||
|
|
||||||
return paddedLayout
|
return paddedLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EqualDate(date1, date2 time.Time) bool {
|
||||||
|
y1, m1, d1 := date1.Date()
|
||||||
|
y2, m2, d2 := date2.Date()
|
||||||
|
return y1 == y2 && m1 == m2 && d1 == d2
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ func MakeTrainingScreen(ts *services.TrainingService, ss *services.SettingsServi
|
||||||
repsLabel.TextSize = 20
|
repsLabel.TextSize = 20
|
||||||
repsLabel.Alignment = fyne.TextAlignCenter
|
repsLabel.Alignment = fyne.TextAlignCenter
|
||||||
|
|
||||||
|
var finishButton *widget.Button
|
||||||
|
|
||||||
var mainTimer *time.Ticker
|
var mainTimer *time.Ticker
|
||||||
|
|
||||||
updateUI := func() {
|
updateUI := func() {
|
||||||
|
|
@ -38,18 +40,29 @@ func MakeTrainingScreen(ts *services.TrainingService, ss *services.SettingsServi
|
||||||
setsLabel.Text = fmt.Sprintf("%d / %d", state.SetsDone, state.GoalSets)
|
setsLabel.Text = fmt.Sprintf("%d / %d", state.SetsDone, state.GoalSets)
|
||||||
repsLabel.Text = fmt.Sprintf("%d Wiederholungen", state.RepsPerSet)
|
repsLabel.Text = fmt.Sprintf("%d Wiederholungen", state.RepsPerSet)
|
||||||
|
|
||||||
|
if finishButton != nil {
|
||||||
|
if state.RemainingSeconds <= 0 && state.IsTrainingRunning {
|
||||||
|
finishButton.Show()
|
||||||
|
} else {
|
||||||
|
finishButton.Hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
timerLabel.Refresh()
|
timerLabel.Refresh()
|
||||||
setsLabel.Refresh()
|
setsLabel.Refresh()
|
||||||
repsLabel.Refresh()
|
repsLabel.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
finishAction := func() {
|
finishAction := func() {
|
||||||
|
if ts.State.RemainingSeconds > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
if mainTimer != nil {
|
if mainTimer != nil {
|
||||||
mainTimer.Stop()
|
mainTimer.Stop()
|
||||||
mainTimer = nil
|
mainTimer = nil
|
||||||
}
|
}
|
||||||
if !ts.State.IsTrainingRunning {
|
if !ts.State.IsTrainingRunning {
|
||||||
return // Nichts tun, wenn kein Training läuft
|
return
|
||||||
}
|
}
|
||||||
session := &data.TrainingSession{
|
session := &data.TrainingSession{
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
|
|
@ -66,7 +79,7 @@ func MakeTrainingScreen(ts *services.TrainingService, ss *services.SettingsServi
|
||||||
|
|
||||||
startAction := func() {
|
startAction := func() {
|
||||||
if ts.State.IsTrainingRunning {
|
if ts.State.IsTrainingRunning {
|
||||||
return // Verhindere Neustart
|
return
|
||||||
}
|
}
|
||||||
settings := ss.LoadSettings()
|
settings := ss.LoadSettings()
|
||||||
ts.StartTraining(settings.TrainingTimeMinutes, settings.GoalSets)
|
ts.StartTraining(settings.TrainingTimeMinutes, settings.GoalSets)
|
||||||
|
|
@ -96,7 +109,8 @@ func MakeTrainingScreen(ts *services.TrainingService, ss *services.SettingsServi
|
||||||
|
|
||||||
topPart := container.NewVBox(widget.NewLabelWithStyle("Verbleibende Zeit", fyne.TextAlignCenter, fyne.TextStyle{}), timerLabel)
|
topPart := container.NewVBox(widget.NewLabelWithStyle("Verbleibende Zeit", fyne.TextAlignCenter, fyne.TextStyle{}), timerLabel)
|
||||||
middlePart := container.NewVBox(widget.NewLabelWithStyle("Sätze", fyne.TextAlignCenter, fyne.TextStyle{}), setsLabel, repsLabel)
|
middlePart := container.NewVBox(widget.NewLabelWithStyle("Sätze", fyne.TextAlignCenter, fyne.TextStyle{}), setsLabel, repsLabel)
|
||||||
finishButton := widget.NewButton("Training beenden", finishAction)
|
finishButton = widget.NewButton("Training beenden", finishAction)
|
||||||
|
finishButton.Hide() // oder: finishButton.Hide() // finishButton.Disable()
|
||||||
setButton := widget.NewButton("Satz abschließen", setAction)
|
setButton := widget.NewButton("Satz abschließen", setAction)
|
||||||
setButton.Importance = widget.HighImportance
|
setButton.Importance = widget.HighImportance
|
||||||
setButton.Resize(fyne.NewSize(120, 60))
|
setButton.Resize(fyne.NewSize(120, 60))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue