Compare commits

16 Commits

Author SHA1 Message Date
6df80917ee Merge branch 'UtanSplash' of https://gitweb.tfoman.me/tfoman/GreadyPoang into UtanSplash 2025-10-28 08:01:42 +01:00
f48869205e begränsa utbredning neråt 2025-10-28 08:01:33 +01:00
d586c96ddf Små ändringar i roundrunning 2025-10-28 07:16:55 +01:00
5ff42f5bca Checkar in innan funktionen är klar 2025-10-25 08:46:52 +02:00
26ff51169f Nu fungerar RoundRunningView med minimal codeBehind 2025-10-22 10:42:39 +02:00
ecd3e90dbf RoundRunningView med nytt event "Loaded" triggas endast en gg när sidan är renderad 2025-10-20 16:46:38 +02:00
2797162a93 Nu är det ordning på popuperna 2025-10-19 23:18:51 +02:00
735788969a Med Popups och nytt system för släckning, men utan hantering av rätt popup 2025-10-19 16:33:19 +02:00
a8ca07a1bf Ordning på spelarnas poängsummor + popup i participant och i RoundRunning när någon är på väg att vinna 2025-10-18 09:52:49 +02:00
bb8f4bd5ed Nu fungerar Popupen och den går att stänga 2025-10-17 11:52:01 +02:00
21eb0d5498 Observable properties och RelayCommands införda 2025-10-14 21:57:37 +02:00
b4d6c6d530 Infört Observable Property överallt, där tillämpligt 2025-10-13 12:13:12 +02:00
b2dbb9993f Infört Observable Property och observable object från Community Toolkit 2025-10-13 08:59:26 +02:00
f5cc28f202 Före start av införande av Community Toolkit MVVM 2025-10-12 18:03:08 +02:00
469b0b3377 Nu fungerar det 2025-10-12 14:34:54 +02:00
ae05adc823 Poängräkningen fungerar 2025-10-12 09:41:14 +02:00
82 changed files with 1138 additions and 1841 deletions

View File

@ -1,29 +0,0 @@
using System.ComponentModel;
namespace Common.Library;
public abstract class CommonBase : INotifyPropertyChanged
{
#region Constructor
protected CommonBase()
{
Init();
}
#endregion
#region Init Method
public virtual void Init()
{
}
#endregion
#region RaisePropertyChanged Method
public event PropertyChangedEventHandler? PropertyChanged;
public virtual void RaisePropertyChanged(string propertyName)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}

View File

@ -1,5 +0,0 @@
namespace Common.Library;
public class EntityBase : CommonBase
{
}

View File

@ -1,14 +0,0 @@
//using GreadyPoang.DataLayer;
namespace Common.Library;
public class ViewModelBase : CommonBase
{
//private readonly LocalDbService _dbService;
//public ViewModelBase(LocalDbService dbService)
//{
// _dbService = dbService;
//}
}

View File

@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,39 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.Core;
public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
private bool isBusy;
protected async Task RunAsyncCommand(Func<Task> action, string loadingMessage = null, string errorMessage = "Ett fel inträffade")
{
if (IsBusy) return;
try
{
IsBusy = true;
if (!string.IsNullOrWhiteSpace(loadingMessage))
await Snackbar.Make(
message: loadingMessage,
duration: TimeSpan.FromSeconds(2),
action: null).Show();
await action.Invoke();
}
catch (Exception ex)
{
await Snackbar.Make(
message: $"{errorMessage}: {ex.Message}",
duration: TimeSpan.FromSeconds(3),
action: () => Console.WriteLine("Åtgärd vald")).Show();
}
finally
{
IsBusy = false;
}
}
}

View File

View File

@ -1,15 +0,0 @@
<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,9 +22,8 @@ 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,17 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" /> <PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" />
</ItemGroup> </ItemGroup>

View File

@ -2,27 +2,21 @@
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 required string EventName { get; set; } public 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,9 +15,8 @@ public class EventToCommandBehavior : BehaviorBase<VisualElement>
set => SetValue(CommandProperty, value); set => SetValue(CommandProperty, value);
} }
// Fix for CS8618: Make the field nullable and fix IDE1006: Add '_' prefix private EventInfo eventInfo;
private EventInfo? _eventInfo; private Delegate eventHandler;
private Delegate? _eventHandler;
protected override void OnAttachedTo(VisualElement bindable) protected override void OnAttachedTo(VisualElement bindable)
{ {
@ -26,29 +25,21 @@ public class EventToCommandBehavior : BehaviorBase<VisualElement>
if (bindable == null || string.IsNullOrEmpty(EventName)) if (bindable == null || string.IsNullOrEmpty(EventName))
return; return;
var runtimeEvent = bindable.GetType().GetRuntimeEvent(EventName); eventInfo = bindable.GetType().GetRuntimeEvent(EventName);
if (runtimeEvent == null) if (eventInfo == 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}'");
_eventInfo = runtimeEvent; MethodInfo methodInfo = typeof(EventToCommandBehavior).GetTypeInfo().GetDeclaredMethod(nameof(OnEvent));
eventHandler = methodInfo.CreateDelegate(eventInfo.EventHandlerType, this);
MethodInfo? methodInfo = typeof(EventToCommandBehavior).GetTypeInfo().GetDeclaredMethod(nameof(OnEvent)); eventInfo.AddEventHandler(bindable, eventHandler);
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

@ -0,0 +1,12 @@
using System.Globalization;
namespace GreadyPoang.Common;
public class HeaderColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
(bool)value ? Colors.DarkGray : Colors.Yellow;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotImplementedException();
}

View File

@ -0,0 +1,35 @@
using System.Windows.Input;
namespace GreadyPoang.Common;
public class LoadedBehavior
{
public static readonly BindableProperty CommandProperty =
BindableProperty.CreateAttached(
"Command",
typeof(ICommand),
typeof(LoadedBehavior),
null,
propertyChanged: OnCommandChanged);
public static ICommand GetCommand(BindableObject view) =>
(ICommand)view.GetValue(CommandProperty);
public static void SetCommand(BindableObject view, ICommand value) =>
view.SetValue(CommandProperty, value);
private static void OnCommandChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is VisualElement element && newValue is ICommand command)
{
element.Loaded += (s, e) =>
{
if (command.CanExecute(null))
{
command.Execute(null);
}
};
}
}
}

View File

@ -59,7 +59,7 @@ public class CombinedRepository : ICombinedRepository
(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 , sum(GameRegPoints) AS totPoints 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
.FromSql($@" .FromSqlRaw($@"
SELECT SELECT
gp.GamePointId, gp.GamePointId,
gp.GameRoundId, gp.GameRoundId,

View File

@ -1,12 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
@ -16,6 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,97 +1,42 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
using SQLite; using SQLite;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
[Table("GamePoint")] [Table("GamePoint")]
public class GamePoint : EntityBase public partial class GamePoint : ObservableObject
{ {
public GamePoint() public GamePoint()
{ {
_gamePointId = 0; GamePointId = 0;
_participantId = 0; ParticipantId = 0;
_gameRoundId = 0; GameRoundId = 0;
_gameDate = DateTime.Now; GameDate = DateTime.Now;
_gameRoundRegNr = 0; GameRoundRegNr = 0;
_gameRegPoints = 0; GameRegPoints = 0;
} }
private int _gamePointId; [ObservableProperty]
private int _participantId; [property: PrimaryKey, AutoIncrement, Column("GamePointId")]
private int _gameRoundId; private int gamePointId;
private DateTime _gameDate;
private int _gameRoundRegNr;
private int _gameRegPoints;
[PrimaryKey] [ObservableProperty]
[AutoIncrement] [property: Column("ParticipantId")]
[Column("GamePointId")] private int participantId;
public int GamePointId
{
get { return _gamePointId; }
set
{
_gamePointId = value;
RaisePropertyChanged(nameof(GamePointId));
}
}
[Column("ParticipantId")] [ObservableProperty]
public int ParticipantId [property: Column("GameRoundId")]
{ private int gameRoundId;
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[Column("GameRoundId")]
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
}
[Column("GameDate")] [ObservableProperty]
public DateTime GameDate [property: Column("GameDate")]
{ private DateTime gameDate;
get { return _gameDate; }
set
{
_gameDate = value;
RaisePropertyChanged(nameof(GameDate));
}
}
// GameRoundRegNr räknas upp när en spelare får en ny gamepoint inlagd
// Alltså hans/hennes senaste i samma runda uppräknad med 1
[Column("GameRoundRegNr")]
public int GameRoundRegNr
{
get { return _gameRoundRegNr; }
set
{
_gameRoundRegNr = value;
RaisePropertyChanged(nameof(GameRoundRegNr));
}
}
[Column("GameRegPoints")]
public int GameRegPoints
{
get { return _gameRegPoints; }
set
{
_gameRegPoints = value;
RaisePropertyChanged(nameof(GameRegPoints));
}
}
[ObservableProperty]
[property: Column("GameRoundRegNr")]
private int gameRoundRegNr;
[ObservableProperty]
[property: Column("GameRegPoints")]
private int gameRegPoints;
} }

View File

@ -1,4 +1,4 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
using SQLite; using SQLite;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
@ -6,72 +6,34 @@ namespace GreadyPoang.EntityLayer;
[Table("GameRound")] [Table("GameRound")]
public class GameRound : EntityBase public partial class GameRound : ObservableObject
{ {
public GameRound() public GameRound()
{ {
_gameRoundId = 0; GameRoundId = 0;
_gameRoundStartDate = DateTime.Now; GameRoundStartDate = DateTime.Now;
_gameStatus = GamePointStatus.New; GameStatus = GamePointStatus.New;
_gameRoundFinished = null; GameRoundFinished = null;
} }
private int _gameRoundId; [ObservableProperty]
private DateTime _gameRoundStartDate; [property: PrimaryKey, AutoIncrement, Column("GameRoundId")]
private GamePointStatus _gameStatus; private int gameRoundId;
private DateTime? _gameRoundFinished;
[Column("GameRoundFinished")] [ObservableProperty]
public DateTime? GameRoundFinished [property: Column("GameRoundStartDate")]
{ private DateTime gameRoundStartDate;
get { return _gameRoundFinished; }
set
{
_gameRoundFinished = value;
RaisePropertyChanged(nameof(GameRoundFinished));
}
}
[Column("GameRoundStartDate")] [ObservableProperty]
public DateTime GameRoundStartDate [property: Column("GameStatus")]
{ private GamePointStatus gameStatus;
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
RaisePropertyChanged(nameof(GameRoundStartDate));
}
}
[Column("GameStatus")] [ObservableProperty]
public GamePointStatus GameStatus [property: Column("GameRoundFinished")]
{ private DateTime? gameRoundFinished;
get { return _gameStatus; }
set
{
_gameStatus = value;
RaisePropertyChanged(nameof(GameStatus));
}
}
[PrimaryKey]
[AutoIncrement]
[Column("GameRoundId")]
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
}
public string GameRoundStartDateString public string GameRoundStartDateString
{ {
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); } get { return GameRoundStartDate.ToString("yyyy-MM-dd"); }
} }
} }

