From b5672910631049b608814b38d0aa5ab095450df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sun, 5 Oct 2025 08:57:34 +0200 Subject: [PATCH] Nu fungerar hanteringen kring navigation --- .../Implements/ObjectMessageService.cs | 1 + .../Interfaces/IObjectMessageService.cs | 13 +++++----- .../Interfaces/INavigationService.cs | 1 + .../ViewModelClasses/AppShellViewModel.cs | 21 ++++++++++++++++ .../ViewModelClasses/RoundRunningViewModel.cs | 24 ++++++++++++++++++- .../RoundStartingViewModel.cs | 15 ++++++++---- GreadyPoang/AppShell.xaml | 16 +++++-------- GreadyPoang/AppShell.xaml.cs | 10 ++++---- .../AppShellViewModelCommands.cs | 11 +++++++++ .../RoundRunningViewModelCommands.cs | 22 ++++++++--------- .../RoundStartingViewModelCommands.cs | 7 +++--- GreadyPoang/Core/NavigationService.cs | 1 + GreadyPoang/MauiProgram.cs | 5 ++-- GreadyPoang/Views/RoundRunningView.xaml | 13 +++++++--- GreadyPoang/Views/RoundRunningView.xaml.cs | 11 --------- 15 files changed, 115 insertions(+), 56 deletions(-) create mode 100644 GreadyPoang.ViewModelLayer/ViewModelClasses/AppShellViewModel.cs create mode 100644 GreadyPoang/CommandClasses/AppShellViewModelCommands.cs diff --git a/GreadyPoang.Services/Services/Implements/ObjectMessageService.cs b/GreadyPoang.Services/Services/Implements/ObjectMessageService.cs index 3325f8f..90cef68 100644 --- a/GreadyPoang.Services/Services/Implements/ObjectMessageService.cs +++ b/GreadyPoang.Services/Services/Implements/ObjectMessageService.cs @@ -5,4 +5,5 @@ namespace GreadyPoang.Services; public class ObjectMessageService : IObjectMessageService { public RoundBuilderGroup CurrentGroup { get; set; } + public bool Delivered { get; set; } } diff --git a/GreadyPoang.Services/Services/Interfaces/IObjectMessageService.cs b/GreadyPoang.Services/Services/Interfaces/IObjectMessageService.cs index 72dca14..81203a1 100644 --- a/GreadyPoang.Services/Services/Interfaces/IObjectMessageService.cs +++ b/GreadyPoang.Services/Services/Interfaces/IObjectMessageService.cs @@ -1,9 +1,10 @@ using GreadyPoang.EntityLayer; -namespace GreadyPoang.Services; - -public interface IObjectMessageService +namespace GreadyPoang.Services { - RoundBuilderGroup CurrentGroup { get; set; } - -} + public interface IObjectMessageService + { + RoundBuilderGroup CurrentGroup { get; set; } + bool Delivered { get; set; } + } +} \ No newline at end of file diff --git a/GreadyPoang.ViewModelLayer/Interfaces/INavigationService.cs b/GreadyPoang.ViewModelLayer/Interfaces/INavigationService.cs index d3658ae..a1a18c0 100644 --- a/GreadyPoang.ViewModelLayer/Interfaces/INavigationService.cs +++ b/GreadyPoang.ViewModelLayer/Interfaces/INavigationService.cs @@ -4,5 +4,6 @@ public interface INavigationService { Task NavigateToAsync(string route); Task NavigateToPageAsync(Page page); + } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/AppShellViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/AppShellViewModel.cs new file mode 100644 index 0000000..dfa88c4 --- /dev/null +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/AppShellViewModel.cs @@ -0,0 +1,21 @@ +using Common.Library; + +namespace GreadyPoang.ViewModelLayer; + +public class AppShellViewModel : ViewModelBase +{ + + private bool _roundRounningVisible = true; + + public bool RoundRunningVisible + { + get { return _roundRounningVisible; } + set + { + _roundRounningVisible = value; + RaisePropertyChanged(nameof(RoundRunningVisible)); + } + } + + +} diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index a6f3c6a..7277022 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -24,7 +24,8 @@ public class RoundRunningViewModel : ViewModelBase IMethodSharingService sharingService, ICombinedRepository combined, IObjectMessageService objectMessage, - ISplashService splashService + ISplashService splashService, + AppShellViewModel appShell ) : base() { _roundsRepo = roundsRepo; @@ -33,6 +34,7 @@ public class RoundRunningViewModel : ViewModelBase _combined = combined; _objectMessage = objectMessage; _splashService = splashService; + _appShell = appShell; _roundElements = new ObservableCollection(); _builderObject = new(); _SplashShowing = false; @@ -47,6 +49,7 @@ public class RoundRunningViewModel : ViewModelBase private readonly ICombinedRepository _combined; private readonly IObjectMessageService _objectMessage; private readonly ISplashService _splashService; + private readonly AppShellViewModel _appShell; private ObservableCollection _GameRoundList = new(); private ObservableCollection _ParticipantList = new(); private ObservableCollection _roundElements; @@ -89,6 +92,18 @@ public class RoundRunningViewModel : ViewModelBase } } + private bool _gobackVisible = true; + + public bool GobackVisible + { + get { return _gobackVisible; } + set + { + _gobackVisible = value; + RaisePropertyChanged(nameof(GobackVisible)); + } + } + public ObservableCollection Get() { @@ -97,6 +112,8 @@ public class RoundRunningViewModel : ViewModelBase if (_objectMessage.CurrentGroup != null) { + GobackVisible = _objectMessage.Delivered; + _objectMessage.Delivered = false; //CurrentGroup är satt från RoundStarting ViewModel Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}"); if (RoundElements.Count > 0) @@ -271,6 +288,11 @@ public class RoundRunningViewModel : ViewModelBase } } + + public void GobackAsync() + { + _appShell.RoundRunningVisible = true; + } } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs index d9b5e93..f32a9d7 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs @@ -23,7 +23,9 @@ public class RoundStartingViewModel : ViewModelBase IObjectMessageService objectMessage, INavigationService nav, IPageFactory factory, - ISplashService splashService) : base() + ISplashService splashService, + AppShellViewModel appShellView + ) : base() { _roundsRepo = roundsRepo; _pointsRepo = pointsRepo; @@ -33,6 +35,7 @@ public class RoundStartingViewModel : ViewModelBase _nav = nav; _factory = factory; _splashService = splashService; + _appShellView = appShellView; _roundElements = new ObservableCollection(); } @@ -49,6 +52,7 @@ public class RoundStartingViewModel : ViewModelBase private readonly INavigationService _nav; private readonly IPageFactory _factory; private readonly ISplashService _splashService; + private readonly AppShellViewModel _appShellView; private Participant _selectedItem; private ObservableCollection _roundElements; @@ -248,11 +252,14 @@ public class RoundStartingViewModel : ViewModelBase if (rbGroup != null) { _objectMessage.CurrentGroup = rbGroup; - await _splashService.ShowSplash("Runda vald, gå till\r 'Påbörja eller fortsätt Runda'", 3000); - // await Shell.Current.GoToAsync("RoundRunning"); + _objectMessage.Delivered = true; + //await _splashService.ShowSplash("Runda vald, gå till\r\r 'Påbörja eller fortsätt Runda'", 3000); + await Shell.Current.GoToAsync("RoundRunningPage"); + _appShellView.RoundRunningVisible = false; + //_roundRunning.GobackVisible = false; //var page = _factory.CreateRoundPage(); - //await _nav.NavigateToPageAsync(page); + //_nav.NavigateToPageAsync(page); } } diff --git a/GreadyPoang/AppShell.xaml b/GreadyPoang/AppShell.xaml index 8102721..4bcae85 100644 --- a/GreadyPoang/AppShell.xaml +++ b/GreadyPoang/AppShell.xaml @@ -3,12 +3,13 @@ x:Class="GreadyPoang.AppShell" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" - xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses" + xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer" xmlns:views="clr-namespace:GreadyPoang.Views" xmlns:pages="clr-namespace:GreadyPoang.Pages" xmlns:local="clr-namespace:GreadyPoang" Title="GreadyPoang" Shell.TitleColor="LightYellow" + x:DataType="vm:AppShellViewModel" Shell.BackgroundColor="CadetBlue"> @@ -17,18 +18,13 @@ Route="MainPage" /> + Route="ParticipantListPage"/> + Route="RoundStartingPage"/> + Route="RoundRunningPage" IsVisible="{Binding RoundRunningVisible}"/> - + diff --git a/GreadyPoang/AppShell.xaml.cs b/GreadyPoang/AppShell.xaml.cs index 8b8e67e..ae96b64 100644 --- a/GreadyPoang/AppShell.xaml.cs +++ b/GreadyPoang/AppShell.xaml.cs @@ -1,4 +1,5 @@ using GreadyPoang.Core; +using GreadyPoang.ViewModelLayer; namespace GreadyPoang { @@ -6,14 +7,15 @@ namespace GreadyPoang { private readonly IPageFactory _factory; - public AppShell(IPageFactory factory) + public AppShell(IPageFactory factory, AppShellViewModel appShellView) { InitializeComponent(); - Routing.RegisterRoute("RoundStart", typeof(Pages.RoundStartingPage)); - Routing.RegisterRoute("Deltagare", typeof(Pages.ParticipantListPage)); - Routing.RegisterRoute("RoundRunning", typeof(Pages.RoundRunningPage)); + Routing.RegisterRoute("RoundStartingPage", typeof(Pages.RoundStartingPage)); + Routing.RegisterRoute("ParticipantListPage", typeof(Pages.ParticipantListPage)); + Routing.RegisterRoute("RoundRunningPage", typeof(Pages.RoundRunningPage)); _factory = factory; + BindingContext = appShellView; } } } diff --git a/GreadyPoang/CommandClasses/AppShellViewModelCommands.cs b/GreadyPoang/CommandClasses/AppShellViewModelCommands.cs new file mode 100644 index 0000000..28ed037 --- /dev/null +++ b/GreadyPoang/CommandClasses/AppShellViewModelCommands.cs @@ -0,0 +1,11 @@ +using GreadyPoang.ViewModelLayer; + +namespace GreadyPoang.CommandClasses; + +public class AppShellViewModelCommands : AppShellViewModel +{ + public AppShellViewModelCommands() : base() + { + + } +} diff --git a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs index bbcd1d8..59348dd 100644 --- a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs @@ -20,22 +20,20 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel IMethodSharingService sharingService, ICombinedRepository combined, IObjectMessageService objectMessage, - ISplashService splashService) + ISplashService splashService, + AppShellViewModel appShell) : base(roundsRepo, pointsRepo, sharingService, combined, objectMessage, - splashService) + splashService, + appShell) { } #region Commands - public ICommand SaveCommand { get; private set; } - public ICommand EditCommand { get; private set; } - public ICommand RensaCommand { get; private set; } - public ICommand ElementTappedCommand { get; private set; } - public ICommand ParticipantTappedCommand { get; private set; } + public ICommand GobackCommand { get; private set; } public ICommand StoreAndHandlePointsCommand { get; private set; } public ICommand OnSplashClickedCommand { get; private set; } @@ -46,11 +44,13 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel base.Init(); StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync()); OnSplashClickedCommand = new Command(async () => await ToggleSplash()); - //EditCommand = new Command(async (id) => await EditAsync(id), (id) => id > 0); - //RensaCommand = new Command(async () => RensaAsync()); - //ParticipantTappedCommand = new Command(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant)); - //ElementTappedCommand = new Command((selectedElement) => RoundSelected(selectedElement)); + GobackCommand = new Command(async () => GobackAsync()); + } + private async void GobackAsync() + { + base.GobackAsync(); + await Shell.Current.GoToAsync(".."); } private async Task StoreAndHandleAsync() diff --git a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs index 499faa5..8784549 100644 --- a/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/RoundStartingViewModelCommands.cs @@ -22,7 +22,8 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel IObjectMessageService objectMessage, INavigationService nav, IPageFactory factory, - ISplashService splashService) + ISplashService splashService, + AppShellViewModel appShell) : base(roundsRepo, pointsRepo, sharingService, @@ -30,7 +31,8 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel objectMessage, nav, factory, - splashService) + splashService, + appShell) { } @@ -108,7 +110,6 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel base.SelectNewlyAddedParticipant(roundBuilder); goneOk = true; return goneOk; - } } diff --git a/GreadyPoang/Core/NavigationService.cs b/GreadyPoang/Core/NavigationService.cs index dd7ede7..06756ff 100644 --- a/GreadyPoang/Core/NavigationService.cs +++ b/GreadyPoang/Core/NavigationService.cs @@ -2,6 +2,7 @@ public class NavigationService : INavigationService { + public Task NavigateToAsync(string route) => Shell.Current.GoToAsync(route); diff --git a/GreadyPoang/MauiProgram.cs b/GreadyPoang/MauiProgram.cs index 21c40e1..f592538 100644 --- a/GreadyPoang/MauiProgram.cs +++ b/GreadyPoang/MauiProgram.cs @@ -44,7 +44,6 @@ public static class MauiProgram builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); builder.Services.AddScoped, ParticipantRepository>(); builder.Services.AddScoped(); @@ -63,8 +62,8 @@ public static class MauiProgram builder.Services.AddSingleton(); - - //builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/GreadyPoang/Views/RoundRunningView.xaml b/GreadyPoang/Views/RoundRunningView.xaml index 407d5ad..52d0858 100644 --- a/GreadyPoang/Views/RoundRunningView.xaml +++ b/GreadyPoang/Views/RoundRunningView.xaml @@ -85,9 +85,16 @@