Nu fungerar splash, men måste se vidare på övrig sidhantering

This commit is contained in:
2025-10-04 07:37:52 +02:00
parent f1077febc4
commit cbf018a890
11 changed files with 149 additions and 33 deletions

View File

@ -1,10 +1,10 @@
using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel;
using System.Diagnostics;
using GreadyPoang.Core;
namespace GreadyPoang.ViewModelLayer;
@ -24,7 +24,8 @@ public class RoundRunningViewModel : ViewModelBase
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage,
IOverlayService overlay
IOverlayService overlay,
ISplashService splashService
) : base()
{
_roundsRepo = roundsRepo;
@ -33,16 +34,22 @@ public class RoundRunningViewModel : ViewModelBase
_combined = combined;
_objectMessage = objectMessage;
_overlay = overlay;
_splashService = splashService;
_roundElements = new ObservableCollection<RoundBuilderElement>();
_builderObject = new();
_SplashShowing = false;
}
private bool _SplashShowing;
private readonly IRepository<GameRound>? _roundsRepo;
private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private readonly IOverlayService _overlay;
private readonly ISplashService _splashService;
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private ObservableCollection<RoundBuilderElement> _roundElements;
@ -89,7 +96,7 @@ public class RoundRunningViewModel : ViewModelBase
public ObservableCollection<RoundBuilderElement> Get()
{
_overlay.ShowSplash("Laddar...", 3000);
//_overlay.ShowSplash("Laddar...", 30);
if (_objectMessage.CurrentGroup != null)
{
@ -251,6 +258,22 @@ public class RoundRunningViewModel : ViewModelBase
}
}
public async void ToggleSplash()
{
if (!_SplashShowing)
{
//_overlay.ShowSplash("Clcicked!", 5000);
await _splashService.ShowSplash("Clicked", 0);
_SplashShowing = true;
}
else
{
await _splashService.HideAsync();
_SplashShowing = false;
}
}
}

View File

@ -6,7 +6,19 @@ public class SplashViewModel : ViewModelBase
{
// public event PropertyChangedEventHandler PropertyChanged;
private bool _isSplashVisible = true;
private Color _splashBackgroundColor = Colors.DarkSlateBlue;
public Color SplashBackgroundColor
{
get => _splashBackgroundColor;
set
{
_splashBackgroundColor = value;
RaisePropertyChanged(nameof(SplashBackgroundColor));
}
}
private bool _isSplashVisible = false;
public bool IsSplashVisible
{
get => _isSplashVisible;
@ -28,6 +40,19 @@ public class SplashViewModel : ViewModelBase
}
}
private Color _splashTextColor = Colors.White;
public Color SplashTextColor
{
get { return _splashTextColor; }
set
{
_splashTextColor = value;
RaisePropertyChanged(nameof(SplashTextColor));
}
}
private double _splashTranslationY = 0;
public double SplashTranslationY
{
@ -46,19 +71,32 @@ public class SplashViewModel : ViewModelBase
IsSplashVisible = false;
}
public string SplashText { get; set; } = "Välkommen!";
public Color SplashBackgroundColor { get; set; } = Colors.DarkSlateBlue;
public string SplashImage { get; set; } = "splash_icon.png";
private string _splashText = "Välkommen!";
public string SplashText
{
get => _splashText;
set
{
_splashText = value;
RaisePropertyChanged(nameof(SplashText));
}
}
//public Color SplashBackgroundColor { get; set; } = Colors.DarkSlateBlue;
//public string SplashImage { get; set; } = "splash_icon.png";
//protected void OnPropertyChanged(string name) =>
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
private async Task AnimateSplashOut()
{
for (int i = 0; i < 10; i++)
{
SplashOpacity -= 0.1;
SplashTranslationY += 5;
//SplashTranslationY += 5;
await Task.Delay(30);
}
}

View File

@ -14,9 +14,27 @@
<viewsPartial:SplashView
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
IsVisible="{Binding IsSplashVisible}"
Opacity="{Binding SplashOpacity}"
x:Name="SplashView"
IsVisible="True"
Opacity="1"
ZIndex="999"
TranslationY="{Binding SplashTranslationY}"
InputTransparent="False" />
InputTransparent="True" >
</viewsPartial:SplashView>
<!--
WidthRequest="250"
HeightRequest="150"
IsVisible="{Binding IsSplashVisible}"
BackgroundColor="{Binding SplashBackgroundColor}"
x:Name="SplashView"
BackgroundColor="Black"
Opacity="{Binding SplashOpacity}"
IsVisible="True"
Opacity="0.9"
ZIndex="999"
BackgroundColor="Black" />-->
</AbsoluteLayout>
</ContentPage>

View File

@ -8,6 +8,6 @@ public partial class BasePage : ContentPage
{
InitializeComponent();
MainContent.Content = content;
BindingContext = splashVm;
SplashView.BindingContext = splashVm;
}
}

View File

