From 5f45d28b9ff6ece9ad98bdec4b19d5895810cf21 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 12 Jul 2022 00:18:56 -0600 Subject: [PATCH] Refinements --- .../AvaloniaUI/Assets/edit_25x25.png | Bin 0 -> 747 bytes .../AvaloniaUI/ViewModels/BookTags.cs | 47 +-------- .../ViewModels/LibraryBookEntry2.cs | 2 +- .../AvaloniaUI/ViewModels/ProcessBook2.cs | 4 +- .../ViewModels/ProcessQueueViewModel.cs | 20 ++-- .../AvaloniaUI/ViewModels/SeriesEntrys2.cs | 6 +- .../Views/ProcessQueueControl2.axaml | 2 +- .../Views/ProcessQueueControl2.axaml.cs | 96 +++++++++++++----- .../AvaloniaUI/Views/ProductsDisplay2.axaml | 26 ++--- .../Views/ProductsDisplay2.axaml.cs | 18 ++-- .../LibationWinForms/LibationWinForms.csproj | 1 + 11 files changed, 115 insertions(+), 107 deletions(-) create mode 100644 Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png b/Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png new file mode 100644 index 0000000000000000000000000000000000000000..12e70d0f1edeab1507607513178535e4a578dda6 GIT binary patch literal 747 zcmVP000>X1^@s6#OZ}&00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0)RR$bUivCZTjzmrLD5;A$TUHOGC_tl)=J@?$1GHsyJBO?x3xrFWn{Fy~2 zN)_MVP)N%2#+djKx=uJlA4u$IqA^&P_N7v0ci|@JQkK~0NnxLKBv9pSuBjho9ln@PxTG7X+cEBYfNQ_Sc7W@%_2u- z;d_X1d8S;hDdZ0(hU!b*^%Z-_vN7+G!3~TR5O>`3a2_cYXMLX((%k(D{0)v~)6{QF zpHH}Mp;iqvxMtBQ1Jw^WH{+LIhC>`l1oDal=Va+iDQJvagc>A}ffjiZj>|wdISRn* za2U!o+OBE^ z5iSJftG4#W^Sp4TO+6vF$6J_bnuVSNbQM!k&`&rQ)PjO*%$O0`6i&CQuj7Iaf;Nrz z89-Oi>P^&ZnzdrzISJ<$UW~Ez>KCFqjI5rZLQm1Z0OwJIf?=b<^|^_S)f*zRjBm|C zy#VKy7MCALV2bFg&cIz?Nqs*jal-E_Xm-P&aCFD!DwU=BLPUcc*P8YJK%zA%vZYhZ zcA%PAHgjlp!Lc=oLKfkVaC6+Rj==h_qAR3~w)6X7Fueuj1R(mLwn%Go4)*J#wMzp( d>;xbp`U|)M@ !string.IsNullOrEmpty(Tags); } } diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/LibraryBookEntry2.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/LibraryBookEntry2.cs index 84a77d82..be7f5cf5 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/LibraryBookEntry2.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/LibraryBookEntry2.cs @@ -81,7 +81,7 @@ namespace LibationWinForms.AvaloniaUI.ViewModels Category = string.Join(" > ", Book.CategoriesNames()); Misc = GetMiscDisplay(libraryBook); LongDescription = GetDescriptionDisplay(Book); - Description = LongDescription; + Description = TrimTextToWord(LongDescription, 62); SeriesIndex = Book.SeriesLink.FirstOrDefault()?.Index ?? 0; NotifyPropertyChanged(nameof(Title)); diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs index 97241615..067fff42 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessBook2.cs @@ -53,8 +53,8 @@ namespace LibationWinForms.AvaloniaUI.ViewModels private Bitmap _cover; #region Properties exposed to the view - public ProcessBookResult Result { get => _result; private set { _result = value; NotifyPropertyChanged(); NotifyPropertyChanged(nameof(StatusText)); } } - public ProcessBookStatus Status { get => _status; private set { _status = value; NotifyPropertyChanged(); NotifyPropertyChanged(nameof(BackgroundColor)); NotifyPropertyChanged(nameof(IsFinished)); NotifyPropertyChanged(nameof(IsDownloading)); NotifyPropertyChanged(nameof(Queued)); } } + public ProcessBookResult Result { get => _result; set { _result = value; NotifyPropertyChanged(); NotifyPropertyChanged(nameof(StatusText)); } } + public ProcessBookStatus Status { get => _status; set { _status = value; NotifyPropertyChanged(); NotifyPropertyChanged(nameof(BackgroundColor)); NotifyPropertyChanged(nameof(IsFinished)); NotifyPropertyChanged(nameof(IsDownloading)); NotifyPropertyChanged(nameof(Queued)); } } public string Narrator { get => _narrator; set { _narrator = value; NotifyPropertyChanged(); } } public string Author { get => _author; set { _author = value; NotifyPropertyChanged(); } } public string Title { get => _title; set { _title = value; NotifyPropertyChanged(); } } diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessQueueViewModel.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessQueueViewModel.cs index 1d610264..8d30937d 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessQueueViewModel.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/ProcessQueueViewModel.cs @@ -1,14 +1,11 @@ -using ReactiveUI; +using Avalonia.Threading; +using ReactiveUI; using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LibationWinForms.AvaloniaUI.ViewModels { - public class ProcessQueueViewModel : ViewModelBase + public class ProcessQueueViewModel : ViewModelBase, ProcessQueue.ILogForm { public string QueueHeader => "this is a header!"; @@ -24,6 +21,17 @@ namespace LibationWinForms.AvaloniaUI.ViewModels public ObservableCollection LogEntries { get; } = new(); public ProcessBook2 SelectedItem { get; set; } + + public void WriteLine(string text) + { + Dispatcher.UIThread.Post(() => + LogEntries.Add(new() + { + LogDate = DateTime.Now, + LogMessage = text.Trim() + })); + } + } public class LogEntry diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/SeriesEntrys2.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/SeriesEntrys2.cs index 118dfe46..3a403335 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/SeriesEntrys2.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/SeriesEntrys2.cs @@ -91,13 +91,11 @@ namespace LibationWinForms.AvaloniaUI.ViewModels Category = string.Join(" > ", Book.CategoriesNames()); Misc = GetMiscDisplay(LibraryBook); LongDescription = GetDescriptionDisplay(Book); - Description = LongDescription; + Description = TrimTextToWord(LongDescription, 62); int bookLenMins = Children.Sum(c => c.LibraryBook.Book.LengthInMinutes); Length = bookLenMins == 0 ? "" : $"{bookLenMins / 60} hr {bookLenMins % 60} min"; - - NotifyPropertyChanged(nameof(Title)); NotifyPropertyChanged(nameof(Series)); NotifyPropertyChanged(nameof(Length)); @@ -110,8 +108,6 @@ namespace LibationWinForms.AvaloniaUI.ViewModels NotifyPropertyChanged(nameof(Misc)); NotifyPropertyChanged(nameof(LongDescription)); NotifyPropertyChanged(nameof(Description)); - - NotifyPropertyChanged(); } #region Data Sorting diff --git a/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml b/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml index 0145e46b..8bb8c708 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml +++ b/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:views="clr-namespace:LibationWinForms.AvaloniaUI.Views" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="700" + mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="850" x:Class="LibationWinForms.AvaloniaUI.Views.ProcessQueueControl2"> diff --git a/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml.cs index e708737d..5c2200c5 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/ProcessQueueControl2.axaml.cs @@ -4,6 +4,7 @@ using Avalonia.Controls; using Avalonia.Input; using Avalonia.Markup.Xaml; using Avalonia.Threading; +using DataLayer; using LibationWinForms.AvaloniaUI.ViewModels; using System; using System.Collections.Generic; @@ -13,7 +14,7 @@ using System.Threading.Tasks; namespace LibationWinForms.AvaloniaUI.Views { - public partial class ProcessQueueControl2 : UserControl, ProcessQueue.ILogForm + public partial class ProcessQueueControl2 : UserControl { private readonly ProcessQueueViewModel _viewModel; private ItemsRepeater _repeater; @@ -65,6 +66,7 @@ namespace LibationWinForms.AvaloniaUI.Views _repeater.PointerPressed += RepeaterClick; _repeater.KeyDown += RepeaterOnKeyDown; DataContext = _viewModel = new ProcessQueueViewModel(); + Logger = ProcessQueue.LogMe.RegisterForm(_viewModel); ProcessBookControl2.PositionButtonClicked += ProcessBookControl2_ButtonClicked; ProcessBookControl2.CancelButtonClicked += ProcessBookControl2_CancelButtonClicked; @@ -81,19 +83,68 @@ namespace LibationWinForms.AvaloniaUI.Views toolStripProgressBar1 = this.FindControl(nameof(toolStripProgressBar1)); - Logger = ProcessQueue.LogMe.RegisterForm(this); Queue.QueuededCountChanged += Queue_QueuededCountChanged; Queue.CompletedCountChanged += Queue_CompletedCountChanged; + #region Design Mode Testing if (Design.IsDesignMode) - return; + { + using var context = DbContexts.GetContext(); + var book = context.GetLibraryBook_Flat_NoTracking("B017V4IM1G"); + List testList = new() + { + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.FailedAbort, + Status = ProcessBookStatus.Failed, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.FailedSkip, + Status = ProcessBookStatus.Failed, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.FailedRetry, + Status = ProcessBookStatus.Failed, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.ValidationFail, + Status = ProcessBookStatus.Failed, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.Cancelled, + Status = ProcessBookStatus.Cancelled, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.Success, + Status = ProcessBookStatus.Completed, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.None, + Status = ProcessBookStatus.Working, + }, + new ProcessBook2(book, Logger) + { + Result = ProcessBookResult.None, + Status = ProcessBookStatus.Queued, + }, + }; - runningTimeLbl.Text = string.Empty; - QueuedCount = 0; - ErrorCount = 0; - CompletedCount = 0; + _viewModel.Items.Enqueue(testList); + return; + } + #endregion + runningTimeLbl.Text = string.Empty; + QueuedCount = 0; + ErrorCount = 0; + CompletedCount = 0; } private void InitializeComponent() @@ -156,19 +207,19 @@ namespace LibationWinForms.AvaloniaUI.Views } - private bool isBookInQueue(DataLayer.LibraryBook libraryBook) + private bool isBookInQueue(LibraryBook libraryBook) => Queue.Any(b => b?.LibraryBook?.Book?.AudibleProductId == libraryBook.Book.AudibleProductId); - public void AddDownloadPdf(DataLayer.LibraryBook libraryBook) - => AddDownloadPdf(new List() { libraryBook }); + public void AddDownloadPdf(LibraryBook libraryBook) + => AddDownloadPdf(new List() { libraryBook }); - public void AddDownloadDecrypt(DataLayer.LibraryBook libraryBook) - => AddDownloadDecrypt(new List() { libraryBook }); + public void AddDownloadDecrypt(LibraryBook libraryBook) + => AddDownloadDecrypt(new List() { libraryBook }); - public void AddConvertMp3(DataLayer.LibraryBook libraryBook) - => AddConvertMp3(new List() { libraryBook }); + public void AddConvertMp3(LibraryBook libraryBook) + => AddConvertMp3(new List() { libraryBook }); - public void AddDownloadPdf(IEnumerable entries) + public void AddDownloadPdf(IEnumerable entries) { List procs = new(); foreach (var entry in entries) @@ -185,7 +236,7 @@ namespace LibationWinForms.AvaloniaUI.Views AddToQueue(procs); } - public void AddDownloadDecrypt(IEnumerable entries) + public void AddDownloadDecrypt(IEnumerable entries) { List procs = new(); foreach (var entry in entries) @@ -203,7 +254,7 @@ namespace LibationWinForms.AvaloniaUI.Views AddToQueue(procs); } - public void AddConvertMp3(IEnumerable entries) + public void AddConvertMp3(IEnumerable entries) { List procs = new(); foreach (var entry in entries) @@ -266,17 +317,6 @@ namespace LibationWinForms.AvaloniaUI.Views Serilog.Log.Logger.Error(ex, "An error was encountered while processing queued items"); } } - - public void WriteLine(string text) - { - Dispatcher.UIThread.Post(() => - _viewModel.LogEntries.Add(new() - { - LogDate = DateTime.Now, - LogMessage = text.Trim() - })); - } - #region Control event handlers private void Queue_CompletedCountChanged(object sender, int e) diff --git a/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml b/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml index 1c621246..15f17211 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml +++ b/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml @@ -6,13 +6,11 @@ xmlns:controls="clr-namespace:LibationWinForms.AvaloniaUI.Controls" mc:Ignorable="d" d:DesignWidth="1560" d:DesignHeight="400" x:Class="LibationWinForms.AvaloniaUI.Views.ProductsDisplay2"> - - + - - + @@ -25,8 +23,7 @@ - - + @@ -36,7 +33,7 @@ - + @@ -46,7 +43,7 @@ - + @@ -56,7 +53,7 @@ - + @@ -66,7 +63,7 @@ - + @@ -76,7 +73,7 @@ - + @@ -150,7 +147,12 @@ - diff --git a/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml.cs b/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml.cs index 23481a26..61db5b9c 100644 --- a/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml.cs +++ b/Source/LibationWinForms/AvaloniaUI/Views/ProductsDisplay2.axaml.cs @@ -3,6 +3,7 @@ using AudibleUtilities; using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Avalonia.Media; using DataLayer; using Dinah.Core.DataBinding; using FileLiberator; @@ -26,7 +27,7 @@ namespace LibationWinForms.AvaloniaUI.Views public event EventHandler InitialLoaded; private ProductsDisplayViewModel _viewModel; - private GridEntryBindingList2 bindingList => productsGrid.Items as GridEntryBindingList2; + private GridEntryBindingList2 bindingList => _viewModel.GridEntries; private IEnumerable GetAllBookEntries() => bindingList.AllItems().BookEntries(); @@ -46,12 +47,14 @@ namespace LibationWinForms.AvaloniaUI.Views productsGrid.CanUserSortColumns = true; removeGVColumn = productsGrid.Columns[0]; - } - public override void EndInit() - { - base.EndInit(); - } + if (Design.IsDesignMode) + { + using var context = DbContexts.GetContext(); + var book = context.GetLibraryBook_Flat_NoTracking("B017V4IM1G"); + productsGrid.DataContext = _viewModel = new ProductsDisplayViewModel(new List { book }); + } + } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); @@ -325,7 +328,8 @@ namespace LibationWinForms.AvaloniaUI.Views InitialLoaded?.Invoke(this, EventArgs.Empty); VisibleCountChanged?.Invoke(this, bindingList.BookEntries().Count()); } - UpdateGrid(dbBooks); + else + UpdateGrid(dbBooks); } catch (Exception ex) { diff --git a/Source/LibationWinForms/LibationWinForms.csproj b/Source/LibationWinForms/LibationWinForms.csproj index 579d53ad..a2854712 100644 --- a/Source/LibationWinForms/LibationWinForms.csproj +++ b/Source/LibationWinForms/LibationWinForms.csproj @@ -43,6 +43,7 @@ +