diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index 8443623..80175a1 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -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 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(); _builderObject = new(); + _SplashShowing = false; + } + private bool _SplashShowing; + private readonly IRepository? _roundsRepo; private readonly IRepository _pointsRepo; private readonly IMethodSharingService _sharingService; private readonly ICombinedRepository _combined; private readonly IObjectMessageService _objectMessage; private readonly IOverlayService _overlay; + private readonly ISplashService _splashService; private ObservableCollection _GameRoundList = new(); private ObservableCollection _ParticipantList = new(); private ObservableCollection _roundElements; @@ -89,7 +96,7 @@ public class RoundRunningViewModel : ViewModelBase public ObservableCollection 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; + } + + } } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/SplashViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/SplashViewModel.cs index 7c571b6..cecf2d0 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/SplashViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/SplashViewModel.cs @@ -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); } } diff --git a/GreadyPoang/BasePage.xaml b/GreadyPoang/BasePage.xaml index dbd4ac4..16166ab 100644 --- a/GreadyPoang/BasePage.xaml +++ b/GreadyPoang/BasePage.xaml @@ -14,9 +14,27 @@ + InputTransparent="True" > + + + + + \ No newline at end of file diff --git a/GreadyPoang/BasePage.xaml.cs b/GreadyPoang/BasePage.xaml.cs index 063c4e3..444d4d7 100644 --- a/GreadyPoang/BasePage.xaml.cs +++ b/GreadyPoang/BasePage.xaml.cs @@ -8,6 +8,6 @@ public partial class BasePage : ContentPage { InitializeComponent(); MainContent.Content = content; - BindingContext = splashVm; + SplashView.BindingContext = splashVm; } } \ No newline at end of file diff --git a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs b/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs index d1a9806..5da65d9 100644 --- a/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/RoundRunningViewModelCommands.cs @@ -20,13 +20,15 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel IMethodSharingService 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(async (id) => await EditAsync(id), (id) => id > 0); //RensaCommand = new Command(async () => RensaAsync()); //ParticipantTappedCommand = new Command(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(); } } diff --git a/GreadyPoang/CommandClasses/SplashViewModelCommands.cs b/GreadyPoang/CommandClasses/SplashViewModelCommands.cs index 8a6ca30..942444b 100644 --- a/GreadyPoang/CommandClasses/SplashViewModelCommands.cs +++ b/GreadyPoang/CommandClasses/SplashViewModelCommands.cs @@ -2,7 +2,7 @@ namespace GreadyPoang.CommandClasses; -public class SplashViewModelCommands :SplashViewModel +public class SplashViewModelCommands : SplashViewModel { public SplashViewModelCommands() : base() { diff --git a/GreadyPoang/LocalServices/Implements/SplashService.cs b/GreadyPoang/LocalServices/Implements/SplashService.cs index 39df135..7af6a7c 100644 --- a/GreadyPoang/LocalServices/Implements/SplashService.cs +++ b/GreadyPoang/LocalServices/Implements/SplashService.cs @@ -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(); } } diff --git a/GreadyPoang/Pages/RoundRunningPage.cs b/GreadyPoang/Pages/RoundRunningPage.cs index cfd1138..d8e0f81 100644 --- a/GreadyPoang/Pages/RoundRunningPage.cs +++ b/GreadyPoang/Pages/RoundRunningPage.cs @@ -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(); + _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(); ; } + } diff --git a/GreadyPoang/Views/RoundRunningView.xaml b/GreadyPoang/Views/RoundRunningView.xaml index a15ed2d..407d5ad 100644 --- a/GreadyPoang/Views/RoundRunningView.xaml +++ b/GreadyPoang/Views/RoundRunningView.xaml @@ -85,6 +85,9 @@