View File

@ -1,67 +1,32 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
using SQLite; using SQLite;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
[Table("Participants")] [Table("Participants")]
public class Participant : EntityBase public partial class Participant : ObservableObject
{ {
public Participant() public Participant()
{ {
_firstName = string.Empty; FirstName = string.Empty;
_lastName = string.Empty; LastName = string.Empty;
_email = string.Empty; Email = string.Empty;
} }
private int _participantId; [ObservableProperty]
private string _firstName; [property: PrimaryKey, AutoIncrement, Column("ParticipantId")]
private string _lastName; private int participantId;
private string _email;
[PrimaryKey] [ObservableProperty]
[AutoIncrement] [property: Column("FirstName")]
[Column("ParticipantId")] private string firstName;
public int ParticipantId
{
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[Column("FirstName")] [ObservableProperty]
public string FirstName [property: Column("LastName")]
{ private string lastName;
get { return _firstName; }
set
{
_firstName = value;
RaisePropertyChanged(nameof(FirstName));
}
}
[Column("LastName")] [ObservableProperty]
public string LastName [property: Column("Email")]
{ private string email;
get { return _lastName; }
set
{
_lastName = value;
RaisePropertyChanged(nameof(LastName));
}
}
[Column("Email")]
public string Email
{
get { return _email; }
set
{
_email = value;
RaisePropertyChanged(nameof(Email));
}
}
public string FullName public string FullName
{ {

View File

@ -1,12 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
@ -16,6 +11,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" /> <PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.11" /> <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.11" />
</ItemGroup> </ItemGroup>

View File

@ -1,55 +1,27 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
public class PlayerColumn : EntityBase public partial class PlayerColumn : ObservableObject
{ {
public PlayerColumn() public PlayerColumn()
{ {
_playerName = string.Empty; PlayerName = string.Empty;
_values = new List<string>(); Values = new List<string>();
} }
private int _playerId; [ObservableProperty]
private string _playerName; private int playerId;
private List<string> _values;
public string PlayerName
{
get { return _playerName; }
set
{
_playerName = value;
RaisePropertyChanged(nameof(PlayerName));
}
}
public List<string> Values
{
get { return _values; }
set
{
_values = value;
RaisePropertyChanged(nameof(Values));
}
}
public int PlayerId [ObservableProperty]
{ private string playerName;
get { return _playerId; }
set
{
_playerId = value;
RaisePropertyChanged(nameof(PlayerId));
}
}
private int _playerPoints; [ObservableProperty]
private List<string> values;
public int PlayerPoints [ObservableProperty]
{ private int playerPoints;
get { return _playerPoints; }
set { _playerPoints = value; }
}
} }

View File

@ -1,125 +1,55 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
public class RoundBuilderElement : EntityBase public partial class RoundBuilderElement : ObservableObject
{ {
public RoundBuilderElement() public RoundBuilderElement()
{ {
_participantId = 0; ParticipantId = 0;
_participantName = string.Empty; ParticipantName = string.Empty;
_gameRoundRegNr = 0; GameRoundRegNr = 0;
_gameRegPoints = 0; GameRegPoints = 0;
_status = GamePointStatus.New; Status = GamePointStatus.New;
_gameRoundStartDate = DateTime.MinValue; GameRoundStartDate = DateTime.MinValue;
_gameRoundId = 0; GameRoundId = 0;
_gamePointId = 0; GamePointId = 0;
} }
private int _participantId; [ObservableProperty]
private string _participantName; private int participantId;
private int _gameRoundRegNr;
private int _gameRegPoints;
private GamePointStatus _status;
private DateTime _gameRoundStartDate;
private int _gameRoundId;
private int _gamePointId;
public int ParticipantId [ObservableProperty]
{ private string participantName;
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[ObservableProperty]
private int gameRoundRegNr;
public string ParticipantName [ObservableProperty]
{ private int gameRegPoints;
get { return _participantName; }
set
{
_participantName = value;
RaisePropertyChanged(nameof(ParticipantName));
}
}
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusString))]
private GamePointStatus status;
public int GameRoundRegNr [ObservableProperty]
{ [NotifyPropertyChangedFor(nameof(GameRoundStartDateString))]
get { return _gameRoundRegNr; } private DateTime gameRoundStartDate;
set
{
_gameRoundRegNr = value;
RaisePropertyChanged(nameof(GameRoundRegNr));
}
}
[ObservableProperty]
private int gameRoundId;
public int GameRegPoints [ObservableProperty]
{ private int gamePointId;
get { return _gameRegPoints; }
set
{
_gameRegPoints = value;
RaisePropertyChanged(nameof(GameRegPoints));
}
}
public GamePointStatus Status
{
get { return _status; }
set
{
_status = value;
RaisePropertyChanged(nameof(Status));
RaisePropertyChanged(nameof(StatusString));
}
}
public string StatusString public string StatusString
{ {
get { return _status.ToString(); } get { return status.ToString(); }
}
public DateTime GameRoundStartDate
{
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
RaisePropertyChanged(nameof(GameRoundStartDate));
RaisePropertyChanged(nameof(GameRoundStartDateString));
}
} }
public string GameRoundStartDateString public string GameRoundStartDateString
{ {
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); } get { return gameRoundStartDate.ToString("yyyy-MM-dd"); }
}
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
}
public int GamePointId
{
get { return _gamePointId; }
set
{
_gamePointId = value;
RaisePropertyChanged(nameof(GamePointId));
}
} }

View File

@ -1,56 +1,26 @@
using Common.Library; using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer; namespace GreadyPoang.EntityLayer;
public class RoundBuilderGroup : EntityBase public partial class RoundBuilderGroup : ObservableObject
{ {
public RoundBuilderGroup() public RoundBuilderGroup()
{ {
_gameRoundId = 0; GameRoundId = 0;
_gameRoundStartDate = DateTime.MinValue; GameRoundStartDate = DateTime.MinValue;
_status = GamePointStatus.New; Status = GamePointStatus.New;
_elements = new List<RoundBuilderElement>(); Elements = new List<RoundBuilderElement>();
}
private int _gameRoundId;
private DateTime _gameRoundStartDate;
private GamePointStatus _status;
private List<RoundBuilderElement> _elements;
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
// No need to raise property changed for this example
}
}
public DateTime GameRoundStartDate
{
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
// No need to raise property changed for this example
}
}
public GamePointStatus Status
{
get { return _status; }
set
{
_status = value;
// No need to raise property changed for this example
}
} }
public List<RoundBuilderElement> Elements [ObservableProperty]
{ private int gameRoundId;
get { return _elements; }
set [ObservableProperty]
{ private DateTime gameRoundStartDate;
_elements = value;
RaisePropertyChanged(nameof(Elements)); [ObservableProperty]
// No need to raise property changed for this example private GamePointStatus _status;
}
} [ObservableProperty]
private List<RoundBuilderElement> elements;
} }

View File

@ -0,0 +1,7 @@
namespace GreadyPoang.EntityLayer;
public class ScoreCell
{
public string Text { get; set; }
public bool IsHeader { get; set; }
}

View File

@ -0,0 +1,9 @@
using System.Collections.ObjectModel;
namespace GreadyPoang.EntityLayer;
public class ScoreColumn
{
public string PlayerName { get; set; }
public ObservableCollection<ScoreCell> Cells { get; set; } = new();
}

View File

@ -2,17 +2,13 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,6 @@
namespace GreadyPoang.Services;
public static class LatestPopup
{
public static string valueGuid = "";
}

