Nu fungerar hanteringen kring navigation

This commit is contained in:
2025-10-05 08:57:34 +02:00
parent a449dbeab3
commit b567291063
15 changed files with 115 additions and 56 deletions

View File

@ -5,4 +5,5 @@ namespace GreadyPoang.Services;
public class ObjectMessageService : IObjectMessageService public class ObjectMessageService : IObjectMessageService
{ {
public RoundBuilderGroup CurrentGroup { get; set; } public RoundBuilderGroup CurrentGroup { get; set; }
public bool Delivered { get; set; }
} }

View File

@ -1,9 +1,10 @@
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
namespace GreadyPoang.Services; namespace GreadyPoang.Services
{
public interface IObjectMessageService public interface IObjectMessageService
{ {
RoundBuilderGroup CurrentGroup { get; set; } RoundBuilderGroup CurrentGroup { get; set; }
bool Delivered { get; set; }
}
} }

View File

@ -4,5 +4,6 @@ public interface INavigationService
{ {
Task NavigateToAsync(string route); Task NavigateToAsync(string route);
Task NavigateToPageAsync(Page page); Task NavigateToPageAsync(Page page);
} }

View File

@ -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));
}
}
}

View File

@ -24,7 +24,8 @@ public class RoundRunningViewModel : ViewModelBase
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage, IObjectMessageService objectMessage,
ISplashService splashService ISplashService splashService,
AppShellViewModel appShell
) : base() ) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
@ -33,6 +34,7 @@ public class RoundRunningViewModel : ViewModelBase
_combined = combined; _combined = combined;
_objectMessage = objectMessage; _objectMessage = objectMessage;
_splashService = splashService; _splashService = splashService;
_appShell = appShell;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
_builderObject = new(); _builderObject = new();
_SplashShowing = false; _SplashShowing = false;
@ -47,6 +49,7 @@ public class RoundRunningViewModel : ViewModelBase
private readonly ICombinedRepository _combined; private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage; private readonly IObjectMessageService _objectMessage;
private readonly ISplashService _splashService; private readonly ISplashService _splashService;
private readonly AppShellViewModel _appShell;
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new(); private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new(); private ObservableCollection<Participant> _ParticipantList = new();
private ObservableCollection<RoundBuilderElement> _roundElements; private ObservableCollection<RoundBuilderElement> _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<RoundBuilderElement> Get() public ObservableCollection<RoundBuilderElement> Get()
{ {
@ -97,6 +112,8 @@ public class RoundRunningViewModel : ViewModelBase
if (_objectMessage.CurrentGroup != null) if (_objectMessage.CurrentGroup != null)
{ {
GobackVisible = _objectMessage.Delivered;
_objectMessage.Delivered = false;
//CurrentGroup är satt från RoundStarting ViewModel //CurrentGroup är satt från RoundStarting ViewModel
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}"); Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
if (RoundElements.Count > 0) if (RoundElements.Count > 0)
@ -271,6 +288,11 @@ public class RoundRunningViewModel : ViewModelBase
} }
} }
public void GobackAsync()
{
_appShell.RoundRunningVisible = true;
}
} }

View File

@ -23,7 +23,9 @@ public class RoundStartingViewModel : ViewModelBase
IObjectMessageService objectMessage, IObjectMessageService objectMessage,
INavigationService nav, INavigationService nav,
IPageFactory factory, IPageFactory factory,
ISplashService splashService) : base() ISplashService splashService,
AppShellViewModel appShellView
) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
_pointsRepo = pointsRepo; _pointsRepo = pointsRepo;
@ -33,6 +35,7 @@ public class RoundStartingViewModel : ViewModelBase
_nav = nav; _nav = nav;
_factory = factory; _factory = factory;
_splashService = splashService; _splashService = splashService;
_appShellView = appShellView;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
} }
@ -49,6 +52,7 @@ public class RoundStartingViewModel : ViewModelBase
private readonly INavigationService _nav; private readonly INavigationService _nav;
private readonly IPageFactory _factory; private readonly IPageFactory _factory;
private readonly ISplashService _splashService; private readonly ISplashService _splashService;
private readonly AppShellViewModel _appShellView;
private Participant _selectedItem; private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements; private ObservableCollection<RoundBuilderElement> _roundElements;
@ -248,11 +252,14 @@ public class RoundStartingViewModel : ViewModelBase
if (rbGroup != null) if (rbGroup != null)
{ {
_objectMessage.CurrentGroup = rbGroup; _objectMessage.CurrentGroup = rbGroup;
await _splashService.ShowSplash("Runda vald, gå till\r 'Påbörja eller fortsätt Runda'", 3000); _objectMessage.Delivered = true;
// await Shell.Current.GoToAsync("RoundRunning"); //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(); //var page = _factory.CreateRoundPage();
//await _nav.NavigateToPageAsync(page); //_nav.NavigateToPageAsync(page);
} }
} }

