Compare commits

9 Commits

60 changed files with 922 additions and 154 deletions

View File

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

0
Example.cs Normal file
View File

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Library\Common.Library.csproj" />
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.ViewModelLayer\GreadyPoang.ViewModelLayer.csproj" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,7 @@
public class BehaviorBase<T> : Behavior<T> where T : BindableObject public class BehaviorBase<T> : Behavior<T> where T : BindableObject
{ {
public T AssociatedObject { get; private set; } public T? AssociatedObject { get; private set; }
protected override void OnAttachedTo(T bindable) protected override void OnAttachedTo(T bindable)
{ {
@ -22,8 +22,9 @@ public class BehaviorBase<T> : Behavior<T> where T : BindableObject
AssociatedObject = null; AssociatedObject = null;
} }
void OnBindingContextChanged(object sender, EventArgs e) void OnBindingContextChanged(object? sender, EventArgs e)
{ {
if (AssociatedObject != null)
BindingContext = AssociatedObject.BindingContext; BindingContext = AssociatedObject.BindingContext;
} }
} }

View File

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -2,21 +2,27 @@
namespace GreadyPoang.Common; namespace GreadyPoang.Common;
public class DigitsOnlyBehavior : Behavior<Entry> public class DigitsOnlyBehavior : Behavior<Entry?>
{ {
protected override void OnAttachedTo(Entry entry) protected override void OnAttachedTo(Entry? entry)
{
if (entry != null)
{ {
entry.TextChanged += OnTextChanged; entry.TextChanged += OnTextChanged;
}
base.OnAttachedTo(entry); base.OnAttachedTo(entry);
} }
protected override void OnDetachingFrom(Entry entry) protected override void OnDetachingFrom(Entry? entry)
{
if (entry != null)
{ {
entry.TextChanged -= OnTextChanged; entry.TextChanged -= OnTextChanged;
}
base.OnDetachingFrom(entry); base.OnDetachingFrom(entry);
} }
private void OnTextChanged(object sender, TextChangedEventArgs e) private void OnTextChanged(object? sender, TextChangedEventArgs e)
{ {
var entry = sender as Entry; var entry = sender as Entry;
if (entry == null) return; if (entry == null) return;

View File

@ -4,7 +4,7 @@ using System.Windows.Input;
namespace GreadyPoang.Common; namespace GreadyPoang.Common;
public class EventToCommandBehavior : BehaviorBase<VisualElement> public class EventToCommandBehavior : BehaviorBase<VisualElement>
{ {
public string EventName { get; set; } public required string EventName { get; set; }
public static readonly BindableProperty CommandProperty = public static readonly BindableProperty CommandProperty =
BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(EventToCommandBehavior)); BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(EventToCommandBehavior));
@ -15,8 +15,9 @@ public class EventToCommandBehavior : BehaviorBase<VisualElement>
set => SetValue(CommandProperty, value); set => SetValue(CommandProperty, value);
} }
private EventInfo eventInfo; // Fix for CS8618: Make the field nullable and fix IDE1006: Add '_' prefix
private Delegate eventHandler; private EventInfo? _eventInfo;
private Delegate? _eventHandler;
protected override void OnAttachedTo(VisualElement bindable) protected override void OnAttachedTo(VisualElement bindable)
{ {
@ -25,21 +26,29 @@ public class EventToCommandBehavior : BehaviorBase<VisualElement>
if (bindable == null || string.IsNullOrEmpty(EventName)) if (bindable == null || string.IsNullOrEmpty(EventName))
return; return;
eventInfo = bindable.GetType().GetRuntimeEvent(EventName); var runtimeEvent = bindable.GetType().GetRuntimeEvent(EventName);
if (eventInfo == null) if (runtimeEvent == null)
throw new ArgumentException($"Event '{EventName}' not found on type '{bindable.GetType().Name}'"); throw new ArgumentException($"Event '{EventName}' not found on type '{bindable.GetType().Name}'");
MethodInfo methodInfo = typeof(EventToCommandBehavior).GetTypeInfo().GetDeclaredMethod(nameof(OnEvent)); _eventInfo = runtimeEvent;
eventHandler = methodInfo.CreateDelegate(eventInfo.EventHandlerType, this);
eventInfo.AddEventHandler(bindable, eventHandler); MethodInfo? methodInfo = typeof(EventToCommandBehavior).GetTypeInfo().GetDeclaredMethod(nameof(OnEvent));
if (methodInfo == null)
throw new InvalidOperationException($"Method '{nameof(OnEvent)}' not found on type '{typeof(EventToCommandBehavior).Name}'");
if (_eventInfo.EventHandlerType == null)
throw new InvalidOperationException($"EventHandlerType for event '{EventName}' is null on type '{bindable.GetType().Name}'");
_eventHandler = methodInfo.CreateDelegate(_eventInfo.EventHandlerType, this);
_eventInfo.AddEventHandler(bindable, _eventHandler);
} }
protected override void OnDetachingFrom(VisualElement bindable) protected override void OnDetachingFrom(VisualElement bindable)
{ {
base.OnDetachingFrom(bindable); base.OnDetachingFrom(bindable);
if (eventInfo != null && eventHandler != null) if (_eventInfo != null && _eventHandler != null)
eventInfo.RemoveEventHandler(bindable, eventHandler); _eventInfo.RemoveEventHandler(bindable, _eventHandler);
} }
private void OnEvent(object sender, object eventArgs) private void OnEvent(object sender, object eventArgs)

View File

@ -52,14 +52,14 @@ public class CombinedRepository : ICombinedRepository
gp.GamePointId, gp.GamePointId,
gp.GameRoundId, gp.GameRoundId,
gp.GameRoundRegNr, gp.GameRoundRegNr,
gp.GameRegPoints, latest.totPoints as GameRegPoints,
gr.GameRoundStartDate, gr.GameRoundStartDate,
gr.GameStatus AS Status, gr.GameStatus AS Status,
p.ParticipantId, p.ParticipantId,
(p.LastName || ' ' || p.FirstName) AS ParticipantName (p.LastName || ' ' || p.FirstName) AS ParticipantName
FROM GamePoints gp FROM GamePoints gp
INNER JOIN ( INNER JOIN (
SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId , sum(GameRegPoints) AS totPoints
FROM GamePoints FROM GamePoints
GROUP BY ParticipantId, GameRoundId GROUP BY ParticipantId, GameRoundId
) latest ON gp.GamePointId = latest.MaxGamePointId ) latest ON gp.GamePointId = latest.MaxGamePointId
@ -74,7 +74,7 @@ public class CombinedRepository : ICombinedRepository
public IEnumerable<RoundBuilderElement> roundBuilderElementsDbById(int GameId) public IEnumerable<RoundBuilderElement> roundBuilderElementsDbById(int GameId)
{ {
var result = _context.RoundBuilderElements var result = _context.RoundBuilderElements
.FromSqlRaw($@" .FromSql($@"
SELECT SELECT
gp.GamePointId, gp.GamePointId,
gp.GameRoundId, gp.GameRoundId,

View File

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -5,5 +5,7 @@ public enum GamePointStatus
New = 0, New = 0,
InProgress = 1, InProgress = 1,
Completed = 2, Completed = 2,
Cancelled = 3 Cancelled = 3,
Winning = 4,
Winner = 5
} }

View File

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -123,6 +123,4 @@ public class RoundBuilderElement : EntityBase
} }
} }