View File

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

View File

@ -0,0 +1,12 @@
namespace GreadyPoang.Services;
public class PopupEventHub : IPopupEventHub
{
public event EventHandler<PopupCloseEventArgs>? InfoPopupCloseRequested;
public void RaiseInfoPopupClose(string popupId)
{
InfoPopupCloseRequested?.Invoke(this, new PopupCloseEventArgs(popupId));
}
}

View File

@ -1,10 +1,9 @@
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

@ -0,0 +1,9 @@
namespace GreadyPoang.Services;
public interface IPopupEventHub
{
event EventHandler<PopupCloseEventArgs>? InfoPopupCloseRequested;
void RaiseInfoPopupClose(string popupId);
}

View File

@ -0,0 +1,11 @@
namespace GreadyPoang.Services;
public class PopupCloseEventArgs : EventArgs
{
public string PopupId { get; }
public PopupCloseEventArgs(string popupId)
{
PopupId = popupId;
}
}

View File

@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks> <TargetFramework>net9.0</TargetFramework>
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>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Common.Library\Common.Library.csproj" /> <ProjectReference Include="..\Common.Library\Common.Library.csproj" />
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" /> <ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />

View File

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

View File

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

View File

@ -1,9 +0,0 @@

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

View File

@ -1,21 +0,0 @@
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,50 @@
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.Services;
namespace GreadyPoang.ViewModelLayer;
public partial class InfoPopupViewModel : ObservableObject, IQueryAttributable
{
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
public string PopupId { get; } = Guid.NewGuid().ToString();
public event EventHandler ClosePopupRequested;
[ObservableProperty]
private string title;
[ObservableProperty]
private string message;
[ObservableProperty]
private string name;
public InfoPopupViewModel(IPopupService popupService, IPopupEventHub popupEvent)
{
_popupService = popupService;
_popupEvent = popupEvent;
LatestPopup.valueGuid = PopupId;
}
[RelayCommand]
private async Task Cancel()
{
_popupEvent.RaiseInfoPopupClose(PopupId);
}
[RelayCommand(CanExecute = nameof(CanSave))]
void OnSave()
{
}
bool CanSave() => string.IsNullOrWhiteSpace(Name) is false;
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
Title = (string)query[nameof(InfoPopupViewModel.Title)];
Message = (string)query[nameof(InfoPopupViewModel.Message)];
Name = (string)query[nameof(InfoPopupViewModel.Name)];
}
}

View File

@ -1,30 +0,0 @@
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,10 +1,11 @@
using Common.Library; using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
namespace GreadyPoang.ViewModelLayer; namespace GreadyPoang.ViewModelLayer;
public class MethodSharingService : ViewModelBase, IMethodSharingService<Participant> public class MethodSharingService : ObservableObject, IMethodSharingService<Participant>
{ {
private readonly IRepository<Participant> _repository; private readonly IRepository<Participant> _repository;

View File

@ -1,4 +1,8 @@
using Common.Library; using Common.Library;
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.Core;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -6,7 +10,7 @@ using System.Collections.ObjectModel;
namespace GreadyPoang.ViewModelLayer; namespace GreadyPoang.ViewModelLayer;
public class ParticipantViewModel : ViewModelBase public partial class ParticipantViewModel : BaseViewModel
{ {
#region Constructors #region Constructors
public ParticipantViewModel() : base() public ParticipantViewModel() : base()
@ -17,58 +21,65 @@ public class ParticipantViewModel : ViewModelBase
public ParticipantViewModel( public ParticipantViewModel(
IRepository<Participant> repo, IRepository<Participant> repo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
AppShellViewModel appShell, IPopupService popupService,
IObjectMessageService objectMessage) : base() IPopupEventHub popupEvent
) : base()
{ {
_Repository = repo; _Repository = repo;
_sharingService = sharingService; _sharingService = sharingService;
_appShell = appShell; _popupService = popupService;
_objectMessage = objectMessage; _popupEvent = popupEvent;
ParticipantObject = new Participant();
ParticipantList = new ObservableCollection<Participant>();
IsSaveCommandEnabled = true;
PopupVisad = false;
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
} }
#endregion #endregion
#region Private Variables #region Private Variables
private Participant? _ParticipantObject = new(); [ObservableProperty]
private ObservableCollection<Participant> _ParticipantList = new(); private Participant? participantObject;
[ObservableProperty]
private ObservableCollection<Participant> participantList;
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 IPopupService _popupService;
private readonly IObjectMessageService _objectMessage; private readonly IPopupEventHub _popupEvent;
#endregion private readonly InfoPopupViewModel _infoPopupViewModel;
private string _activePopupId;
#region public Properties
public Participant? ParticipantObject
{
get { return _ParticipantObject; }
set
{
_ParticipantObject = value;
RaisePropertyChanged(nameof(ParticipantObject));
}
}
public ObservableCollection<Participant> ParticipantList
{
get { return _ParticipantList; }
set
{
_ParticipantList = value;
RaisePropertyChanged(nameof(ParticipantList));
}
}
#endregion #endregion
public bool PopupVisad { get; set; }
[ObservableProperty]
private bool isSaveCommandEnabled;
#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();
if (!PopupVisad)
{
var queryAttributes = new Dictionary<string, object>
{
[nameof(InfoPopupViewModel.Title)] = "Deltagar bildens infopopup",
[nameof(InfoPopupViewModel.Message)] = "Deltagare laddade",
[nameof(InfoPopupViewModel.Name)] = " ",
};
_popupService.ShowPopup<InfoPopupViewModel>(
Shell.Current,
options: PopupOptions.Empty,
shellParameters: queryAttributes);
_activePopupId = LatestPopup.valueGuid;
}
return ParticipantList; return ParticipantList;
} }
@ -90,20 +101,62 @@ public class ParticipantViewModel : ViewModelBase
return ParticipantObject; return ParticipantObject;
} }
public virtual bool Save()
{
if (_Repository == null || ParticipantObject == null)
{
return false;
}
var tmpTask = _Repository.Save(ParticipantObject);
int tmp = tmpTask.GetAwaiter().GetResult();
if (tmp != -1)
{
ParticipantObject = new Participant();
this.Get();
}
return tmp != -1;
}
#endregion #endregion
[RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))]
private async Task Save()
{
await RunAsyncCommand(async () =>
{
if (_Repository == null || ParticipantObject == null)
{
return;
}
await Task.Delay(3600); // Simulerar en fördröjning för att visa laddningsindikatorn
var tmpTask = _Repository.Save(ParticipantObject);
int tmp = await tmpTask;
if (tmp != -1)
{
ParticipantObject = new Participant();
this.Get();
await Shell.Current.GoToAsync("..");
}
}, loadingMessage: "Sparar deltagare...", errorMessage: "Fel vid sparande av deltagare");
}
[RelayCommand]
private void DeleteAsync(Participant pp)
{
Console.WriteLine($"Valt från ViewModel: {pp.FullName}");
if (_Repository == null || pp == null || pp.ParticipantId <= 0)
{
return;
}
var tmpTask = _Repository.Delete(pp);
this.Get();
Shell.Current.GoToAsync("..");
}
[RelayCommand]
private async Task LoadDataAsync()
{
await RunAsyncCommand(async () =>
{
await Task.Delay(1500); // Simulerar laddning
Console.WriteLine("Data laddad!");
}, loadingMessage: "Laddar data...");
}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{
if (e.PopupId != _activePopupId)
{
return;
}
PopupVisad = true;
await _popupService.ClosePopupAsync(Shell.Current);
}
} }

View File