@ -20,13 +20,15 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage,
IOverlayService overlay)
IOverlayService overlay,
ISplashService splashService)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage,
overlay)
overlay,
splashService)
{
}
@ -37,6 +39,7 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
public ICommand ElementTappedCommand { get; private set; }
public ICommand ParticipantTappedCommand { get; private set; }
public ICommand StoreAndHandlePointsCommand { get; private set; }
public ICommand OnSplashClickedCommand { get; private set; }
#endregion
@ -44,6 +47,7 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
{
base.Init();
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
OnSplashClickedCommand = new Command(async () => await ToggleSplash());
//EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
//RensaCommand = new Command(async () => RensaAsync());
//ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
@ -54,6 +58,12 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
private async Task StoreAndHandleAsync()
{
base.StoreAndHandlePoints();
await Shell.Current.GoToAsync("..");
//await Shell.Current.GoToAsync("..");
await Shell.Current.GoToAsync("Påbörja eller fortsätt Runda");
}
private async Task ToggleSplash()
{
base.ToggleSplash();
}
}

View File

@ -2,7 +2,7 @@
namespace GreadyPoang.CommandClasses;
public class SplashViewModelCommands :SplashViewModel
public class SplashViewModelCommands : SplashViewModel
{
public SplashViewModelCommands() : base()
{

View File

@ -15,13 +15,20 @@ public class SplashService : ISplashService
public async Task ShowSplash(string text = "Välkommen!", int durationMs = 3000)
{
_viewModel.SplashText = text;
_viewModel.SplashOpacity = 0.8;
_viewModel.SplashBackgroundColor = Colors.DodgerBlue;
_viewModel.IsSplashVisible = true;
await Task.Delay(durationMs);
_viewModel.IsSplashVisible = false;
//await Task.Yield(); // ger UI-tråden en chans att uppdatera
if (durationMs > 0)
{
await Task.Delay(durationMs);
_viewModel.IsSplashVisible = false;
}
}
public async Task HideAsync()
{
//_viewModel.IsSplashVisible = false;
await _viewModel.HideSplashAsync();
}
}

View File

@ -1,4 +1,5 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Core;
using GreadyPoang.Views;
namespace GreadyPoang.Pages;
@ -6,25 +7,37 @@ namespace GreadyPoang.Pages;
public class RoundRunningPage : BasePage
{
private readonly RoundRunningViewModelCommands _vm;
private readonly SplashViewModelCommands _splashVm;
public ISplashService Splash { get; set; }
public RoundRunningPage(RoundRunningViewModelCommands Vm, SplashViewModelCommands splashVm)
: base(new RoundRunningView(Vm), splashVm)
{
Title = "RoundRunningView";
Title = "Starta/Fortsätt runda";
_vm = Vm;
Splash = ServiceLocator.Services?.GetRequiredService<ISplashService>();
_splashVm = splashVm;
}
protected override void OnAppearing()
public SplashViewModelCommands SplashVm { get; }
protected override async void OnAppearing()
{
base.OnAppearing();
BindingContext = _vm;
_vm.Get();
//BuildScoreGrid(ViewModel.PlayerColumns); // <-- här bygger du layouten
//// _vm.RebuildRequested += ViewModel_RebuildRequested;
//_splash.ShowSplash("Nu kan du spela vidare").GetAwaiter().GetResult(); ;
if (_splashVm != null)
{
await Splash.ShowSplash("Nu kan du spela vidare", 3000);
//await Splash.ShowSplash("Nu kan du spela vidare", 3000).GetAwaiter().GetResult();
}
//_splashVm.ShowSplash("Nu kan du spela vidare").GetAwaiter().GetResult(); ;
}
}

View File

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

View File

@ -4,23 +4,27 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GreadyPoang.ViewsPartial.SplashView"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
x:DataType="vm:SplashViewModelCommands"
IsVisible="{Binding IsSplashVisible, Mode=OneWay}">
<Border Background="{Binding SplashBackgroundColor}"
WidthRequest="250"
HeightRequest="150"
x:DataType="vm:SplashViewModelCommands">
<!--IsVisible="{Binding IsSplashVisible}">-->
<Border x:Name="SplashBorder"
Stroke="Black"
BackgroundColor="{Binding SplashBackgroundColor}"
WidthRequest="350"
HeightRequest="200"
StrokeShape="RoundRectangle 20"
Padding="20"
IsVisible="{Binding IsSplashVisible}"
HorizontalOptions="Center"
VerticalOptions="Center">
VerticalOptions="Center"
Opacity="{Binding SplashOpacity}">
<StackLayout>
<Image Source="{Binding SplashImage}" HeightRequest="60" />
<!--<Image Source="{Binding SplashImage}" HeightRequest="60" />-->
<Label Text="{Binding SplashText}"
FontSize="18"
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="White"/>
TextColor="{Binding SplashTextColor}"/>
</StackLayout>
</Border>
</ContentView>

View File

@ -9,9 +9,9 @@ public partial class SplashView : ContentView
InitializeComponent();
}
public SplashViewModelCommands? ViewModel
public SplashViewModelCommands ViewModel
{
get => BindingContext as SplashViewModelCommands;
get => (SplashViewModelCommands)BindingContext;
set => BindingContext = value;
}