View File

@ -2,7 +2,12 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

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

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

@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFrameworks>
net9.0-android;
net9.0-ios;
net9.0-maccatalyst;
net9.0-windows10.0.19041
</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>

View File

@ -0,0 +1,9 @@
namespace GreadyPoang.Core;
public interface INavigationService
{
Task NavigateToAsync(string route);
Task NavigateToPageAsync(Page page);
}

View File

@ -0,0 +1,6 @@
namespace GreadyPoang.Core;
public interface IPageFactory
{
Page CreateRoundPage();
}

View File

@ -0,0 +1,9 @@

namespace GreadyPoang.Core;
public interface ISplashService
{
Task ShowSplash(string text = "Välkommen!", int durationMs = 3000);
Task HideAsync();
}

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

@ -0,0 +1,30 @@
using Common.Library;
using GreadyPoang.Services;
namespace GreadyPoang.ViewModelLayer;
public class MainPageViewModel : ViewModelBase
{
private readonly AppShellViewModel _appShell;
private readonly IObjectMessageService _messageService;
public MainPageViewModel(
AppShellViewModel appShell,
IObjectMessageService messageService
) : base()
{
_appShell = appShell;
_messageService = messageService;
}
public void InitMessage()
{
if (_appShell.RoundRunningVisible == false)
{
_messageService.Delivered = true;
}
}
}

View File