@ -1,17 +1,21 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core; using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Input;
namespace GreadyPoang.ViewModelLayer; namespace GreadyPoang.ViewModelLayer;
public class RoundRunningViewModel : ViewModelBase public partial class RoundRunningViewModel : ObservableObject
{ {
public event EventHandler RebuildRequested; public event EventHandler RebuildRequested;
public ICommand OnLoadedCommand { get; }
public RoundRunningViewModel() : base() public RoundRunningViewModel() : base()
{ {
@ -24,8 +28,8 @@ public class RoundRunningViewModel : ViewModelBase
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage, IObjectMessageService objectMessage,
ISplashService splashService, IPopupService popupService,
AppShellViewModel appShell IPopupEventHub popupEvent
) : base() ) : base()
{ {
_roundsRepo = roundsRepo; _roundsRepo = roundsRepo;
@ -33,91 +37,48 @@ public class RoundRunningViewModel : ViewModelBase
_sharingService = sharingService; _sharingService = sharingService;
_combined = combined; _combined = combined;
_objectMessage = objectMessage; _objectMessage = objectMessage;
_splashService = splashService; _popupService = popupService;
_appShell = appShell; _popupEvent = popupEvent;
_roundElements = new ObservableCollection<RoundBuilderElement>(); RoundElements = new ObservableCollection<RoundBuilderElement>();
_builderObject = new(); BuilderObject = new();
_SplashShowing = false; _popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
//PopupVisad = false;
OnLoadedCommand = new AsyncRelayCommand(OnLoadedAsync, () => true);
} }
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 IPopupService _popupService;
private readonly AppShellViewModel _appShell; private readonly IPopupEventHub _popupEvent;
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private ObservableCollection<RoundBuilderElement> _roundElements;
private Collection<PlayerColumn> _playerColumns;
private RoundBuilderElement _builderObject;
public void TriggerRebuild() [ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements;
[ObservableProperty]
private Collection<PlayerColumn> playerColumns;
[ObservableProperty]
private RoundBuilderElement builderObject;
public ObservableCollection<ScoreColumn> ScoreColumns { get; } = new ObservableCollection<ScoreColumn>();
private string _activePopupId;
//public bool PopupVisad { get; set; }
private async Task OnLoadedAsync()
{ {
// Trigga eventet await Get();
RebuildRequested?.Invoke(this, EventArgs.Empty);
} }
// Översta raden public async Task Get()
public ObservableCollection<RoundBuilderElement> RoundElements
{ {
get { return _roundElements; }
set
{
_roundElements = value;
RaisePropertyChanged(nameof(RoundElements));
}
}
// Nedersta strukturen
public Collection<PlayerColumn> PlayerColumns
{
get { return _playerColumns; }
set
{
_playerColumns = value;
RaisePropertyChanged(nameof(PlayerColumns));
}
}
public RoundBuilderElement BuilderObject
{
get { return _builderObject; }
set
{
_builderObject = value;
RaisePropertyChanged(nameof(BuilderObject));
}
}
private bool _gobackVisible = true;
public bool GobackVisible
{
get { return _gobackVisible; }
set
{
_gobackVisible = value;
RaisePropertyChanged(nameof(GobackVisible));
}
}
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)
@ -129,30 +90,17 @@ public class RoundRunningViewModel : ViewModelBase
RoundElements.Add(item); RoundElements.Add(item);
} }
// Räkna ut vem som är nästa spelare
var nxt = nextPlayerElement();
// Aktuell spelare sätts som BuilderObject
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[nxt].ParticipantName;
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
BuilderObject.ParticipantId = _objectMessage.CurrentGroup.Elements[nxt].ParticipantId;
BuilderObject.Status = _objectMessage.CurrentGroup.Status; BuilderObject.Status = _objectMessage.CurrentGroup.Status;
// Alla poängposter från samtliga spelare i rundan samlas ihop och fördelas per deltagare UpdateAndShow();
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
FillupResultTable(localElements);
foreach (var col in _playerColumns)
{
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
}
TriggerRebuild();
} }
return RoundElements;
} }
public void StoreAndHandlePoints()
[RelayCommand]
private void StoreAndHandlePointsAsync()
{ {
var game = _roundsRepo.Get(BuilderObject.GameRoundId).GetAwaiter().GetResult(); var game = _roundsRepo.Get(BuilderObject.GameRoundId).GetAwaiter().GetResult();
var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1; var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1;
@ -186,20 +134,10 @@ public class RoundRunningViewModel : ViewModelBase
RoundElements.Add(item); RoundElements.Add(item);
} }
// Uppdatera spelaren som skall spela nästa
var nxt = nextPlayerElement();
BuilderObject.GameRegPoints = 0; BuilderObject.GameRegPoints = 0;
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName; UpdateAndShow();
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId; Shell.Current.GoToAsync("..").GetAwaiter().GetResult();
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
FillupResultTable(localElements);
foreach (var col in _playerColumns)
{
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
}
TriggerRebuild();
} }
private int nextPlayerElement() private int nextPlayerElement()
@ -214,15 +152,76 @@ public class RoundRunningViewModel : ViewModelBase
return -1; return -1;
} }
private void UpdateAndShow()
{
// Räkna ut vem som är nästa spelare
var nxt = nextPlayerElement();
// Aktuell spelare sätts som BuilderObject
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[nxt].ParticipantName;
BuilderObject.ParticipantId = _objectMessage.CurrentGroup.Elements[nxt].ParticipantId;
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
// Alla poängposter från samtliga spelare i rundan samlas ihop och fördelas per deltagare
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
FillupResultTable(localElements);
// Fix for CS8602: Add null check before dereferencing FirstOrDefault result
foreach (var col in PlayerColumns)
{
var roundElement = RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId);
if (roundElement != null)
{
roundElement.GameRegPoints = col.PlayerPoints;
}
}
// Fix for MVVMTK0034: Use the generated property 'PlayerColumns' instead of the backing field 'playerColumns'
BuildScore(PlayerColumns);
}
private void Show_a_Popup(string ppName, string ppTitle, string ppMessage)
{
//if (!PopupVisad)
//{
var queryAttributes = new Dictionary<string, object>
{
[nameof(InfoPopupViewModel.Title)] = ppTitle,
[nameof(InfoPopupViewModel.Message)] = ppMessage,
[nameof(InfoPopupViewModel.Name)] = ppName,
};
_popupService.ShowPopup<InfoPopupViewModel>(
Shell.Current,
options: PopupOptions.Empty,
shellParameters: queryAttributes);
_activePopupId = LatestPopup.valueGuid;
//}
}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{
if (e.PopupId != _activePopupId)
{
return;
}
//PopupVisad = true;
await _popupService.ClosePopupAsync(Shell.Current);
}
private void FillupResultTable(IEnumerable<RoundBuilderElement> elements) private void FillupResultTable(IEnumerable<RoundBuilderElement> elements)
{ {
if (_playerColumns != null) if (PlayerColumns != null)
{ {
_playerColumns.Clear(); PlayerColumns.Clear();
} }
else else
{ {
_playerColumns = new Collection<PlayerColumn>(); PlayerColumns = new Collection<PlayerColumn>();
} }
// if (elements.Any(g => g.GameRegPoints > 0)) // if (elements.Any(g => g.GameRegPoints > 0))
@ -230,10 +229,12 @@ public class RoundRunningViewModel : ViewModelBase
{ {
PlayerColumn player = new PlayerColumn(); PlayerColumn player = new PlayerColumn();
var regMax = elements.Max(e => e.GameRoundRegNr);
var existingWinning = elements.FirstOrDefault(e => e.Status == GamePointStatus.Winning);
foreach (var element in elements) foreach (var element in elements)
{ {
player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId); player = PlayerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId)!;
if (player == null) if (player == null)
{ {
player = new PlayerColumn player = new PlayerColumn
@ -247,18 +248,17 @@ public class RoundRunningViewModel : ViewModelBase
if (element.GameRegPoints > 0) if (element.GameRegPoints > 0)
{ {
player.Values.Add(element.GameRegPoints.ToString()); player.Values.Add(element.GameRegPoints.ToString());
var playerPointsOld = player.PlayerPoints;
player.PlayerPoints += element.GameRegPoints; player.PlayerPoints += element.GameRegPoints;
if (player.PlayerPoints > 10000) if (player.PlayerPoints > 10000)
{ {
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId); HandlePlayerReachedWinningThreshold(player, regMax, element, playerPointsOld, existingWinning);
winner.Status = GamePointStatus.Winning;
} }
} }
//oldPart = element.ParticipantId;
if (!_playerColumns.Contains(player)) if (!PlayerColumns.Contains(player))
{ {
_playerColumns.Add(player); PlayerColumns.Add(player);
} }
} }
} }
@ -270,7 +270,9 @@ public class RoundRunningViewModel : ViewModelBase
{ {
var player = new PlayerColumn var player = new PlayerColumn
{ {
PlayerName = element.ParticipantName PlayerName = element.ParticipantName,
PlayerId = element.ParticipantId,
PlayerPoints = 0
}; };
for (int i = 0; i < slumper.Next(6); i++) for (int i = 0; i < slumper.Next(6); i++)
@ -278,32 +280,91 @@ public class RoundRunningViewModel : ViewModelBase
player.Values.Add(slumper.Next(1, 10).ToString()); player.Values.Add(slumper.Next(1, 10).ToString());
} }
_playerColumns.Add(player); PlayerColumns.Add(player);
} }
} }
} }
public async void ToggleSplash() private void HandlePlayerReachedWinningThreshold(
PlayerColumn player,
int regMax,
RoundBuilderElement element,
int playerPointsOld,
RoundBuilderElement existingWinning
)
{ {
if (!_SplashShowing) var nextPlayer = RoundElements[AfterNext()].ParticipantName;
Debug.WriteLine($"Spelare {nextPlayer} samma som {player.PlayerName} ???.");
if (existingWinning != null && existingWinning.ParticipantId != player.PlayerId)
{ {
//_overlay.ShowSplash("Clcicked!", 5000); // Det finns redan en vinnare, sätt dennes status tillbaka till InProgress
await _splashService.ShowSplash("Clicked", 0); existingWinning.Status = GamePointStatus.InProgress;
_SplashShowing = true;
}
else
{
await _splashService.HideAsync();
_SplashShowing = false;
} }
// Om det redan finns en vinnare, sätt dennes status tillbaka till InProgress, kanske
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
var oldStatus = winner.Status;
winner.Status = GamePointStatus.Winning;
if (playerPointsOld < 10000 && oldStatus != winner.Status && regMax == element.GameRoundRegNr)
{
//PopupVisad = false;
Show_a_Popup(
player.PlayerName,
"Se upp för denne spelare !",
$"Du har nått en poängnivå över 10000 ({player.PlayerPoints})\r" +
$"Alla övriga får nu en chans att överträffa\r" +
$"om någon kommer till samma poäng som\r" +
$"{player.PlayerName}\r" +
$"får hen försvara sig med nytt kast\r" +
$"Om kastet inte blir godkänt (ger poäng)\r" +
$"Vinner den upphinnande spelaren"
);
}
} }
public void GobackAsync() private int AfterNext()
{ {
_appShell.RoundRunningVisible = true; var comingUp = nextPlayerElement();
if (RoundElements.Count - 1 == comingUp)
{
return 0;
}
return comingUp;
} }
public void BuildScore(IEnumerable<PlayerColumn> columns)
{
ScoreColumns.Clear();
foreach (var column in columns)
{
var scoreColumn = new ScoreColumn
{
PlayerName = column.PlayerName
};
scoreColumn.Cells.Add(new ScoreCell
{
Text = column.PlayerName,
IsHeader = true
});
foreach (var value in System.Linq.Enumerable.Reverse(column.Values))
{
scoreColumn.Cells.Add(new ScoreCell
{
Text = value,
IsHeader = false
});
}
ScoreColumns.Add(scoreColumn);
}
}
} }