View File

@ -3,12 +3,13 @@
x:Class="GreadyPoang.AppShell" x:Class="GreadyPoang.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 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:views="clr-namespace:GreadyPoang.Views"
xmlns:pages="clr-namespace:GreadyPoang.Pages" xmlns:pages="clr-namespace:GreadyPoang.Pages"
xmlns:local="clr-namespace:GreadyPoang" xmlns:local="clr-namespace:GreadyPoang"
Title="GreadyPoang" Title="GreadyPoang"
Shell.TitleColor="LightYellow" Shell.TitleColor="LightYellow"
x:DataType="vm:AppShellViewModel"
Shell.BackgroundColor="CadetBlue"> Shell.BackgroundColor="CadetBlue">
<TabBar> <TabBar>
@ -17,18 +18,13 @@
Route="MainPage" /> Route="MainPage" />
<ShellContent <ShellContent
Title="Deltagare" ContentTemplate="{DataTemplate pages:ParticipantListPage}" Title="Deltagare" ContentTemplate="{DataTemplate pages:ParticipantListPage}"
Route="Deltagare"/> Route="ParticipantListPage"/>
<ShellContent <ShellContent
Title="Ny Runda" ContentTemplate="{DataTemplate pages:RoundStartingPage}" Title="Ny Runda" ContentTemplate="{DataTemplate pages:RoundStartingPage}"
Route="RoundStart"/> Route="RoundStartingPage"/>
<ShellContent <ShellContent
Title="Påbörja eller fortsätt Runda" ContentTemplate="{DataTemplate pages:RoundRunningPage}" Title="Påbörja eller fortsätt Runda" ContentTemplate="{DataTemplate pages:RoundRunningPage}"
Route="RoundRunning"/> Route="RoundRunningPage" IsVisible="{Binding RoundRunningVisible}"/>
</TabBar> </TabBar>
<!--<viewsPartial:SplashView
x:Name="SplashViewControl"
IsVisible="{Binding IsSplashVisible}"
Opacity="{Binding SplashOpacity}"
TranslationY="{Binding SplashTranslationY}"
InputTransparent="False" />-->
</Shell> </Shell>

View File

@ -1,4 +1,5 @@
using GreadyPoang.Core; using GreadyPoang.Core;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang namespace GreadyPoang
{ {
@ -6,14 +7,15 @@ namespace GreadyPoang
{ {
private readonly IPageFactory _factory; private readonly IPageFactory _factory;
public AppShell(IPageFactory factory) public AppShell(IPageFactory factory, AppShellViewModel appShellView)
{ {
InitializeComponent(); InitializeComponent();
Routing.RegisterRoute("RoundStart", typeof(Pages.RoundStartingPage)); Routing.RegisterRoute("RoundStartingPage", typeof(Pages.RoundStartingPage));
Routing.RegisterRoute("Deltagare", typeof(Pages.ParticipantListPage)); Routing.RegisterRoute("ParticipantListPage", typeof(Pages.ParticipantListPage));
Routing.RegisterRoute("RoundRunning", typeof(Pages.RoundRunningPage)); Routing.RegisterRoute("RoundRunningPage", typeof(Pages.RoundRunningPage));
_factory = factory; _factory = factory;
BindingContext = appShellView;
} }
} }
} }

View File

@ -0,0 +1,11 @@
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.CommandClasses;
public class AppShellViewModelCommands : AppShellViewModel
{
public AppShellViewModelCommands() : base()
{
}
}

View File

@ -20,22 +20,20 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage, IObjectMessageService objectMessage,
ISplashService splashService) ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo, : base(roundsRepo,
pointsRepo, pointsRepo,
sharingService, sharingService,
combined, combined,
objectMessage, objectMessage,
splashService) splashService,
appShell)
{ {
} }
#region Commands #region Commands
public ICommand SaveCommand { get; private set; } public ICommand GobackCommand { 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 StoreAndHandlePointsCommand { get; private set; } public ICommand StoreAndHandlePointsCommand { get; private set; }
public ICommand OnSplashClickedCommand { get; private set; } public ICommand OnSplashClickedCommand { get; private set; }
@ -46,11 +44,13 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
base.Init(); base.Init();
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync()); StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
OnSplashClickedCommand = new Command(async () => await ToggleSplash()); OnSplashClickedCommand = new Command(async () => await ToggleSplash());
//EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0); GobackCommand = new Command(async () => GobackAsync());
//RensaCommand = new Command(async () => RensaAsync()); }
//ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
//ElementTappedCommand = new Command<RoundBuilderElement>((selectedElement) => RoundSelected(selectedElement));
private async void GobackAsync()
{
base.GobackAsync();
await Shell.Current.GoToAsync("..");
} }
private async Task StoreAndHandleAsync() private async Task StoreAndHandleAsync()