@ -1,5 +1,6 @@
using Common.Library; using Common.Library;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -13,10 +14,16 @@ public class ParticipantViewModel : ViewModelBase
} }
public ParticipantViewModel(IRepository<Participant> repo, IMethodSharingService<Participant> sharingService) : base() public ParticipantViewModel(
IRepository<Participant> repo,
IMethodSharingService<Participant> sharingService,
AppShellViewModel appShell,
IObjectMessageService objectMessage) : base()
{ {
_Repository = repo; _Repository = repo;
_sharingService = sharingService; _sharingService = sharingService;
_appShell = appShell;
_objectMessage = objectMessage;
} }
#endregion #endregion
@ -26,6 +33,8 @@ public class ParticipantViewModel : ViewModelBase
private ObservableCollection<Participant> _ParticipantList = new(); private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<Participant>? _Repository; private readonly IRepository<Participant>? _Repository;
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly AppShellViewModel _appShell;
private readonly IObjectMessageService _objectMessage;
#endregion #endregion
#region public Properties #region public Properties
@ -55,6 +64,10 @@ public class ParticipantViewModel : ViewModelBase
#region Get Method #region Get Method
public ObservableCollection<Participant> Get() public ObservableCollection<Participant> Get()
{ {
if (_appShell.RoundRunningVisible == false)
{
_objectMessage.Delivered = true;
}
ParticipantList = _sharingService.Get(); ParticipantList = _sharingService.Get();
return ParticipantList; return ParticipantList;
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
@ -22,7 +23,9 @@ public class RoundRunningViewModel : ViewModelBase
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage IObjectMessageService objectMessage,
ISplashService splashService,
AppShellViewModel appShell
) : base() ) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
@ -30,16 +33,23 @@ public class RoundRunningViewModel : ViewModelBase
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined; _combined = combined;
_objectMessage = objectMessage; _objectMessage = objectMessage;
_splashService = splashService;
_appShell = appShell;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
_builderObject = new(); _builderObject = new();
_SplashShowing = false;
} }
private bool _SplashShowing;
private readonly IRepository<GameRound>? _roundsRepo; private readonly IRepository<GameRound>? _roundsRepo;
private readonly IRepository<GamePoint> _pointsRepo; private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined; private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage; private readonly IObjectMessageService _objectMessage;
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;
@ -52,6 +62,7 @@ public class RoundRunningViewModel : ViewModelBase
RebuildRequested?.Invoke(this, EventArgs.Empty); RebuildRequested?.Invoke(this, EventArgs.Empty);
} }
// Översta raden
public ObservableCollection<RoundBuilderElement> RoundElements public ObservableCollection<RoundBuilderElement> RoundElements
{ {
get { return _roundElements; } get { return _roundElements; }
@ -62,6 +73,7 @@ public class RoundRunningViewModel : ViewModelBase
} }
} }
// Nedersta strukturen
public Collection<PlayerColumn> PlayerColumns public Collection<PlayerColumn> PlayerColumns
{ {
get { return _playerColumns; } get { return _playerColumns; }
@ -82,13 +94,30 @@ 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()
{ {
//_overlay.ShowSplash("Laddar...", 30);
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)
@ -97,7 +126,7 @@ public class RoundRunningViewModel : ViewModelBase
} }
foreach (var item in _objectMessage.CurrentGroup.Elements) foreach (var item in _objectMessage.CurrentGroup.Elements)
{ {
_roundElements.Add(item); RoundElements.Add(item);
} }
// Räkna ut vem som är nästa spelare // Räkna ut vem som är nästa spelare
@ -113,6 +142,10 @@ public class RoundRunningViewModel : ViewModelBase
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId); var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
FillupResultTable(localElements); FillupResultTable(localElements);
foreach (var col in _playerColumns)
{
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
}
TriggerRebuild(); TriggerRebuild();
} }
return RoundElements; return RoundElements;
@ -181,8 +214,6 @@ public class RoundRunningViewModel : ViewModelBase
return -1; return -1;
} }
private void FillupResultTable(IEnumerable<RoundBuilderElement> elements) private void FillupResultTable(IEnumerable<RoundBuilderElement> elements)
{ {
if (_playerColumns != null) if (_playerColumns != null)
@ -217,6 +248,11 @@ public class RoundRunningViewModel : ViewModelBase
{ {
player.Values.Add(element.GameRegPoints.ToString()); player.Values.Add(element.GameRegPoints.ToString());
player.PlayerPoints += element.GameRegPoints; player.PlayerPoints += element.GameRegPoints;
if (player.PlayerPoints > 10000)
{
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
winner.Status = GamePointStatus.Winning;
}
} }
//oldPart = element.ParticipantId; //oldPart = element.ParticipantId;
@ -247,6 +283,27 @@ 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;
}
}
public void GobackAsync()
{
_appShell.RoundRunningVisible = true;
}
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
@ -12,7 +13,6 @@ public class RoundStartingViewModel : ViewModelBase
#region Constructors #region Constructors
public RoundStartingViewModel() : base() public RoundStartingViewModel() : base()
{ {
} }
public RoundStartingViewModel( public RoundStartingViewModel(
@ -20,13 +20,22 @@ public class RoundStartingViewModel : ViewModelBase
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage) : base() IObjectMessageService objectMessage,
INavigationService nav,
IPageFactory factory,
ISplashService splashService,
AppShellViewModel appShellView
) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
_pointsRepo = pointsRepo; _pointsRepo = pointsRepo;
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined; _combined = combined;
_objectMessage = objectMessage; _objectMessage = objectMessage;
_nav = nav;
_factory = factory;
_splashService = splashService;
_appShellView = appShellView;
_roundElements = new ObservableCollection<RoundBuilderElement>(); _roundElements = new ObservableCollection<RoundBuilderElement>();
} }
@ -40,6 +49,10 @@ public class RoundStartingViewModel : ViewModelBase
private readonly IMethodSharingService<Participant> _sharingService; private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined; private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage; private readonly IObjectMessageService _objectMessage;
private readonly INavigationService _nav;
private readonly IPageFactory _factory;
private readonly ISplashService _splashService;
private readonly AppShellViewModel _appShellView;
private Participant _selectedItem; private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements; private ObservableCollection<RoundBuilderElement> _roundElements;
@ -232,17 +245,25 @@ public class RoundStartingViewModel : ViewModelBase
RoundElements.Clear(); RoundElements.Clear();
} }
public void RoundSelected(RoundBuilderElement element) public async void RoundSelected(RoundBuilderElement element)
{ {
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId); var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}"); Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
if (rbGroup != null) if (rbGroup != null)
{ {
_objectMessage.CurrentGroup = rbGroup; _objectMessage.CurrentGroup = rbGroup;
Shell.Current.GoToAsync("//RoundRunningView"); _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();
//_nav.NavigateToPageAsync(page);
} }
} }
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{ {
Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}"); Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}");