View File

@ -1,5 +1,6 @@
using Common.Library; using Common.Library;
using GreadyPoang.Core; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.DataLayer; using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer; using GreadyPoang.EntityLayer;
using GreadyPoang.Services; using GreadyPoang.Services;
@ -8,11 +9,12 @@ using System.Diagnostics;
namespace GreadyPoang.ViewModelLayer; namespace GreadyPoang.ViewModelLayer;
public class RoundStartingViewModel : ViewModelBase public partial class RoundStartingViewModel : ObservableObject
{ {
#region Constructors #region Constructors
public RoundStartingViewModel() : base() public RoundStartingViewModel() : base()
{ {
} }
public RoundStartingViewModel( public RoundStartingViewModel(
@ -20,72 +22,51 @@ public class RoundStartingViewModel : ViewModelBase
IRepository<GamePoint> pointsRepo, IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService, IMethodSharingService<Participant> sharingService,
ICombinedRepository combined, ICombinedRepository combined,
IObjectMessageService objectMessage, IObjectMessageService objectMessage) : base()
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; RoundElements = new ObservableCollection<RoundBuilderElement>();
_factory = factory;
_splashService = splashService;
_appShellView = appShellView;
_roundElements = new ObservableCollection<RoundBuilderElement>();
} }
#endregion #endregion
private GameRound? _GameRoundObject = new();
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
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 INavigationService _nav;
private readonly IPageFactory _factory;
private readonly ISplashService _splashService;
private readonly AppShellViewModel _appShellView;
private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements;
public ObservableCollection<RoundBuilderElement> RoundElements [ObservableProperty]
private Participant selectedItem;
partial void OnSelectedItemChanged(Participant value)
{ {
get { return _roundElements; } if (value != null)
set
{ {
_roundElements = value; OnItemSelected(value);
RaisePropertyChanged(nameof(RoundElements));
} }
} }
[ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements;
public Participant SelectedItem [ObservableProperty]
{ private GameRound? gameRoundObject = new();
get => _selectedItem;
set [ObservableProperty]
{ private ObservableCollection<RoundBuilderGroup> gameRoundList = new();
if (_selectedItem != value)
{ [ObservableProperty]
private ObservableCollection<Participant> participantList = new();
_selectedItem = value;
RaisePropertyChanged(nameof(SelectedItem));
OnItemSelected(value); // Metod som triggas vid val
}
}
}
private void OnItemSelected(Participant item) private void OnItemSelected(Participant item)
{ {
if (_roundElements.Count == 0) if (RoundElements.Count == 0)
{ {
var GameRound = new GameRound var GameRound = new GameRound
{ {
@ -123,41 +104,12 @@ public class RoundStartingViewModel : ViewModelBase
newElement.GameRoundId = GamePointStart.GameRoundId; newElement.GameRoundId = GamePointStart.GameRoundId;
newElement.GamePointId = GamePointStart.GamePointId; newElement.GamePointId = GamePointStart.GamePointId;
_roundElements.Add(newElement); RoundElements.Add(newElement);
// Gör något med det valda objektet // Gör något med det valda objektet
Debug.WriteLine($"Du valde: {item.LastNameFirstName}"); Debug.WriteLine($"Du valde: {item.LastNameFirstName}");
} }
public GameRound? GameRoundObject
{
get { return _GameRoundObject; }
set
{
_GameRoundObject = value;
RaisePropertyChanged(nameof(GameRoundObject));
}
}
public ObservableCollection<RoundBuilderGroup> GameRoundList
{
get { return _GameRoundList; }
set
{
_GameRoundList = value;
RaisePropertyChanged(nameof(GameRoundList));
}
}
public ObservableCollection<Participant> ParticipantList
{
get { return _ParticipantList; }
set
{
_ParticipantList = value;
RaisePropertyChanged(nameof(ParticipantList));
}
}
#region Get Method #region Get Method
public ObservableCollection<RoundBuilderGroup> Get() public ObservableCollection<RoundBuilderGroup> Get()
@ -218,7 +170,9 @@ public class RoundStartingViewModel : ViewModelBase
return GameRoundObject; return GameRoundObject;
} }
public virtual bool Save()
[RelayCommand]
public async Task<bool> SaveAsync()
{ {
if (_roundsRepo == null || GameRoundObject == null) if (_roundsRepo == null || GameRoundObject == null)
{ {
@ -231,11 +185,13 @@ public class RoundStartingViewModel : ViewModelBase
GameRoundObject = new GameRound(); GameRoundObject = new GameRound();
RoundElements.Clear(); RoundElements.Clear();
this.Get(); this.Get();
await Shell.Current.GoToAsync("..");
} }
return tmp; return tmp;
} }
public void Rensa() [RelayCommand]
private async Task RensaAsync()
{ {
foreach (var element in RoundElements) foreach (var element in RoundElements)
{ {
@ -243,30 +199,29 @@ public class RoundStartingViewModel : ViewModelBase
} }
_roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0); _roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
RoundElements.Clear(); RoundElements.Clear();
await Shell.Current.GoToAsync("..");
} }
public async void RoundSelected(RoundBuilderElement element) [RelayCommand]
public async Task 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;
_objectMessage.Delivered = true; //await Shell.Current.GoToAsync("//RoundRunningView");
//await _splashService.ShowSplash("Runda vald, gå till\r\r 'Påbörja eller fortsätt Runda'", 3000); await Shell.Current.GoToAsync("//RoundRunningView");
await Shell.Current.GoToAsync("RoundRunningPage");
_appShellView.RoundRunningVisible = false;
//_roundRunning.GobackVisible = false;
//var page = _factory.CreateRoundPage();
//_nav.NavigateToPageAsync(page);
} }
} }
[RelayCommand]
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder) public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{ {
bool goneOk = false;
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}");
goneOk = true;
return goneOk;
} }
#endregion #endregion

View File