View File

@ -22,7 +22,8 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
IObjectMessageService objectMessage, IObjectMessageService objectMessage,
INavigationService nav, INavigationService nav,
IPageFactory factory, IPageFactory factory,
ISplashService splashService) ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo, : base(roundsRepo,
pointsRepo, pointsRepo,
sharingService, sharingService,
@ -30,7 +31,8 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
objectMessage, objectMessage,
nav, nav,
factory, factory,
splashService) splashService,
appShell)
{ {
} }
@ -108,7 +110,6 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
base.SelectNewlyAddedParticipant(roundBuilder); base.SelectNewlyAddedParticipant(roundBuilder);
goneOk = true; goneOk = true;
return goneOk; return goneOk;
} }
} }

View File

@ -2,6 +2,7 @@
public class NavigationService : INavigationService public class NavigationService : INavigationService
{ {
public Task NavigateToAsync(string route) public Task NavigateToAsync(string route)
=> Shell.Current.GoToAsync(route); => Shell.Current.GoToAsync(route);

View File

@ -44,7 +44,6 @@ public static class MauiProgram
builder.Services.AddScoped<IPageFactory, PageFactory>(); builder.Services.AddScoped<IPageFactory, PageFactory>();
builder.Services.AddSingleton<INavigationService, NavigationService>(); builder.Services.AddSingleton<INavigationService, NavigationService>();
builder.Services.AddSingleton<IServiceLocator, ServiceLocator>(); builder.Services.AddSingleton<IServiceLocator, ServiceLocator>();
builder.Services.AddSingleton<AppShell>();
builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>(); builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
builder.Services.AddScoped<ParticipantViewModelCommands>(); builder.Services.AddScoped<ParticipantViewModelCommands>();
@ -63,8 +62,8 @@ public static class MauiProgram
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>(); builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddSingleton<AppShellViewModel>();
//builder.Services.AddSingleton<IOverlayService, OverlayService>(); builder.Services.AddSingleton<AppShell>();
builder.Services.AddSingleton<SplashViewModelCommands>(); builder.Services.AddSingleton<SplashViewModelCommands>();
builder.Services.AddSingleton<ISplashService, SplashService>(); builder.Services.AddSingleton<ISplashService, SplashService>();

View File

@ -85,9 +85,16 @@
<Button Text="Register Points" <Button Text="Register Points"
Style="{StaticResource HoverButtonRedStyle}" Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding StoreAndHandlePointsCommand}"/> Command="{Binding StoreAndHandlePointsCommand}"/>
<VerticalStackLayout>
<Button Text="Visa Splash" <Button Text="Visa Splash"
Style="{StaticResource HoverButtonBlueStyle}" Style="{StaticResource HoverButtonBlueStyle}"
Command="{Binding OnSplashClickedCommand}"/> Command="{Binding OnSplashClickedCommand}"/>
<Button Text="Återgå"
Style="{StaticResource HoverButtonBlueStyle}"
Command="{Binding GobackCommand}"
IsVisible="{Binding GobackVisible}" />
</VerticalStackLayout>
</HorizontalStackLayout> </HorizontalStackLayout>
</Border> </Border>
<ScrollView Grid.Row="4" Orientation="Horizontal"> <ScrollView Grid.Row="4" Orientation="Horizontal">

View File

@ -13,17 +13,6 @@ public partial class RoundRunningView : ContentView
ViewModel.RebuildRequested += ViewModel_RebuildRequested; ViewModel.RebuildRequested += ViewModel_RebuildRequested;
} }
//protected override void OnAppearing()
//{
// base.OnAppearing();
// BindingContext = ViewModel;
// ViewModel.Get();
// //BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
// ViewModel.RebuildRequested += ViewModel_RebuildRequested;
// //_splash.ShowSplash("Nu kan du spela vidare").GetAwaiter().GetResult(); ;
//}
private void ViewModel_RebuildRequested(object? sender, EventArgs e) private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{ {