View File

@ -0,0 +1,103 @@
using Common.Library;
namespace GreadyPoang.ViewModelLayer;
public class SplashViewModel : ViewModelBase
{
// public event PropertyChangedEventHandler PropertyChanged;
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;
set
{
_isSplashVisible = value;
RaisePropertyChanged(nameof(IsSplashVisible));
}
}
private double _splashOpacity = 1.0;
public double SplashOpacity
{
get => _splashOpacity;
set
{
_splashOpacity = value;
RaisePropertyChanged(nameof(SplashOpacity));
}
}
private Color _splashTextColor = Colors.White;
public Color SplashTextColor
{
get { return _splashTextColor; }
set
{
_splashTextColor = value;
RaisePropertyChanged(nameof(SplashTextColor));
}
}
private double _splashTranslationY = 0;
public double SplashTranslationY
{
get => _splashTranslationY;
set
{
_splashTranslationY = value;
RaisePropertyChanged(nameof(SplashTranslationY));
}
}
public async Task HideSplashAsync()
{
await Task.Delay(1000); // Simulera laddning
await AnimateSplashOut();
IsSplashVisible = false;
}
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;
await Task.Delay(30);
}
}
}

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4 VisualStudioVersion = 17.14.36518.9 d17.14
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang", "GreadyPoang\GreadyPoang.csproj", "{B237F7D6-3B04-49AE-81B0-FEFE21A94CA7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreadyPoang", "GreadyPoang\GreadyPoang.csproj", "{B237F7D6-3B04-49AE-81B0-FEFE21A94CA7}"
EndProject EndProject

View File

@ -1,18 +1,38 @@
using GreadyPoang.DataLayer.Database; using GreadyPoang.DataLayer.Database;
using System.Diagnostics;
namespace GreadyPoang;
namespace GreadyPoang
{
public partial class App : Application public partial class App : Application
{ {
public App(DataContext dataContext) private readonly IServiceProvider _services;
public App(IServiceProvider services, DataContext dataContext)
{ {
InitializeComponent(); InitializeComponent();
dataContext.Database.EnsureCreated(); dataContext.Database.EnsureCreated();
_services = services;
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
if (Debugger.IsAttached)
Debugger.Break();
};
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
if (Debugger.IsAttached)
Debugger.Break();
};
} }
protected override Window CreateWindow(IActivationState? activationState) protected override Window CreateWindow(IActivationState? activationState)
{ {
return new Window(new AppShell());
} //var splashVm = ServiceLocator.Services.GetRequiredService<SplashViewModelCommands>();
//var shell = new AppShell(splashVm);
var shell = _services.GetRequiredService<AppShell>();
return new Window(shell);
} }
} }

View File

@ -3,28 +3,28 @@
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.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:views="clr-namespace:GreadyPoang.Views" xmlns:views="clr-namespace:GreadyPoang.Views"
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>
<ShellContent <ShellContent
Title="Home" Title="Home" ContentTemplate="{DataTemplate local:MainPage}"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" /> Route="MainPage" />
<ShellContent <ShellContent
Title="Deltagare" Title="Deltagare" ContentTemplate="{DataTemplate pages:ParticipantListPage}"
ContentTemplate="{DataTemplate views:ParticipantListView}" Route="ParticipantListPage"/>
Route="ParticipantListView" />
<ShellContent <ShellContent
Title="Starta Ny Runda" Title="Ny Runda" ContentTemplate="{DataTemplate pages:RoundStartingPage}"
ContentTemplate="{DataTemplate views:RoundStartingView}" Route="RoundStartingPage"/>
Route="RoundStartingView" />
<ShellContent <ShellContent
Title="Påbörja eller fortsätt Runda" Title="Påbörja eller fortsätt Runda" ContentTemplate="{DataTemplate pages:RoundRunningPage}"
ContentTemplate="{DataTemplate views:RoundRunningView}" Route="RoundRunningPage" IsVisible="{Binding RoundRunningVisible}"/>
Route="RoundRunningView" />
</TabBar> </TabBar>
</Shell> </Shell>