@ -1,103 +0,0 @@
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.36518.9 d17.14 VisualStudioVersion = 17.14.36408.4
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,38 +1,18 @@
using GreadyPoang.DataLayer.Database; using GreadyPoang.DataLayer.Database;
using System.Diagnostics;
namespace GreadyPoang; namespace GreadyPoang
public partial class App : Application
{ {
private readonly IServiceProvider _services; public partial class App : Application
public App(IServiceProvider services, DataContext dataContext)
{ {
InitializeComponent(); public App(DataContext dataContext)
dataContext.Database.EnsureCreated();
_services = services;
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{ {
if (Debugger.IsAttached) InitializeComponent();
Debugger.Break(); dataContext.Database.EnsureCreated();
}; }
TaskScheduler.UnobservedTaskException += (sender, e) => protected override Window CreateWindow(IActivationState? activationState)
{ {
if (Debugger.IsAttached) return new Window(new AppShell());
Debugger.Break(); }
};
}
protected override Window CreateWindow(IActivationState? activationState)
{
//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" ContentTemplate="{DataTemplate local:MainPage}" Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" /> Route="MainPage" />
<ShellContent <ShellContent
Title="Deltagare" ContentTemplate="{DataTemplate pages:ParticipantListPage}" Title="Deltagare"
Route="ParticipantListPage"/> ContentTemplate="{DataTemplate views:ParticipantListView}"
Route="ParticipantListView" />
<ShellContent <ShellContent
Title="Ny Runda" ContentTemplate="{DataTemplate pages:RoundStartingPage}" Title="Starta Ny Runda"
Route="RoundStartingPage"/> ContentTemplate="{DataTemplate views:RoundStartingView}"
Route="RoundStartingView" />
<ShellContent <ShellContent
Title="Påbörja eller fortsätt Runda" ContentTemplate="{DataTemplate pages:RoundRunningPage}" Title="Påbörja eller fortsätt Runda"
Route="RoundRunningPage" IsVisible="{Binding RoundRunningVisible}"/> ContentTemplate="{DataTemplate views:RoundRunningView}"
Route="RoundRunningView" />
</TabBar> </TabBar>
</Shell> </Shell>

View File

@ -1,21 +1,10 @@
using GreadyPoang.Core; namespace GreadyPoang
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang
{ {
public partial class AppShell : Shell public partial class AppShell : Shell
{ {
private readonly IPageFactory _factory; public AppShell()
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;
} }
} }
} }

View File

@ -1,40 +0,0 @@
<?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

@ -1,13 +0,0 @@
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

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

View File

@ -1,15 +0,0 @@
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,72 +0,0 @@
using Common.Library;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class ParticipantViewModelCommands : ParticipantViewModel
{
#region constructors
public ParticipantViewModelCommands() : base()
{
}
public ParticipantViewModelCommands(
IRepository<Participant> repo,
IMethodSharingService<Participant> sharingService,
AppShellViewModel appShell,
IObjectMessageService objectMessage) : base(repo, sharingService, appShell, objectMessage)
{
}
#endregion
#region Private Variables
private bool _IsSaveCommandEnabled = true;
#endregion
#region Public Properties
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
#endregion
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
#endregion
#region Init Method
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
}
#endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.ParticipantListView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
}

View File

@ -1,67 +0,0 @@
using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class RoundRunningViewModelCommands : RoundRunningViewModel
{
public RoundRunningViewModelCommands() : base()
{
}
public RoundRunningViewModelCommands(
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage,
ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage,
splashService,
appShell)
{
}
#region Commands
public ICommand GobackCommand { get; private set; }
public ICommand StoreAndHandlePointsCommand { get; private set; }
public ICommand OnSplashClickedCommand { get; private set; }
#endregion
public override void Init()
{
base.Init();
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
OnSplashClickedCommand = new Command(async () => await ToggleSplash());
GobackCommand = new Command(async () => GobackAsync());
}
private async void GobackAsync()
{
base.GobackAsync();
await Shell.Current.GoToAsync("..");
}
private async Task StoreAndHandleAsync()
{
base.StoreAndHandlePoints();
//await Shell.Current.GoToAsync("..");
// await Shell.Current.GoToAsync("RoundRunningPage");
}
private async Task ToggleSplash()
{
base.ToggleSplash();
}
}

View File

@ -1,115 +0,0 @@
using Common.Library;
using GreadyPoang.Core;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class RoundStartingViewModelCommands : RoundStartingViewModel
{
public RoundStartingViewModelCommands() : base()
{
}
public RoundStartingViewModelCommands(
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage,
INavigationService nav,
IPageFactory factory,
ISplashService splashService,
AppShellViewModel appShell)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage,
nav,
factory,
splashService,
appShell)
{
}
#region Private Variables
private bool _IsSaveCommandEnabled = true;
#endregion
#region Public Properties
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
#endregion
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
public ICommand RensaCommand { get; private set; }
public ICommand ElementTappedCommand { get; private set; }
public ICommand ParticipantTappedCommand { get; private set; }
#endregion
#region Init Method
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
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));
ElementTappedCommand = new Command<RoundBuilderElement>((selectedElement) => RoundSelected(selectedElement));
}
private async Task RensaAsync()
{
base.Rensa();
await Shell.Current.GoToAsync("..");
}
#endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.RoundStartingView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
public async Task<bool> RoundSelected(RoundBuilderElement element)
{
bool goneOk = false;
base.RoundSelected(element);
goneOk = true;
return goneOk;
}
public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{
bool goneOk = false;
base.SelectNewlyAddedParticipant(roundBuilder);
goneOk = true;
return goneOk;
}
}

View File

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

View File

@ -1,11 +0,0 @@
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

@ -1,30 +0,0 @@
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

@ -1,10 +0,0 @@
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

@ -60,6 +60,16 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Views\RoundRunningViewOld.xaml.cs" />
</ItemGroup>
<ItemGroup>
<MauiXaml Remove="Views\RoundRunningViewOld.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" /> <PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
@ -70,26 +80,29 @@
<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>
<ItemGroup> <ItemGroup>
<Compile Update="Popups\InfoPopup.xaml.cs">
<DependentUpon>InfoPopup.xaml</DependentUpon>
</Compile>
<Compile Update="Views\ParticipantListView.xaml.cs"> <Compile Update="Views\ParticipantListView.xaml.cs">
<DependentUpon>ParticipantListView.xaml</DependentUpon> <DependentUpon>ParticipantListView.xaml</DependentUpon>
</Compile> </Compile>
</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>
<MauiXaml Update="ViewsPartial\HeaderView.xaml"> <MauiXaml Update="ViewsPartial\HeaderView.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Popups\InfoPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ParticipantListView.xaml"> <MauiXaml Update="Views\ParticipantListView.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
@ -99,9 +112,6 @@
<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

@ -1,12 +0,0 @@
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

@ -1,34 +0,0 @@
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,8 +3,6 @@
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}">
@ -14,8 +12,7 @@
ViewDescription="Välkommen till Gready"> ViewDescription="Välkommen till Gready">
</partial:HeaderView> </partial:HeaderView>
<Image <Image Source="snurrtarning.gif"
Source="snurrtarning.gif"
IsAnimationPlaying="True" IsAnimationPlaying="True"
HorizontalOptions="Center" HorizontalOptions="Center"
VerticalOptions="Center" VerticalOptions="Center"

View File

