Minor refactoring.

This commit is contained in:
Michael Bucari-Tovo 2021-08-12 10:39:55 -06:00
parent 65027fd001
commit 56a48c04bf
7 changed files with 27 additions and 45 deletions

View file

@ -40,9 +40,9 @@ namespace LibationWinForms.BookLiberation
private void OnUnsubscribeAll(object sender, EventArgs e)
{
Disposed -= OnUnsubscribeAll;
if (Streamable is IAudioDecodable audioDecodable)
{
Disposed -= OnUnsubscribeAll;
audioDecodable.RequestCoverArt -= OnRequestCoverArt;
audioDecodable.TitleDiscovered -= OnTitleDiscovered;
audioDecodable.AuthorsDiscovered -= OnAuthorsDiscovered;
@ -62,10 +62,10 @@ namespace LibationWinForms.BookLiberation
FileManager.PictureSize._500x500));
//Set default values from library
OnTitleDiscovered(null, libraryBook.Book.Title);
OnAuthorsDiscovered(null, string.Join(", ", libraryBook.Book.Authors));
OnNarratorsDiscovered(null, string.Join(", ", libraryBook.Book.NarratorNames));
OnCoverImageDiscovered(null,
OnTitleDiscovered(sender, libraryBook.Book.Title);
OnAuthorsDiscovered(sender, string.Join(", ", libraryBook.Book.Authors));
OnNarratorsDiscovered(sender, string.Join(", ", libraryBook.Book.NarratorNames));
OnCoverImageDiscovered(sender,
FileManager.PictureStorage.GetPicture(
new FileManager.PictureDefinition(
libraryBook.Book.PictureId,
@ -74,7 +74,6 @@ namespace LibationWinForms.BookLiberation
#endregion
#region IStreamable event handler overrides
public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress)
{
if (!downloadProgress.ProgressPercentage.HasValue)
@ -88,11 +87,9 @@ namespace LibationWinForms.BookLiberation
public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining)
=> updateRemainingTime((int)timeRemaining.TotalSeconds);
#endregion
#region IAudioDecodable event handlers
public virtual void OnRequestCoverArt(object sender, Action<byte[]> setCoverArtDelegate)
=> setCoverArtDelegate(GetCoverArtDelegate?.Invoke());
@ -117,16 +114,13 @@ namespace LibationWinForms.BookLiberation
public virtual void OnCoverImageDiscovered(object sender, byte[] coverArt)
=> pictureBox1.UIThread(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt));
#endregion
// thread-safe UI updates
private void updateBookInfo()
=> bookInfoLbl.UIThread(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}");
private void updateRemainingTime(int remaining)
=> remainingTimeLbl.UIThread(() => remainingTimeLbl.Text = $"ETA:\r\n{remaining} sec");
}
}

View file

@ -22,7 +22,7 @@ namespace LibationWinForms.BookLiberation
//Don't unsubscribe from Dispose because it fires on
//IStreamable.StreamingCompleted, and the IProcessable
//events need to live past that.
//events need to live past that event.
processable.Completed += OnUnsubscribeAll;
}
}
@ -42,7 +42,6 @@ namespace LibationWinForms.BookLiberation
public virtual void OnBegin(object sender, LibraryBook libraryBook) => LogMe.Info($"Begin: {libraryBook.Book}");
public virtual void OnStatusUpdate(object sender, string statusUpdate) => LogMe.Info("- " + statusUpdate);
public virtual void OnCompleted(object sender, LibraryBook libraryBook) => LogMe.Info($"Completed: {libraryBook.Book}{Environment.NewLine}");
#endregion
}
}