View File

@ -1,10 +1,21 @@
namespace GreadyPoang using GreadyPoang.Core;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang
{ {
public partial class AppShell : Shell public partial class AppShell : Shell
{ {
public AppShell() private readonly IPageFactory _factory;
public AppShell(IPageFactory factory, AppShellViewModel appShellView)
{ {
InitializeComponent(); InitializeComponent();
Routing.RegisterRoute("RoundStartingPage", typeof(Pages.RoundStartingPage));
Routing.RegisterRoute("ParticipantListPage", typeof(Pages.ParticipantListPage));
Routing.RegisterRoute("RoundRunningPage", typeof(Pages.RoundRunningPage));
_factory = factory;
BindingContext = appShellView;
} }
} }
} }

40
GreadyPoang/BasePage.xaml Normal file
View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GreadyPoang.BasePage"
xmlns:viewsPartial="clr-namespace:GreadyPoang.ViewsPartial"
x:Name="Root">
<AbsoluteLayout>
<!-- Huvudinnehåll -->
<ContentView x:Name="MainContent"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All" />
<!-- Overlay: Splash -->
<viewsPartial:SplashView
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
x:Name="SplashView"
IsVisible="True"
Opacity="1"
ZIndex="999"
TranslationY="{Binding SplashTranslationY}"
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

@ -0,0 +1,13 @@
using GreadyPoang.CommandClasses;
namespace GreadyPoang;
public partial class BasePage : ContentPage
{
public BasePage(View content, SplashViewModelCommands splashVm)
{
InitializeComponent();
MainContent.Content = content;
SplashView.BindingContext = splashVm;
}
}

View File

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

View File

@ -0,0 +1,15 @@
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.CommandClasses;
public class MainPageViewModelCommands : MainPageViewModel
{
public MainPageViewModelCommands(
AppShellViewModel appShell,
IObjectMessageService messageService
) : base(appShell, messageService)
{
}
}

View File

@ -1,8 +1,10 @@
using Common.Library; using Common.Library;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using System.Windows.Input; using System.Windows.Input;
namespace GreadyPoang.CommandClasses; namespace GreadyPoang.CommandClasses;
public class ParticipantViewModelCommands : ParticipantViewModel public class ParticipantViewModelCommands : ParticipantViewModel
@ -10,9 +12,13 @@ public class ParticipantViewModelCommands : ParticipantViewModel
#region constructors #region constructors
public ParticipantViewModelCommands() : base() public ParticipantViewModelCommands() : base()
{ {
} }
public ParticipantViewModelCommands(IRepository<Participant> repo, IMethodSharingService<Participant> sharingService) : base(repo, sharingService)
public ParticipantViewModelCommands(
IRepository<Participant> repo,
IMethodSharingService<Participant> sharingService,
AppShellViewModel appShell,
IObjectMessageService objectMessage) : base(repo, sharingService, appShell, objectMessage)
{ {
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
@ -18,22 +19,23 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage) IObjectMessageService objectMessage,
ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo, : base(roundsRepo,
pointsRepo, pointsRepo,
sharingService, sharingService,
combined, combined,
objectMessage) objectMessage,
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; }
#endregion #endregion
@ -41,16 +43,25 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
{ {
base.Init(); base.Init();
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync()); StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
//EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0); OnSplashClickedCommand = new Command(async () => await ToggleSplash());
//RensaCommand = new Command(async () => RensaAsync()); GobackCommand = new Command(async () => GobackAsync());
//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()
{ {
base.StoreAndHandlePoints(); base.StoreAndHandlePoints();
await Shell.Current.GoToAsync(".."); //await Shell.Current.GoToAsync("..");
// await Shell.Current.GoToAsync("RoundRunningPage");
}
private async Task ToggleSplash()
{
base.ToggleSplash();
} }
} }

View File

@ -1,4 +1,5 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
@ -18,12 +19,20 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage) IObjectMessageService objectMessage,
INavigationService nav,
IPageFactory factory,
ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo, : base(roundsRepo,
pointsRepo, pointsRepo,
sharingService, sharingService,
combined, combined,
objectMessage) objectMessage,
nav,
factory,
splashService,
appShell)
{ {
} }
@ -101,7 +110,6 @@ public class RoundStartingViewModelCommands : RoundStartingViewModel
base.SelectNewlyAddedParticipant(roundBuilder); base.SelectNewlyAddedParticipant(roundBuilder);
goneOk = true; goneOk = true;
return goneOk; return goneOk;
} }
} }

View File