@ -1,23 +1,11 @@
using GreadyPoang.CommandClasses; namespace GreadyPoang;
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,11 +1,9 @@
using Common.Library; using Common.Library;
using GreadyPoang.CommandClasses; using CommunityToolkit.Maui;
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.Popups;
using GreadyPoang.LocalServices;
using GreadyPoang.Services; using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer; using GreadyPoang.ViewModelLayer;
using GreadyPoang.Views; using GreadyPoang.Views;
@ -22,6 +20,8 @@ public static class MauiProgram
builder builder
.UseMauiApp<App>() .UseMauiApp<App>()
.UseMauiCommunityToolkit(options =>
options.SetShouldEnableSnackbarOnWindows(true))
.ConfigureFonts(fonts => .ConfigureFonts(fonts =>
{ {
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
@ -33,49 +33,41 @@ public static class MauiProgram
builder.Services.AddDbContext<DataContext>(options => builder.Services.AddDbContext<DataContext>(options =>
{ {
var MauiDataPath = FileSystem.Current.AppDataDirectory; var MauiDataPath = FileSystem.Current.AppDataDirectory;
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ; //if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
{ //{
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath); // File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
} //}
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db"); var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
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<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<ParticipantViewModel>();
builder.Services.AddScoped<ParticipantListView>(); builder.Services.AddScoped<ParticipantListView>();
builder.Services.AddScoped<IRepository<GameRound>, GameRoundRepository>(); builder.Services.AddScoped<IRepository<GameRound>, GameRoundRepository>();
builder.Services.AddScoped<RoundStartingViewModelCommands>();
builder.Services.AddScoped<RoundStartingViewModel>();
builder.Services.AddScoped<RoundStartingView>(); builder.Services.AddScoped<RoundStartingView>();
builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>(); builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>();
builder.Services.AddScoped<RoundRunningViewModelCommands>();
builder.Services.AddScoped<RoundRunningViewModel>();
builder.Services.AddScoped<RoundRunningView>(); builder.Services.AddScoped<RoundRunningView>();
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<ICombinedRepository, CombinedRepository>(); builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>(); builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddSingleton<AppShellViewModel>(); builder.Services.AddTransientPopup<InfoPopup, InfoPopupViewModel>();
builder.Services.AddSingleton<AppShell>(); builder.Services.AddSingleton<IPopupEventHub, PopupEventHub>();
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();
ServiceLocator.Services = app.Services; return builder.Build();
return app;
} }
} }

View File

@ -1,24 +0,0 @@
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

@ -1,43 +0,0 @@
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

@ -1,25 +0,0 @@
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

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
x:Class="GreadyPoang.Popups.InfoPopup"
HorizontalOptions="Center"
VerticalOptions="Center"
Padding="0"
x:DataType="viewModels:InfoPopupViewModel"
BackgroundColor="Transparent">
<VerticalStackLayout BackgroundColor="Aquamarine" Padding="5" Margin="0">
<Label HorizontalOptions="Center" TextColor="BlueViolet" Text="{Binding Title}" Style="{StaticResource Headline}" />
<Label HorizontalOptions="Center" Text="{Binding Name}" Style="{StaticResource SubHeadline}"/>
<Label HorizontalOptions="Center" Text="{Binding Message}" Style="{StaticResource StatusLabelStyle}"/>
<!--<Label Text="What is your name?" />
<Entry Text="{Binding Name}" />
<Button Text="Save" Command="{Binding SaveCommand}" />-->
<Button Margin="10" Text="Cancel" Command="{Binding CancelCommand}" Style="{StaticResource HoverButtonBlueStyle}" />
</VerticalStackLayout>
</ContentView>

View File

@ -0,0 +1,13 @@
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Popups;
public partial class InfoPopup : ContentView
{
public InfoPopup(InfoPopupViewModel ipViewModel)
{
InitializeComponent();
BindingContext = ipViewModel;
}
}

View File

@ -2,7 +2,10 @@
<?xaml-comp compile="true" ?> <?xaml-comp compile="true" ?>
<ResourceDictionary <ResourceDictionary
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:local="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common" >
<local:HeaderColorConverter x:Key="HeaderColorConverter" />
<Style TargetType="StackLayout" x:Key="ResponsiveStackStyle"> <Style TargetType="StackLayout" x:Key="ResponsiveStackStyle">
<Setter Property="Orientation" Value="Horizontal"/> <Setter Property="Orientation" Value="Horizontal"/>

View File

@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage 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:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial" xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses" xmlns:vm="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
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:ParticipantViewModel"
x:Name="ParticipantListPage"> x:Name="ParticipantListPage"
<!--Title="Deltagar Lista"--> Title="Deltagar Lista">
<!--xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"-->
<Border Style="{StaticResource Border.Page}" StrokeThickness="4"> <Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -20,11 +23,16 @@
Grid.ColumnSpan="2" Grid.ColumnSpan="2"
ViewTitle="Deltagare" ViewTitle="Deltagare"
ViewDescription="Lägg till deltagare här" /> ViewDescription="Lägg till deltagare här" />
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" Grid.Row="1"> <ActivityIndicator Grid.Row="1" IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}"
Color="DarkBlue"
HeightRequest="40" />
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" Grid.Row="2">
<VerticalStackLayout Spacing="4" > <VerticalStackLayout Spacing="4" >
<Label Style="{StaticResource Label}" <!--<Label Style="{StaticResource SubHeadline}"
Text="Deltagare " Text="Deltagare "
FontAttributes="Bold" FontSize="Large"/> FontAttributes="Bold" />-->
<Grid ColumnDefinitions="Auto,Auto,*" RowDefinitions="Auto,auto,auto,auto" <Grid ColumnDefinitions="Auto,Auto,*" RowDefinitions="Auto,auto,auto,auto"
Padding="10" RowSpacing="8"> Padding="10" RowSpacing="8">
<Label Grid.Row="0" Grid.Column="0" Style="{StaticResource Label}" <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource Label}"
@ -58,7 +66,7 @@
</Grid> </Grid>
</VerticalStackLayout> </VerticalStackLayout>
</Border> </Border>
<Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5"> <Border Grid.Row="3" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
<CollectionView <CollectionView
x:Name="participants" x:Name="participants"
SelectionMode="Single" SelectionMode="Single"
@ -67,7 +75,6 @@
ItemsUpdatingScrollMode="KeepLastItemInView"> ItemsUpdatingScrollMode="KeepLastItemInView">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Participant"> <DataTemplate x:DataType="model:Participant">
<!--Stroke="DarkGray" BackgroundColor="Cornsilk"-->
<Border Margin="8" Padding="12" > <Border Margin="8" Padding="12" >
<VerticalStackLayout Spacing="4"> <VerticalStackLayout Spacing="4">
<Label FontAttributes="Bold" <Label FontAttributes="Bold"
@ -76,7 +83,14 @@
Text="{Binding LastNameFirstName}" /> Text="{Binding LastNameFirstName}" />
<HorizontalStackLayout > <HorizontalStackLayout >
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/> <Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" /> <Button Text="Delete" Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ParticipantViewModel}}, Path=DeleteAsyncCommand}"
CommandParameter="{Binding .}" />
<!--Command="{Binding BindingContext.ParticipantTappedCommand, Source={x:Reference Name=ParticipantList}}"
CommandParameter="{Binding .}" />-->
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
</Border> </Border>
@ -84,6 +98,7 @@
</CollectionView.ItemTemplate> </CollectionView.ItemTemplate>
</CollectionView> </CollectionView>
</Border> </Border>
</Grid> </Grid>
</Border> </Border>
</ContentView> </ContentPage>

View File

@ -1,24 +1,30 @@
using GreadyPoang.CommandClasses; using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class ParticipantListView : ContentView public partial class ParticipantListView : ContentPage
{ {
public ParticipantListView(ParticipantViewModelCommands viewModel) public ParticipantListView(ParticipantViewModel viewModel)
{ {
InitializeComponent(); InitializeComponent();
ViewModel = viewModel; ViewModel = viewModel;
} }
public ParticipantViewModelCommands ViewModel { get; set; } public ParticipantViewModel 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();
//} }
protected override void OnDisappearing()
{
base.OnDisappearing();
ViewModel.PopupVisad = false;
}
} }

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage 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"
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses" xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
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:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer" xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModelCommands"> x:DataType="vm:RoundRunningViewModel"
<!--Title="RoundRunningView"--> Title="RoundRunningView">
<Border
<Border Style="{StaticResource Border.Page}" StrokeThickness="4"> behaviors:LoadedBehavior.Command="{Binding OnLoadedCommand}"
Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}"> <Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -27,6 +27,7 @@
<CollectionView Grid.Row="1" <CollectionView Grid.Row="1"
ItemsSource="{Binding RoundElements}" ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList" ItemsLayout="HorizontalList"
HeightRequest="125"
Margin="2"> Margin="2">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement"> <DataTemplate x:DataType="model:RoundBuilderElement">
@ -34,7 +35,6 @@
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
@ -79,37 +79,45 @@
<Entry.Behaviors> <Entry.Behaviors>
<behaviors:DigitsOnlyBehavior/> <behaviors:DigitsOnlyBehavior/>
<behaviors:EventToCommandBehavior EventName="Completed" <behaviors:EventToCommandBehavior EventName="Completed"
Command="{Binding StoreAndHandlePointsCommand}" /> Command="{Binding StoreAndHandlePointsAsyncCommand}" />
</Entry.Behaviors> </Entry.Behaviors>
</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 StoreAndHandlePointsAsyncCommand}"/>
<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">
<Grid <ScrollView Grid.Row="4" Orientation="Horizontal">
x:Name="ScoreGrid" <HorizontalStackLayout
ColumnSpacing="5" BindableLayout.ItemsSource="{Binding ScoreColumns}"
RowSpacing="5" x:Name="ScoreGrid">
Padding="3" <BindableLayout.ItemTemplate>
HorizontalOptions="FillAndExpand" <DataTemplate x:DataType="model:ScoreColumn">
VerticalOptions="FillAndExpand" /> <VerticalStackLayout BindableLayout.ItemsSource="{Binding Cells}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:ScoreCell">
<Border
Stroke="Gray"
StrokeThickness="1"
BackgroundColor="{Binding IsHeader, Converter={StaticResource HeaderColorConverter}}"
Margin="1"
Padding="2">
<Label
Text="{Binding Text}"
FontAttributes="{Binding IsHeader, Converter={StaticResource FontWeightConverter}}"
TextColor="{Binding IsHeader, Converter={StaticResource TextColorConverter}}"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Border>
</DataTemplate>
</BindableLayout.ItemTemplate>
</VerticalStackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</HorizontalStackLayout>
</ScrollView> </ScrollView>
</Grid> </Grid>
</Border> </Border>
</ContentView> </ContentPage>

View File

@ -1,87 +1,12 @@
using GreadyPoang.CommandClasses; using GreadyPoang.ViewModelLayer;
using GreadyPoang.EntityLayer;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class RoundRunningView : ContentView public partial class RoundRunningView : ContentPage
{ {
public RoundRunningView(RoundRunningViewModel viewModel)
public RoundRunningView(RoundRunningViewModelCommands viewModel)
{ {
InitializeComponent(); InitializeComponent();
ViewModel = viewModel; BindingContext = viewModel;
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
} }
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
}
//protected override
public RoundRunningViewModelCommands ViewModel { get; set; }
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
{
ScoreGrid.ColumnDefinitions.Clear();
ScoreGrid.RowDefinitions.Clear();
ScoreGrid.Children.Clear();
int maxRows = columns.Max(c => c.Values.Count);
// Skapa rader
for (int row = 0; row < maxRows + 1; row++) // +1 f<>r rubrikraden
{
ScoreGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
}
int colIndex = 0;
foreach (var column in columns)
{
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var headerCell = CreateCell(column.PlayerName, isHeader: true);
ScoreGrid.Children.Add(headerCell);
Grid.SetRow(headerCell, 0);
Grid.SetColumn(headerCell, colIndex);
// V<>rdeceller
for (int rowIndex = 0; rowIndex < column.Values.Count; rowIndex++)
{
var value = column.Values[rowIndex];
var cell = CreateCell(value);
ScoreGrid.Children.Add(cell);
Grid.SetRow(cell, rowIndex + 1); // +1 f<>r att hoppa <20>ver rubrikraden
Grid.SetColumn(cell, colIndex);
}
colIndex++;
}
}
private View CreateCell(string text, bool isHeader = false)
{
return new Border
{
Stroke = Colors.Gray,
StrokeThickness = 1,
BackgroundColor = isHeader ? Colors.DarkGray : Colors.Yellow,
Margin = 1,
Padding = 2,
Content = new Label
{
Text = text,
FontAttributes = isHeader ? FontAttributes.Bold : FontAttributes.None,
TextColor = isHeader ? Colors.White : Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
};
}
} }

View File

