From 4c4e699f1f7ea8482466b484399aac721f3d6acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Przyw=C3=B3ski?= <35424311+marcin-przywoski@users.noreply.github.com> Date: Tue, 20 Feb 2024 01:23:46 +0100 Subject: [PATCH] UI Overhaul * Added Main.xaml view * Added Chats.xaml view * Added MainViewModel.cs * Added ChatsViewModel.cs * Added IMenuItem.cs interface for declaring which class is used for navigation within the views * Updated UtilitiesViewModel with IMenuItem interface * Changed OnStart method from async void to async Task in UtilitiesViewModel.cs * Replaced MainWindow view with Main for the startup in App.xaml.cs * Added logging to App.xaml.cs * Updated layout of Utilities.xaml view * Removed AddLogging --- ExportViewer.GUI/App.xaml.cs | 3 +- ExportViewer.GUI/Interfaces/IMenuItem.cs | 11 +++ ExportViewer.GUI/ViewModels/ChatsViewModel.cs | 12 +++ ExportViewer.GUI/ViewModels/MainViewModel.cs | 45 ++++++++++ .../ViewModels/UtilitiesViewModel.cs | 6 +- ExportViewer.GUI/Views/Chats.xaml | 56 +++++++++++++ ExportViewer.GUI/Views/Chats.xaml.cs | 26 ++++++ ExportViewer.GUI/Views/Main.xaml | 83 +++++++++++++++++++ ExportViewer.GUI/Views/Main.xaml.cs | 25 ++++++ ExportViewer.GUI/Views/Utilities.xaml | 17 ++-- 10 files changed, 275 insertions(+), 9 deletions(-) create mode 100644 ExportViewer.GUI/Interfaces/IMenuItem.cs create mode 100644 ExportViewer.GUI/ViewModels/ChatsViewModel.cs create mode 100644 ExportViewer.GUI/ViewModels/MainViewModel.cs create mode 100644 ExportViewer.GUI/Views/Chats.xaml create mode 100644 ExportViewer.GUI/Views/Chats.xaml.cs create mode 100644 ExportViewer.GUI/Views/Main.xaml create mode 100644 ExportViewer.GUI/Views/Main.xaml.cs diff --git a/ExportViewer.GUI/App.xaml.cs b/ExportViewer.GUI/App.xaml.cs index 7ebffff..0b33e41 100644 --- a/ExportViewer.GUI/App.xaml.cs +++ b/ExportViewer.GUI/App.xaml.cs @@ -31,6 +31,7 @@ public App() private void ConfigureServices(ServiceCollection services) { services.AddSingleton(); + services.AddSingleton
(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -40,7 +41,7 @@ private void ConfigureServices(ServiceCollection services) } private void OnStartup(object sender, StartupEventArgs e) { - var mainWindow = serviceProvider.GetService(); + var mainWindow = serviceProvider.GetService
(); mainWindow.Show(); } } diff --git a/ExportViewer.GUI/Interfaces/IMenuItem.cs b/ExportViewer.GUI/Interfaces/IMenuItem.cs new file mode 100644 index 0000000..70031f5 --- /dev/null +++ b/ExportViewer.GUI/Interfaces/IMenuItem.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ExportViewer.GUI.Interfaces +{ + public interface IMenuItem + { + public string Title { get; } + } +} diff --git a/ExportViewer.GUI/ViewModels/ChatsViewModel.cs b/ExportViewer.GUI/ViewModels/ChatsViewModel.cs new file mode 100644 index 0000000..9fc3dd1 --- /dev/null +++ b/ExportViewer.GUI/ViewModels/ChatsViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ExportViewer.GUI.Interfaces; + +namespace ExportViewer.GUI.ViewModels +{ + public class ChatsViewModel : IMenuItem + { + public string Title => "Chats"; + } +} diff --git a/ExportViewer.GUI/ViewModels/MainViewModel.cs b/ExportViewer.GUI/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..4c1eef6 --- /dev/null +++ b/ExportViewer.GUI/ViewModels/MainViewModel.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using System.Windows.Controls; +using CommunityToolkit.Mvvm.ComponentModel; +using ExportViewer.GUI.Interfaces; + +namespace ExportViewer.GUI.ViewModels +{ + public class MainViewModel : ObservableObject + { + public ObservableCollection MenuItems { get; } + + private object? _selectedItem; + public object? SelectedItem + { + get => _selectedItem; + set + { + if (SetProperty(ref _selectedItem , value)) + { + IsMenuOpen = false; + } + } + } + + private bool isMenuOpen; + public bool IsMenuOpen + { + get => isMenuOpen; + set => SetProperty(ref isMenuOpen , value); + } + + public MainViewModel () + { + MenuItems = new ObservableCollection() + { + new UtilitiesViewModel(), + new ChatsViewModel() + }; + SelectedItem = MenuItems[0]; + } + } +} diff --git a/ExportViewer.GUI/ViewModels/UtilitiesViewModel.cs b/ExportViewer.GUI/ViewModels/UtilitiesViewModel.cs index f2d58dd..5eab9fe 100644 --- a/ExportViewer.GUI/ViewModels/UtilitiesViewModel.cs +++ b/ExportViewer.GUI/ViewModels/UtilitiesViewModel.cs @@ -18,7 +18,7 @@ namespace ExportViewer.GUI.ViewModels { - public partial class UtilitiesViewModel + public partial class UtilitiesViewModel : IMenuItem { private readonly IHtmlParsingService htmlParsingService = App.Current.serviceProvider.GetRequiredService(); private readonly IJsonParsingService jsonParsingService = App.Current.serviceProvider.GetRequiredService(); @@ -31,13 +31,15 @@ public UtilitiesViewModel () { } + public string Title => "Utilities"; public IUtilities Utilities { get; set; } public UtilitiesModel _utilitiesModel { get; set; } = new UtilitiesModel(); + [RelayCommand] - async void OnStart () + async Task OnStart () { if (String.IsNullOrEmpty(_utilitiesModel.SourcePath) || String.IsNullOrEmpty(_utilitiesModel.DestinationPath)) { diff --git a/ExportViewer.GUI/Views/Chats.xaml b/ExportViewer.GUI/Views/Chats.xaml new file mode 100644 index 0000000..f972850 --- /dev/null +++ b/ExportViewer.GUI/Views/Chats.xaml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + Chat 1 + Chat 2 + Chat 3 + + + + + + + + + + Chat Header + + + + + + Sender 1: Message 1 + Sender 2: Message 2 + + + + + +