@ -0,0 +1,10 @@
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.CommandClasses;
public class SplashViewModelCommands : SplashViewModel
{
public SplashViewModelCommands() : base()
{
}
}

View File

@ -0,0 +1,11 @@
namespace GreadyPoang.Core;
public class NavigationService : INavigationService
{
public Task NavigateToAsync(string route)
=> Shell.Current.GoToAsync(route);
public Task NavigateToPageAsync(Page page)
=> Shell.Current.Navigation.PushAsync(page);
}

View File

@ -0,0 +1,30 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Core;
using GreadyPoang.Pages;
namespace GreadyPoang;
public class PageFactory : IPageFactory
{
private readonly IServiceProvider _services;
public PageFactory(IServiceProvider services)
{
_services = services;
}
public Page CreateRoundPage()
{
var vm = _services.GetRequiredService<RoundRunningViewModelCommands>();
var splashVm = _services.GetRequiredService<SplashViewModelCommands>();
return new RoundRunningPage(vm, splashVm);
}
//public Page CreateStatsPage()
//{
// //var vm = _services.GetRequiredService<StatsViewModel>();
// //var splashVm = _services.GetRequiredService<SplashViewModelCommands>();
// //var view = new StatsView { BindingContext = vm };
// //return new StatsPage(view, splashVm);
//}
}

View File

@ -0,0 +1,10 @@
using GreadyPoang.InterFaces;
namespace GreadyPoang;
public class ServiceLocator : IServiceLocator
{
public static IServiceProvider? Services { get; set; } = default;
public T Get<T>() => (T)Services!.GetService(typeof(T))!;
}

View File

@ -70,7 +70,7 @@
<ProjectReference Include="..\GreadyPoang.Common\GreadyPoang.Common.csproj" /> <ProjectReference Include="..\GreadyPoang.Common\GreadyPoang.Common.csproj" />
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
<ProjectReference Include="..\GreadyPoang.Services\GreadyPoang.Services.csproj" /> <!--<ProjectReference Include="..\GreadyPoang.Services\GreadyPoang.Services.csproj" />-->
<ProjectReference Include="..\GreadyPoang.ViewModelLayer\GreadyPoang.ViewModelLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.ViewModelLayer\GreadyPoang.ViewModelLayer.csproj" />
</ItemGroup> </ItemGroup>
@ -81,6 +81,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MauiXaml Update="BasePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Resources\Styles\AppStyles.xaml"> <MauiXaml Update="Resources\Styles\AppStyles.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
@ -96,6 +99,9 @@
<MauiXaml Update="Views\RoundStartingView.xaml"> <MauiXaml Update="Views\RoundStartingView.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="ViewsPartial\SplashView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GreadyPoang.InterFaces;
public interface IServiceLocator
{
T Get<T>();
}

View File

@ -0,0 +1,34 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Core;
namespace GreadyPoang.LocalServices;
public class SplashService : ISplashService
{
private readonly SplashViewModelCommands _viewModel;
public SplashService(SplashViewModelCommands viewModel)
{
_viewModel = viewModel;
}
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.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

@ -3,6 +3,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.MainPage" x:Class="GreadyPoang.MainPage"
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
x:DataType="vm:MainPageViewModelCommands"
Background="LightCyan" Background="LightCyan"
Title="{StaticResource ApplicationTitle}"> Title="{StaticResource ApplicationTitle}">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
@ -12,7 +14,8 @@
ViewDescription="Välkommen till Gready"> ViewDescription="Välkommen till Gready">
</partial:HeaderView> </partial:HeaderView>
<Image Source="snurrtarning.gif" <Image
Source="snurrtarning.gif"
IsAnimationPlaying="True" IsAnimationPlaying="True"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"

View File

@ -1,11 +1,23 @@
namespace GreadyPoang; using GreadyPoang.CommandClasses;
namespace GreadyPoang;
public partial class MainPage : ContentPage public partial class MainPage : ContentPage
{ {
private readonly MainPageViewModelCommands _mainPage;
public MainPage() public MainPage(
MainPageViewModelCommands mainPage)
{ {
InitializeComponent(); InitializeComponent();
BindingContext = mainPage;
_mainPage = mainPage;
}
protected override void OnAppearing()
{
base.OnAppearing();
_mainPage.InitMessage();
} }
} }

View File

@ -1,8 +1,11 @@
using Common.Library; using Common.Library;
using GreadyPoang.CommandClasses; using GreadyPoang.CommandClasses;
using GreadyPoang.Core;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.DataLayer.Database; using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.InterFaces;
using GreadyPoang.LocalServices;
using GreadyPoang.Services; using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using GreadyPoang.Views; using GreadyPoang.Views;
@ -38,6 +41,10 @@ public static class MauiProgram
options.UseSqlite($"Data Source={dbPath}"); options.UseSqlite($"Data Source={dbPath}");
}); });
builder.Services.AddScoped<IPageFactory, PageFactory>();
builder.Services.AddSingleton<INavigationService, NavigationService>();
builder.Services.AddSingleton<IServiceLocator, ServiceLocator>();
builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>(); builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
builder.Services.AddScoped<ParticipantViewModelCommands>(); builder.Services.AddScoped<ParticipantViewModelCommands>();
builder.Services.AddScoped<ParticipantListView>(); builder.Services.AddScoped<ParticipantListView>();
@ -46,22 +53,29 @@ public static class MauiProgram
builder.Services.AddScoped<RoundStartingViewModelCommands>(); builder.Services.AddScoped<RoundStartingViewModelCommands>();
builder.Services.AddScoped<RoundStartingView>(); builder.Services.AddScoped<RoundStartingView>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>(); builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>();
builder.Services.AddScoped<RoundRunningViewModelCommands>(); builder.Services.AddScoped<RoundRunningViewModelCommands>();
builder.Services.AddScoped<RoundRunningView>(); builder.Services.AddScoped<RoundRunningView>();
builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>();
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>(); builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<ICombinedRepository, CombinedRepository>(); builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddSingleton<AppShellViewModel>();
builder.Services.AddSingleton<AppShell>();
builder.Services.AddSingleton<SplashViewModelCommands>();
builder.Services.AddSingleton<ISplashService, SplashService>();
builder.Services.AddSingleton<MainPageViewModelCommands>();
#if DEBUG #if DEBUG
builder.Logging.AddDebug(); builder.Logging.AddDebug();
#endif #endif
var app = builder.Build();
return builder.Build(); ServiceLocator.Services = app.Services;
return app;
} }
} }

