Optimized filtering / data handling, started working on adding channels
This commit is contained in:
parent
1d0b109fcf
commit
832f1fd150
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.5.002.0
|
VisualStudioVersion = 17.5.002.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterRaid", "BetterRaid.csproj", "{7AB75970-30DB-496E-960C-535708A65EC6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterRaid", "BetterRaid.csproj", "{C36B7D6A-D155-4AED-8A75-4D947FD7E4D2}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,10 +11,10 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{7AB75970-30DB-496E-960C-535708A65EC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{C36B7D6A-D155-4AED-8A75-4D947FD7E4D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{7AB75970-30DB-496E-960C-535708A65EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C36B7D6A-D155-4AED-8A75-4D947FD7E4D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7AB75970-30DB-496E-960C-535708A65EC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C36B7D6A-D155-4AED-8A75-4D947FD7E4D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7AB75970-30DB-496E-960C-535708A65EC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C36B7D6A-D155-4AED-8A75-4D947FD7E4D2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
Orientation="Vertical">
|
Orientation="Vertical">
|
||||||
<Label HorizontalAlignment="Stretch"
|
<Label HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center"
|
||||||
Content="{Binding Channel.Name}" />
|
Content="{Binding Channel.DisplayName}" />
|
||||||
<Label HorizontalAlignment="Stretch"
|
<Label HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center"
|
||||||
Foreground="{Binding ViewerCountColor}"
|
Foreground="{Binding ViewerCountColor}"
|
||||||
|
9
ViewModels/AddChannelWindowViewModel.cs
Normal file
9
ViewModels/AddChannelWindowViewModel.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace BetterRaid.ViewModels;
|
||||||
|
|
||||||
|
public class AddChannelWindowViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
public void AddChannel()
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("BLABLABLA");
|
||||||
|
}
|
||||||
|
}
|
@ -6,18 +6,18 @@ namespace BetterRaid.ViewModels;
|
|||||||
public partial class MainWindowViewModel : ViewModelBase
|
public partial class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private string? _filter;
|
private string? _filter;
|
||||||
|
private bool _onlyOnline;
|
||||||
|
|
||||||
public string? Filter
|
public string? Filter
|
||||||
{
|
{
|
||||||
get => _filter;
|
get => _filter;
|
||||||
set
|
set => SetProperty(ref _filter, value);
|
||||||
{
|
}
|
||||||
if (value == _filter)
|
|
||||||
return;
|
public bool OnlyOnline
|
||||||
|
{
|
||||||
_filter = value;
|
get => _onlyOnline;
|
||||||
OnPropertyChanged();
|
set => SetProperty(ref _onlyOnline, value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExitApplication()
|
public void ExitApplication()
|
||||||
|
@ -14,6 +14,12 @@ public class RaidButtonViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
private TwitchChannel? _channel;
|
private TwitchChannel? _channel;
|
||||||
private SolidColorBrush _viewerCountColor = new SolidColorBrush(Color.FromRgb(byte.MaxValue, byte.MaxValue, byte.MaxValue));
|
private SolidColorBrush _viewerCountColor = new SolidColorBrush(Color.FromRgb(byte.MaxValue, byte.MaxValue, byte.MaxValue));
|
||||||
|
|
||||||
|
public bool ShowInGrid
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
} = true;
|
||||||
|
|
||||||
public required string ChannelName
|
public required string ChannelName
|
||||||
{
|
{
|
||||||
@ -56,7 +62,9 @@ public class RaidButtonViewModel : ViewModelBase
|
|||||||
_channel.DisplayName = currentChannelData.DisplayName;
|
_channel.DisplayName = currentChannelData.DisplayName;
|
||||||
_channel.IsLive = currentChannelData.IsLive;
|
_channel.IsLive = currentChannelData.IsLive;
|
||||||
_channel.ThumbnailUrl = currentChannelData.ThumbnailUrl;
|
_channel.ThumbnailUrl = currentChannelData.ThumbnailUrl;
|
||||||
_channel.ViewerCount = currentStreamData?.ViewerCount.ToString() ?? "(Offline)";
|
_channel.ViewerCount = currentStreamData?.ViewerCount == null
|
||||||
|
? "(Offline)"
|
||||||
|
: $"{currentStreamData?.ViewerCount} Viewers";
|
||||||
|
|
||||||
if (_channel.IsLive)
|
if (_channel.IsLive)
|
||||||
{
|
{
|
||||||
|
37
Views/AddChannelWindow.axaml
Normal file
37
Views/AddChannelWindow.axaml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:vm="using:BetterRaid.ViewModels"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="50"
|
||||||
|
x:Class="BetterRaid.Views.AddChannelWindow"
|
||||||
|
x:DataType="vm:AddChannelWindowViewModel"
|
||||||
|
Width="200"
|
||||||
|
Height="80"
|
||||||
|
MaxWidth="200"
|
||||||
|
MaxHeight="80"
|
||||||
|
Title="Add Channel">
|
||||||
|
|
||||||
|
<Design.DataContext>
|
||||||
|
<vm:AddChannelWindowViewModel/>
|
||||||
|
</Design.DataContext>
|
||||||
|
|
||||||
|
<StackPanel Orientation="Vertical"
|
||||||
|
Margin="5"
|
||||||
|
Spacing="5"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch">
|
||||||
|
|
||||||
|
<TextBox HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
x:Name="channelNameTxt"
|
||||||
|
Watermark="Enter Channelname" />
|
||||||
|
|
||||||
|
<Button HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Content="OK"
|
||||||
|
x:Name="okBtn"
|
||||||
|
IsEnabled="True" />
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</Window>
|
13
Views/AddChannelWindow.axaml.cs
Normal file
13
Views/AddChannelWindow.axaml.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
|
namespace BetterRaid.Views;
|
||||||
|
|
||||||
|
public partial class AddChannelWindow : Window
|
||||||
|
{
|
||||||
|
public AddChannelWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,8 @@
|
|||||||
x:Class="BetterRaid.Views.MainWindow"
|
x:Class="BetterRaid.Views.MainWindow"
|
||||||
x:DataType="vm:MainWindowViewModel"
|
x:DataType="vm:MainWindowViewModel"
|
||||||
Icon="/Assets/avalonia-logo.ico"
|
Icon="/Assets/avalonia-logo.ico"
|
||||||
Title="BetterRaid">
|
Title="BetterRaid"
|
||||||
|
WindowStartupLocation="CenterScreen">
|
||||||
|
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
<vm:MainWindowViewModel/>
|
<vm:MainWindowViewModel/>
|
||||||
@ -40,13 +41,23 @@
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
<TextBox Grid.Column="1"
|
<StackPanel Grid.Column="1"
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Width="200"
|
Orientation="Horizontal"
|
||||||
Margin="2"
|
Spacing="5">
|
||||||
Watermark="Filter Channels"
|
|
||||||
Text="{Binding Filter, Mode=TwoWay}"
|
<CheckBox Content="Only Online"
|
||||||
HorizontalAlignment="Right" />
|
IsChecked="{Binding OnlyOnline, Mode=TwoWay}" />
|
||||||
|
|
||||||
|
<TextBox Grid.Column="1"
|
||||||
|
Grid.Row="0"
|
||||||
|
Width="200"
|
||||||
|
Margin="2"
|
||||||
|
Watermark="Filter Channels"
|
||||||
|
Text="{Binding Filter, Mode=TwoWay}"
|
||||||
|
HorizontalAlignment="Right" />
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
<ScrollViewer Grid.Column="0"
|
<ScrollViewer Grid.Column="0"
|
||||||
Grid.ColumnSpan="2"
|
Grid.ColumnSpan="2"
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using BetterRaid.ViewModels;
|
using BetterRaid.ViewModels;
|
||||||
|
|
||||||
@ -9,6 +12,7 @@ namespace BetterRaid.Views;
|
|||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
private ObservableCollection<RaidButtonViewModel> _raidButtonVMs;
|
||||||
private BackgroundWorker _autoUpdater;
|
private BackgroundWorker _autoUpdater;
|
||||||
|
|
||||||
private string[] _channelNames = [
|
private string[] _channelNames = [
|
||||||
@ -26,12 +30,17 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
_autoUpdater = new BackgroundWorker();
|
_raidButtonVMs = [];
|
||||||
|
_autoUpdater = new();
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
InitializeRaidChannels();
|
||||||
GenerateRaidGrid();
|
GenerateRaidGrid();
|
||||||
|
|
||||||
DataContextChanged += OnDataContextChanged;
|
DataContextChanged += OnDataContextChanged;
|
||||||
|
|
||||||
|
_autoUpdater.DoWork += UpdateAllTiles;
|
||||||
|
_autoUpdater.RunWorkerAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDataContextChanged(object? sender, EventArgs e)
|
private void OnDataContextChanged(object? sender, EventArgs e)
|
||||||
@ -50,56 +59,91 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(mainWindowVm.Filter))
|
if (string.IsNullOrEmpty(mainWindowVm.Filter))
|
||||||
{
|
{
|
||||||
foreach (var child in raidGrid.Children)
|
foreach (var vm in _raidButtonVMs)
|
||||||
{
|
{
|
||||||
child.IsVisible = true;
|
vm.ShowInGrid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var child in raidGrid.Children)
|
foreach (var vm in _raidButtonVMs)
|
||||||
{
|
{
|
||||||
if (child.DataContext is RaidButtonViewModel vm)
|
if (string.IsNullOrEmpty(mainWindowVm.Filter))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(vm.Channel?.DisplayName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vm.ShowInGrid = vm.Channel.DisplayName.Contains(mainWindowVm.Filter, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateRaidGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.PropertyName == nameof(MainWindowViewModel.OnlyOnline))
|
||||||
|
{
|
||||||
|
if (DataContext is MainWindowViewModel mainWindowVm)
|
||||||
|
{
|
||||||
|
foreach (var vm in _raidButtonVMs)
|
||||||
|
{
|
||||||
|
if (mainWindowVm.OnlyOnline)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(vm.Channel?.DisplayName))
|
vm.ShowInGrid = vm.Channel.IsLive;
|
||||||
continue;
|
}
|
||||||
|
else
|
||||||
if (string.IsNullOrEmpty(mainWindowVm.Filter))
|
{
|
||||||
continue;
|
vm.ShowInGrid = true;
|
||||||
|
|
||||||
if (vm.Channel.DisplayName.Contains(mainWindowVm.Filter, StringComparison.OrdinalIgnoreCase) == false)
|
|
||||||
{
|
|
||||||
child.IsVisible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GenerateRaidGrid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateRaidGrid()
|
private void InitializeRaidChannels()
|
||||||
{
|
{
|
||||||
var rows = (int)Math.Ceiling(_channelNames.Length / 3.0);
|
_raidButtonVMs.Clear();
|
||||||
|
|
||||||
for (var i = 0; i < rows; i++)
|
|
||||||
{
|
|
||||||
raidGrid.RowDefinitions.Add(new RowDefinition(GridLength.Parse("*")));
|
|
||||||
}
|
|
||||||
|
|
||||||
var colIndex = 0;
|
|
||||||
var rowIndex = 0;
|
|
||||||
foreach (var channel in _channelNames)
|
foreach (var channel in _channelNames)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(channel))
|
if (string.IsNullOrEmpty(channel))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
_raidButtonVMs.Add(new RaidButtonViewModel
|
||||||
|
{
|
||||||
|
ChannelName = channel
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GenerateRaidGrid()
|
||||||
|
{
|
||||||
|
foreach (var child in raidGrid.Children)
|
||||||
|
{
|
||||||
|
if (child is Button btn)
|
||||||
|
{
|
||||||
|
btn.Click -= OnAddChannelButtonClicked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
raidGrid.Children.Clear();
|
||||||
|
|
||||||
|
var visibleChannels = _raidButtonVMs.Where(c => c.ShowInGrid).ToList();
|
||||||
|
var rows = (int)Math.Ceiling((visibleChannels.Count + 1) / 3.0);
|
||||||
|
|
||||||
|
for (var i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
raidGrid.RowDefinitions.Add(new RowDefinition(GridLength.Parse("Auto")));
|
||||||
|
}
|
||||||
|
|
||||||
|
var colIndex = 0;
|
||||||
|
var rowIndex = 0;
|
||||||
|
foreach (var channel in visibleChannels)
|
||||||
|
{
|
||||||
var btn = new RaidButton
|
var btn = new RaidButton
|
||||||
{
|
{
|
||||||
DataContext = new RaidButtonViewModel
|
DataContext = channel
|
||||||
{
|
|
||||||
ChannelName = channel
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Grid.SetColumn(btn, colIndex);
|
Grid.SetColumn(btn, colIndex);
|
||||||
@ -120,8 +164,45 @@ public partial class MainWindow : Window
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_autoUpdater.DoWork += UpdateAllTiles;
|
var addButton = new Button
|
||||||
_autoUpdater.RunWorkerAsync();
|
{
|
||||||
|
Content = "+",
|
||||||
|
FontSize = 36,
|
||||||
|
Margin = new Avalonia.Thickness(5),
|
||||||
|
HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
|
||||||
|
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Stretch,
|
||||||
|
HorizontalContentAlignment = Avalonia.Layout.HorizontalAlignment.Center,
|
||||||
|
VerticalContentAlignment = Avalonia.Layout.VerticalAlignment.Center
|
||||||
|
};
|
||||||
|
|
||||||
|
addButton.Click += OnAddChannelButtonClicked;
|
||||||
|
|
||||||
|
Grid.SetColumn(addButton, colIndex);
|
||||||
|
Grid.SetRow(addButton, rowIndex);
|
||||||
|
|
||||||
|
raidGrid.Children.Add(addButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAddChannelButtonClicked(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new AddChannelWindow();
|
||||||
|
dialog.Position = new Avalonia.PixelPoint(
|
||||||
|
(int)(Position.X + Width / 2 - dialog.Width / 2),
|
||||||
|
(int)(Position.Y + Height / 2 - dialog.Height / 2)
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO Button Command not working, Button remains disabled
|
||||||
|
// This is a dirty workaround
|
||||||
|
dialog.okBtn.Click += (sender, args) => {
|
||||||
|
Array.Resize(ref _channelNames, _channelNames.Length + 1);
|
||||||
|
_channelNames[^1] = dialog?.channelNameTxt.Text ?? "";
|
||||||
|
dialog?.Close();
|
||||||
|
|
||||||
|
InitializeRaidChannels();
|
||||||
|
GenerateRaidGrid();
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.ShowDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateAllTiles(object? sender, DoWorkEventArgs e)
|
public void UpdateAllTiles(object? sender, DoWorkEventArgs e)
|
||||||
@ -138,16 +219,14 @@ public partial class MainWindow : Window
|
|||||||
foreach (var children in raidGrid.Children)
|
foreach (var children in raidGrid.Children)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.InvokeAsync(async () =>
|
Dispatcher.UIThread.InvokeAsync(async () =>
|
||||||
{
|
|
||||||
if (children.DataContext is RaidButtonViewModel vm)
|
|
||||||
{
|
{
|
||||||
await vm.GetOrUpdateChannelAsync();
|
if (children.DataContext is RaidButtonViewModel vm)
|
||||||
|
{
|
||||||
|
await vm.GetOrUpdateChannelAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Data Update");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user