Added LastRaided feature

This commit is contained in:
Enrico Ludwig 2024-08-26 20:56:44 +02:00
parent 2ca8da61a7
commit 4311bfb43f
5 changed files with 52 additions and 2 deletions

View File

@ -62,6 +62,9 @@
HorizontalContentAlignment="Center" HorizontalContentAlignment="Center"
Foreground="{Binding ViewerCountColor}" Foreground="{Binding ViewerCountColor}"
Content="{Binding Channel.ViewerCount}" /> Content="{Binding Channel.ViewerCount}" />
<Label HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"
Content="{Binding LastRaided, TargetNullValue=Never Raided}" />
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -28,6 +28,7 @@ public class BetterRaidDatabase : INotifyPropertyChanged
} }
} }
public List<string> Channels { get; set; } = []; public List<string> Channels { get; set; } = [];
public Dictionary<string, DateTime?> LastRaided = [];
public bool AutoSave { get; set; } public bool AutoSave { get; set; }
public static BetterRaidDatabase LoadFromFile(string path) public static BetterRaidDatabase LoadFromFile(string path)
@ -51,6 +52,14 @@ public class BetterRaidDatabase : INotifyPropertyChanged
dbObj._databaseFilePath = path; dbObj._databaseFilePath = path;
foreach (var channel in dbObj.Channels)
{
if (dbObj.LastRaided.ContainsKey(channel) == false)
{
dbObj.LastRaided.Add(channel, null);
}
}
Console.WriteLine("[DEBUG] Loaded database from {0}", path); Console.WriteLine("[DEBUG] Loaded database from {0}", path);
return dbObj; return dbObj;
@ -93,6 +102,36 @@ public class BetterRaidDatabase : INotifyPropertyChanged
OnPropertyChanged(nameof(Channels)); OnPropertyChanged(nameof(Channels));
} }
public void SetRaided(string channel, DateTime dateTime)
{
ArgumentNullException.ThrowIfNull(channel);
if (LastRaided.ContainsKey(channel))
{
LastRaided[channel] = dateTime;
}
else
{
LastRaided.Add(channel, dateTime);
}
OnPropertyChanged(nameof(LastRaided));
}
public DateTime? GetLastRaided(string channel)
{
ArgumentNullException.ThrowIfNull(channel);
if (LastRaided.ContainsKey(channel))
{
return LastRaided[channel];
}
else
{
return null;
}
}
private void OnPropertyChanged([CallerMemberName] string? propertyName = null) private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

View File

@ -31,6 +31,8 @@ public class RaidButtonViewModel : ViewModelBase
public MainWindowViewModel? MainVm { get; set; } public MainWindowViewModel? MainVm { get; set; }
public DateTime? LastRaided => MainVm?.Database?.GetLastRaided(ChannelName);
public async Task<bool> GetOrUpdateChannelAsync() public async Task<bool> GetOrUpdateChannelAsync()
{ {
if (_channel == null) if (_channel == null)
@ -119,6 +121,11 @@ public class RaidButtonViewModel : ViewModelBase
var createdAt = raid.Data[0].CreatedAt; var createdAt = raid.Data[0].CreatedAt;
var isMature = raid.Data[0].IsMature; var isMature = raid.Data[0].IsMature;
} }
if (MainVm?.Database != null)
{
MainVm.Database.SetRaided(ChannelName, DateTime.Now);
}
} }
public void RemoveChannel() public void RemoveChannel()

View File

@ -173,8 +173,9 @@ public partial class MainWindow : Window
var addButton = new Button var addButton = new Button
{ {
Content = "+", Content = "+",
FontSize = 36, FontSize = 72,
Margin = new Avalonia.Thickness(5), Margin = new Avalonia.Thickness(5),
MinHeight = 250,
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch, HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Stretch, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Stretch,
HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center, HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center,

View File

@ -1 +1 @@
{"OnlyOnline":true,"Channels":["Cedricun","ZanTal","PropzMaster","Artimus83","HyperonsLive","theshroomlife","Robocraft999","sllikson","Aron_dc","AIEsports","TobinatorLP","Lordabgrund","GronkhTV"],"AutoSave":true} {"LastRaided":{"Cedricun":null,"ZanTal":null,"PropzMaster":null,"Artimus83":null,"HyperonsLive":null,"theshroomlife":null,"Robocraft999":null,"sllikson":null,"Aron_dc":null,"AIEsports":null,"TobinatorLP":null,"Lordabgrund":null,"GronkhTV":null},"OnlyOnline":false,"Channels":["Cedricun","ZanTal","PropzMaster","Artimus83","HyperonsLive","theshroomlife","Robocraft999","sllikson","Aron_dc","AIEsports","TobinatorLP","Lordabgrund","GronkhTV"],"AutoSave":true}