View File

@ -0,0 +1,24 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Views;
namespace GreadyPoang.Pages;
public class ParticipantListPage : BasePage
{
private readonly ParticipantViewModelCommands _vm;
public ParticipantListPage(ParticipantViewModelCommands vm, SplashViewModelCommands splashVm)
: base(new ParticipantListView(vm), splashVm)
{
Title = "Deltagar Lista";
_vm = vm;
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = _vm;
_vm.Get();
}
}

View File

@ -0,0 +1,43 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Core;
using GreadyPoang.Views;
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 = "Starta/Fortsätt runda";
_vm = Vm;
Splash = ServiceLocator.Services?.GetRequiredService<ISplashService>();
_splashVm = splashVm;
}
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;
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

@ -0,0 +1,25 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.Views;
namespace GreadyPoang.Pages;
public class RoundStartingPage : BasePage
{
private readonly RoundStartingViewModelCommands _vm;
public RoundStartingPage(RoundStartingViewModelCommands vm, SplashViewModelCommands splashVm)
: base(new RoundStartingView(vm), splashVm)
{
Title = "Starta ny Runda";
_vm = vm;
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = _vm;
_vm.Get();
_vm.GetParticipants();
}
}

View File

@ -55,6 +55,12 @@
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Cancelled"> <DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Cancelled">
<Setter Property="BackgroundColor" Value="LightCoral" /> <Setter Property="BackgroundColor" Value="LightCoral" />
</DataTrigger> </DataTrigger>
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Winning">
<Setter Property="BackgroundColor" Value="Yellow" />
</DataTrigger>
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Winner">
<Setter Property="BackgroundColor" Value="Red" />
</DataTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView 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:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses" xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:Class="GreadyPoang.Views.ParticipantListView" x:Class="GreadyPoang.Views.ParticipantListView"
x:DataType="vm:ParticipantViewModelCommands" x:DataType="vm:ParticipantViewModelCommands"
x:Name="ParticipantListPage" x:Name="ParticipantListPage">
Title="Deltagar Lista"> <!--Title="Deltagar Lista"-->
<Border Style="{StaticResource Border.Page}" StrokeThickness="4"> <Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
@ -86,4 +86,4 @@
</Border> </Border>
</Grid> </Grid>
</Border> </Border>
</ContentPage> </ContentView>

View File

