refactor: another ui test

This commit is contained in:
Patryk Hegenberg 2025-06-27 20:42:17 +02:00
parent a8ed9c9ed1
commit 789ee25e1f
4 changed files with 182 additions and 86 deletions

View file

@ -16,8 +16,7 @@ import (
func main() {
myApp := app.NewWithID("com.example.kettlebell-tracker")
// myApp.Settings().SetTheme(theme.DarkTheme())
mainWIndow := myApp.NewWindow("Kettlebell Programm Tracker")
mainWindow := myApp.NewWindow("Kettlebell Programm Tracker")
dbDir := myApp.Storage().RootURI().Path()
dbPath := filepath.Join(dbDir, "kb_training.db")
@ -32,23 +31,50 @@ func main() {
apiService := services.NewApiService(myApp.UniqueID())
trainingService := services.NewTrainingService(dbService, settingsService, apiService)
// Dark Mode nach Systemeinstellung
if fyne.CurrentDevice().IsMobile() {
myApp.Settings().SetTheme(theme.DarkTheme())
}
homeScreen := ui.MakeHomeScreen()
settingsScreen := ui.MakeSettingsScreen(settingsService, mainWIndow)
historyScreen := ui.MakeHistoryScreen(dbService, mainWIndow)
trainingScreen := ui.MakeTrainingScreen(trainingService, settingsService, mainWIndow)
// mainWindow := myApp.NewWindow("Kettlebell Tracker")
mainWindow.SetMaster()
tabs := container.NewAppTabs(
container.NewTabItemWithIcon("Home", theme.HomeIcon(), homeScreen),
container.NewTabItemWithIcon("Training", theme.MediaPlayIcon(), trainingScreen),
container.NewTabItemWithIcon("Historie", theme.HistoryIcon(), historyScreen),
container.NewTabItemWithIcon("Einstellungen", theme.SettingsIcon(), settingsScreen),
)
// Responsive Layout
content := container.NewMax()
nav := buildNavigation(content, mainWindow, dbService, settingsService, apiService, trainingService) // Eigene Nav-Komponente
tabs.SetTabLocation(container.TabLocationBottom)
mainWIndow.Resize(fyne.NewSize(400, 600))
mainWIndow.SetContent(tabs)
mainWIndow.SetMaster()
mainWIndow.ShowAndRun()
mainWindow.SetContent(container.NewBorder(nav, nil, nil, nil, content))
mainWindow.Resize(fyne.NewSize(400, 600))
mainWindow.ShowAndRun()
}
func buildNavigation(content *fyne.Container, mainWindow fyne.Window, dbService *data.DatabaseService, settingsService *services.SettingsService, apiService *services.ApiService, trainingService *services.TrainingService) fyne.CanvasObject {
navItems := []struct {
icon fyne.Resource
title string
view func() fyne.CanvasObject
}{
{theme.HomeIcon(), "Home", ui.MakeHomeScreen},
{theme.MediaPlayIcon(), "Training", func() fyne.CanvasObject {
return ui.MakeTrainingScreen(trainingService, settingsService, mainWindow)
}},
{theme.HistoryIcon(), "Historie", func() fyne.CanvasObject {
return ui.MakeHistoryScreen(dbService, mainWindow)
}},
{theme.SettingsIcon(), "Einstellungen", func() fyne.CanvasObject {
return ui.MakeSettingsScreen(settingsService, mainWindow)
}},
}
nav := container.NewAppTabs()
for _, item := range navItems {
nav.Append(container.NewTabItemWithIcon(item.title, item.icon, item.view()))
}
nav.SetTabLocation(container.TabLocationBottom)
nav.OnSelected = func(t *container.TabItem) {
content.Objects = []fyne.CanvasObject{t.Content}
content.Refresh()
}
return nav
}