diff --git a/Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png b/Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png new file mode 100644 index 00000000..12e70d0f Binary files /dev/null and b/Source/LibationWinForms/AvaloniaUI/Assets/edit_25x25.png differ diff --git a/Source/LibationWinForms/AvaloniaUI/ViewModels/BookTags.cs b/Source/LibationWinForms/AvaloniaUI/ViewModels/BookTags.cs index 33d89e2d..ab9717d4 100644 --- a/Source/LibationWinForms/AvaloniaUI/ViewModels/BookTags.cs +++ b/Source/LibationWinForms/AvaloniaUI/ViewModels/BookTags.cs @@ -1,52 +1,9 @@ -using Avalonia.Controls; -using Avalonia.Media.Imaging; -using System; -using System.ComponentModel; - -namespace LibationWinForms.AvaloniaUI.ViewModels +namespace LibationWinForms.AvaloniaUI.ViewModels { public class BookTags { - private static Bitmap _buttonImage; - - static BookTags() - { - var memoryStream = new System.IO.MemoryStream(); - - Properties.Resources.edit_25x25.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); - memoryStream.Position = 0; - _buttonImage = new Bitmap(memoryStream); - - } - public string Tags { get; init; } public bool IsSeries { get; init; } - - public Control Control - { - get - { - if (IsSeries) - return null; - - if (string.IsNullOrEmpty(Tags)) - { - return new Image - { - Stretch = Avalonia.Media.Stretch.None, - Source = _buttonImage - }; - } - else - { - return new TextBlock - { - Text = Tags, - Margin = new Avalonia.Thickness(0, 0), - TextWrapping = Avalonia.Media.TextWrapping.WrapWithOverflow - }; - } - } - } + public bool HasTags => !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 @@ +