@ -2,7 +2,7 @@ using GreadyPoang.CommandClasses;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class ParticipantListView : ContentPage public partial class ParticipantListView : ContentView
{ {
public ParticipantListView(ParticipantViewModelCommands viewModel) public ParticipantListView(ParticipantViewModelCommands viewModel)
{ {
@ -13,15 +13,12 @@ public partial class ParticipantListView : ContentPage
public ParticipantViewModelCommands ViewModel { get; set; } public ParticipantViewModelCommands ViewModel { get; set; }
public int ParticipantId { get; set; } public int ParticipantId { get; set; }
protected override void OnAppearing() //protected override void OnAppearing()
{ //{
base.OnAppearing(); // base.OnAppearing();
BindingContext = ViewModel; // BindingContext = ViewModel;
ViewModel.Get(); // ViewModel.Get();
} //}
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView 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:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundRunningView" x:Class="GreadyPoang.Views.RoundRunningView"
@ -7,8 +7,8 @@
xmlns:behaviors="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common" xmlns:behaviors="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common"
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModelCommands" x:DataType="vm:RoundRunningViewModelCommands">
Title="RoundRunningView"> <!--Title="RoundRunningView"-->
<Border Style="{StaticResource Border.Page}" StrokeThickness="4"> <Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
@ -34,6 +34,7 @@
Padding="10" Padding="10"
Margin="5" Margin="5"
StrokeShape="RoundRectangle 10" StrokeShape="RoundRectangle 10"
BackgroundColor="{Binding OverrideColor}"
Style="{StaticResource StatusBorderStyle}"> Style="{StaticResource StatusBorderStyle}">
<Border.GestureRecognizers> <Border.GestureRecognizers>
<TapGestureRecognizer <TapGestureRecognizer
@ -83,8 +84,21 @@
</Entry> </Entry>
</Grid> </Grid>
<Button Text="Register Points" <Button Text="Register Points"
WidthRequest="100"
Style="{StaticResource HoverButtonRedStyle}" Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding StoreAndHandlePointsCommand}"/> Command="{Binding StoreAndHandlePointsCommand}"/>
<VerticalStackLayout >
<Button Text="Visa Splash"
WidthRequest="100"
Style="{StaticResource HoverButtonBlueStyle}"
Command="{Binding OnSplashClickedCommand}"/>
<Button Text="Återgå"
WidthRequest="100"
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">
@ -98,4 +112,4 @@
</ScrollView> </ScrollView>
</Grid> </Grid>
</Border> </Border>
</ContentPage> </ContentView>

View File

@ -3,25 +3,17 @@ using GreadyPoang.EntityLayer;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class RoundRunningView : ContentPage public partial class RoundRunningView : ContentView
{ {
public RoundRunningView(RoundRunningViewModelCommands viewModel) public RoundRunningView(RoundRunningViewModelCommands viewModel)
{ {
InitializeComponent(); InitializeComponent();
ViewModel = viewModel; ViewModel = viewModel;
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
ViewModel.Get();
//BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
ViewModel.RebuildRequested += ViewModel_RebuildRequested; ViewModel.RebuildRequested += ViewModel_RebuildRequested;
} }
private void ViewModel_RebuildRequested(object? sender, EventArgs e) private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{ {
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentView 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:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundStartingView" x:Class="GreadyPoang.Views.RoundStartingView"
@ -7,8 +7,8 @@
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundStartingViewModelCommands" x:DataType="vm:RoundStartingViewModelCommands"
x:Name="GameRoundStartingPage" x:Name="GameRoundStartingPage">
Title="Starta ny Runda"> <!--Title="Starta ny Runda"-->
@ -151,4 +151,4 @@
</Border> </Border>
</Grid> </Grid>
</Border> </Border>
</ContentPage> </ContentView>

View File

@ -2,7 +2,7 @@ using GreadyPoang.CommandClasses;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class RoundStartingView : ContentPage public partial class RoundStartingView : ContentView
{ {
@ -15,28 +15,24 @@ public partial class RoundStartingView : ContentPage
public int GameRoundId { get; set; } public int GameRoundId { get; set; }
protected override void OnAppearing() //protected override void OnAppearing()
{ //{
base.OnAppearing(); // base.OnAppearing();
BindingContext = ViewModel; // BindingContext = ViewModel;
ViewModel.Get(); // ViewModel.Get();
ViewModel.GetParticipants(); // ViewModel.GetParticipants();
} //}
protected override void OnSizeAllocated(double width, double height) protected override void OnSizeAllocated(double width, double height)
{ {
base.OnSizeAllocated(width, height); base.OnSizeAllocated(width, height);
if (width < 500) if (ResponsiveStack == null || width <= 0)
{ return;
VisualStateManager.GoToState(ResponsiveStack, "Narrow");
System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack=Narrow "); var state = width < 500 ? "Narrow" : "Wide";
} VisualStateManager.GoToState(ResponsiveStack, state);
else System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack={state} ");
{
VisualStateManager.GoToState(ResponsiveStack, "Wide");
System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack=Wide ");
}
} }

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Views/SplashView.xaml -->
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
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}">-->
<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"
Opacity="{Binding SplashOpacity}">
<StackLayout>
<!--<Image Source="{Binding SplashImage}" HeightRequest="60" />-->
<Label Text="{Binding SplashText}"
FontSize="18"
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="{Binding SplashTextColor}"/>
</StackLayout>
</Border>
</ContentView>

View File

@ -0,0 +1,18 @@
using GreadyPoang.CommandClasses;
namespace GreadyPoang.ViewsPartial;
public partial class SplashView : ContentView
{
public SplashView()
{
InitializeComponent();
}
public SplashViewModelCommands ViewModel
{
get => (SplashViewModelCommands)BindingContext;
set => BindingContext = value;
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>