@ -0,0 +1,101 @@
<?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"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundRunningView"
xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:behaviors="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common"
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModel"
Title="RoundRunningView">
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<partial:HeaderView Grid.Row="0"
Grid.ColumnSpan="2"
ViewTitle="Starta eller fortsätt en registrerad Runda"
ViewDescription="Deltagarna visas först!" />
<CollectionView Grid.Row="1"
ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList"
Margin="2">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement">
<Border Stroke="Gray"
Padding="10"
Margin="5"
StrokeShape="RoundRectangle 10"
Style="{StaticResource StatusBorderStyle}">
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Grid VerticalOptions="Fill" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Spelare" />
<Label Grid.Row="1" Text="{Binding ParticipantName}" FontAttributes="Bold" Style="{StaticResource StatusLabelStyle}" />
<Label Grid.Row="2" Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" Style="{StaticResource StatusLabelStyle}" />
<Label Grid.Row="3" Text="{Binding Status}" Style="{StaticResource StatusLabelStyle}"/>
<Label Grid.Row="4" Text="{Binding GameRoundStartDate, StringFormat='Start: {0:yyyy-MM-dd}'}" Style="{StaticResource StatusLabelStyle}"/>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<BoxView
Grid.Row="2"
Grid.ColumnSpan="2"
Margin="0,0,0,5"
HeightRequest="1"
Color="Black" />
<Border Grid.Row="3">
<HorizontalStackLayout>
<Grid VerticalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="{Binding BuilderObject.GameRoundId, StringFormat='Runda: {0}'}"/>
<Label Grid.Row="1" Text="{Binding BuilderObject.ParticipantName}" FontAttributes="Bold" FontSize="Subtitle" />
<Entry Grid.Row="2" x:Name="Points" Placeholder="Latest Points" Text="{Binding BuilderObject.GameRegPoints}" FontAttributes="Bold" FontSize="20" >
<Entry.Behaviors>
<behaviors:DigitsOnlyBehavior/>
<behaviors:EventToCommandBehavior EventName="Completed"
Command="{Binding StoreAndHandlePointsAsyncCommand}" />
</Entry.Behaviors>
</Entry>
</Grid>
<Button Text="Register Points"
Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding StoreAndHandlePointsAsyncCommand}"/>
</HorizontalStackLayout>
</Border>
<ScrollView Grid.Row="4" Orientation="Horizontal">
<Grid
x:Name="ScoreGrid"
ColumnSpacing="5"
RowSpacing="5"
Padding="3"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
</ScrollView>
</Grid>
</Border>
</ContentPage>

View File

@ -0,0 +1,105 @@
using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views;
public partial class RoundRunningView : ContentPage
{
public RoundRunningView(RoundRunningViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
this.Loaded += OnPageLoaded;
}
private void OnPageLoaded(object? sender, EventArgs e)
{
ViewModel.Get();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
}
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
}
//protected override
public RoundRunningViewModel ViewModel { get; set; }
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
{
ScoreGrid.ColumnDefinitions.Clear();
ScoreGrid.RowDefinitions.Clear();
ScoreGrid.Children.Clear();
int maxRows = columns.Max(c => c.Values.Count);
// Skapa rader
for (int row = 0; row < maxRows + 1; row++) // +1 f<>r rubrikraden
{
ScoreGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
}
int colIndex = 0;
foreach (var column in columns)
{
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var headerCell = CreateCell(column.PlayerName, isHeader: true);
ScoreGrid.Children.Add(headerCell);
Grid.SetRow(headerCell, 0);
Grid.SetColumn(headerCell, colIndex);
// V<>rdeceller
for (int rowIndex = 0; rowIndex < column.Values.Count; rowIndex++)
{
var value = column.Values[rowIndex];
var cell = CreateCell(value);
ScoreGrid.Children.Add(cell);
Grid.SetRow(cell, column.Values.Count - rowIndex); // +1 f<>r att hoppa <20>ver rubrikraden
Grid.SetColumn(cell, colIndex);
}
colIndex++;
}
}
private View CreateCell(string text, bool isHeader = false)
{
return new Border
{
Stroke = Colors.Gray,
StrokeThickness = 1,
BackgroundColor = isHeader ? Colors.DarkGray : Colors.Yellow,
Margin = 1,
Padding = 2,
Content = new Label
{
Text = text,
FontAttributes = isHeader ? FontAttributes.Bold : FontAttributes.None,
TextColor = isHeader ? Colors.White : Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
};
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ViewModel.PopupVisad = false;
}
}

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage 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"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses" xmlns:vm="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
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:RoundStartingViewModel"
x:Name="GameRoundStartingPage"> x:Name="GameRoundStartingPage"
<!--Title="Starta ny Runda"--> Title="Starta ny Runda">
@ -25,15 +25,15 @@
ViewDescription="Välj deltagare och initiera spel" /> ViewDescription="Välj deltagare och initiera spel" />
<Border Grid.Row="1" Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" > <Border Grid.Row="1" Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" >
<ScrollView Orientation="Horizontal"> <ScrollView Orientation="Horizontal">
<StackLayout x:Name="ResponsiveStack" Spacing="5" Style="{StaticResource ResponsiveStackStyle}" > <StackLayout x:Name="ResponsiveStack" Spacing="5" HeightRequest="125" Style="{StaticResource ResponsiveStackStyle}" >
<Border Stroke="Gray" <Border Stroke="Gray"
StrokeThickness="2" StrokeThickness="2"
BackgroundColor="LightGray" BackgroundColor="LightGray"
Padding="10" Padding="10"
Margin="2" Margin="2"
HorizontalOptions="Start" HorizontalOptions="Start"
VerticalOptions="Center" VerticalOptions="Center"
WidthRequest="250"> WidthRequest="250">
<Picker ItemsSource="{Binding ParticipantList}" <Picker ItemsSource="{Binding ParticipantList}"
ItemDisplayBinding="{Binding LastNameFirstName}" ItemDisplayBinding="{Binding LastNameFirstName}"
SelectedItem="{Binding SelectedItem}" SelectedItem="{Binding SelectedItem}"
@ -64,7 +64,7 @@
> >
<Border.GestureRecognizers> <Border.GestureRecognizers>
<TapGestureRecognizer <TapGestureRecognizer
Command="{Binding BindingContext.ParticipantTappedCommand, Source={x:Reference Name=ParticipantList}}" Command="{Binding BindingContext.SelectNewlyAddedParticipantCommand, Source={x:Reference Name=ParticipantList}}"
CommandParameter="{Binding .}" /> CommandParameter="{Binding .}" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
<Border Margin="1" Padding="2" StrokeThickness="3" > <Border Margin="1" Padding="2" StrokeThickness="3" >
@ -80,16 +80,16 @@
</CollectionView> </CollectionView>
</Border> </Border>
<Border <Border
HorizontalOptions="Start" HorizontalOptions="Start"
Padding="2" Padding="2"
Margin="5" Margin="5"
WidthRequest="150" WidthRequest="150"
HeightRequest="100" HeightRequest="100"
Stroke="LightGray" Stroke="LightGray"
StrokeThickness="1" StrokeThickness="1"
x:Name="RoundElementBorder" x:Name="RoundElementBorder"
BackgroundColor="BlanchedAlmond" BackgroundColor="BlanchedAlmond"
StrokeShape="RoundRectangle 10"> StrokeShape="RoundRectangle 10">
<VerticalStackLayout Spacing="5" Padding="4"> <VerticalStackLayout Spacing="5" Padding="4">
<Button Text="Spara omgång" WidthRequest="130" <Button Text="Spara omgång" WidthRequest="130"
Style="{StaticResource HoverButtonBlueStyle}" Style="{StaticResource HoverButtonBlueStyle}"
@ -119,6 +119,7 @@
ItemsLayout="HorizontalList" ItemsLayout="HorizontalList"
x:Name="InnerList" x:Name="InnerList"
Margin="0,10,0,10" Margin="0,10,0,10"
HeightRequest="90"
ItemSizingStrategy="MeasureAllItems"> ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate> <CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement"> <DataTemplate x:DataType="model:RoundBuilderElement">
@ -129,7 +130,7 @@
Style="{StaticResource StatusBorderStyle}" > Style="{StaticResource StatusBorderStyle}" >
<Border.GestureRecognizers> <Border.GestureRecognizers>
<TapGestureRecognizer <TapGestureRecognizer
Command="{Binding Path=BindingContext.ElementTappedCommand,Source={x:Reference OuterList}}" Command="{Binding Path=BindingContext.RoundSelectedCommand ,Source={x:Reference OuterList}}"
CommandParameter="{Binding .}" /> CommandParameter="{Binding .}" />
</Border.GestureRecognizers> </Border.GestureRecognizers>
@ -151,4 +152,4 @@
</Border> </Border>
</Grid> </Grid>
</Border> </Border>
</ContentView> </ContentPage>

View File

@ -1,38 +1,42 @@
using GreadyPoang.CommandClasses; using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views; namespace GreadyPoang.Views;
public partial class RoundStartingView : ContentView public partial class RoundStartingView : ContentPage
{ {
public RoundStartingView(RoundStartingViewModelCommands viewModel) public RoundStartingView(RoundStartingViewModel viewModel)
{ {
InitializeComponent(); InitializeComponent();
ViewModel = viewModel; ViewModel = viewModel;
} }
public RoundStartingViewModelCommands ViewModel { get; set; } public RoundStartingViewModel ViewModel { get; set; }
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 (ResponsiveStack == null || width <= 0) if (width < 500)
return; {
VisualStateManager.GoToState(ResponsiveStack, "Narrow");
var state = width < 500 ? "Narrow" : "Wide"; System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack=Narrow ");
VisualStateManager.GoToState(ResponsiveStack, state); }
System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack={state} "); else
{
VisualStateManager.GoToState(ResponsiveStack, "Wide");
System.Diagnostics.Debug.WriteLine($"width={width} ResponsiveStack=Wide ");
}
} }

View File

@ -1,30 +0,0 @@
<?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

@ -1,18 +0,0 @@
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

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