Updated PictureCached event and removed dependence on WinAudibleImageServer
This commit is contained in:
parent
4989cda93c
commit
d795244247
@ -7,6 +7,11 @@ using System.Net.Http;
|
|||||||
namespace FileManager
|
namespace FileManager
|
||||||
{
|
{
|
||||||
public enum PictureSize { _80x80 = 80, _300x300 = 300, _500x500 = 500 }
|
public enum PictureSize { _80x80 = 80, _300x300 = 300, _500x500 = 500 }
|
||||||
|
public class PictureCachedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public PictureDefinition Definition { get; internal set; }
|
||||||
|
public byte[] Picture { get; internal set; }
|
||||||
|
}
|
||||||
public struct PictureDefinition
|
public struct PictureDefinition
|
||||||
{
|
{
|
||||||
public string PictureId { get; }
|
public string PictureId { get; }
|
||||||
@ -38,7 +43,7 @@ namespace FileManager
|
|||||||
timer.Elapsed += (_, __) => timerDownload();
|
timer.Elapsed += (_, __) => timerDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static event EventHandler<string> PictureCached;
|
public static event EventHandler<PictureCachedEventArgs> PictureCached;
|
||||||
|
|
||||||
private static Dictionary<PictureDefinition, byte[]> cache { get; } = new Dictionary<PictureDefinition, byte[]>();
|
private static Dictionary<PictureDefinition, byte[]> cache { get; } = new Dictionary<PictureDefinition, byte[]>();
|
||||||
public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def)
|
public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def)
|
||||||
@ -109,7 +114,7 @@ namespace FileManager
|
|||||||
saveFile(def, bytes);
|
saveFile(def, bytes);
|
||||||
cache[def] = bytes;
|
cache[def] = bytes;
|
||||||
|
|
||||||
PictureCached?.Invoke(nameof(PictureStorage), def.PictureId);
|
PictureCached?.Invoke(nameof(PictureStorage), new PictureCachedEventArgs { Definition = def, Picture = bytes });
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
@ -285,10 +285,11 @@ namespace LibationWinForms.BookLiberation
|
|||||||
decryptDialog.SetAuthorNames(string.Join(", ", libraryBook.Book.Authors));
|
decryptDialog.SetAuthorNames(string.Join(", ", libraryBook.Book.Authors));
|
||||||
decryptDialog.SetNarratorNames(string.Join(", ", libraryBook.Book.NarratorNames));
|
decryptDialog.SetNarratorNames(string.Join(", ", libraryBook.Book.NarratorNames));
|
||||||
decryptDialog.SetCoverImage(
|
decryptDialog.SetCoverImage(
|
||||||
WindowsDesktopUtilities.WinAudibleImageServer.GetImage(
|
Dinah.Core.Drawing.ImageReader.ToImage(
|
||||||
|
FileManager.PictureStorage.GetPictureSynchronously(
|
||||||
|
new FileManager.PictureDefinition(
|
||||||
libraryBook.Book.PictureId,
|
libraryBook.Book.PictureId,
|
||||||
FileManager.PictureSize._80x80
|
FileManager.PictureSize._80x80))));
|
||||||
));
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region define how model actions will affect form behavior
|
#region define how model actions will affect form behavior
|
||||||
@ -300,7 +301,12 @@ namespace LibationWinForms.BookLiberation
|
|||||||
void updateProgress(object _, int percentage) => decryptDialog.UpdateProgress(percentage);
|
void updateProgress(object _, int percentage) => decryptDialog.UpdateProgress(percentage);
|
||||||
void updateRemainingTime(object _, TimeSpan remaining) => decryptDialog.UpdateRemainingTime(remaining);
|
void updateRemainingTime(object _, TimeSpan remaining) => decryptDialog.UpdateRemainingTime(remaining);
|
||||||
void decryptCompleted(object _, string __) => decryptDialog.Close();
|
void decryptCompleted(object _, string __) => decryptDialog.Close();
|
||||||
void requestCoverArt(object _, Action<byte[]> setCoverArtDelegate) => setCoverArtDelegate(FileManager.PictureStorage.GetPictureSynchronously(new FileManager.PictureDefinition(libraryBook.Book.PictureId, FileManager.PictureSize._500x500)));
|
void requestCoverArt(object _, Action<byte[]> setCoverArtDelegate)
|
||||||
|
=> setCoverArtDelegate(
|
||||||
|
FileManager.PictureStorage.GetPictureSynchronously(
|
||||||
|
new FileManager.PictureDefinition(
|
||||||
|
libraryBook.Book.PictureId,
|
||||||
|
FileManager.PictureSize._500x500)));
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region subscribe new form to model's events
|
#region subscribe new form to model's events
|
||||||
|
|||||||
@ -28,18 +28,18 @@ namespace LibationWinForms
|
|||||||
public GridEntry(LibraryBook libraryBook)
|
public GridEntry(LibraryBook libraryBook)
|
||||||
{
|
{
|
||||||
LibraryBook = libraryBook;
|
LibraryBook = libraryBook;
|
||||||
|
|
||||||
_memberValues = CreateMemberValueDictionary();
|
_memberValues = CreateMemberValueDictionary();
|
||||||
|
|
||||||
//Get cover art. If it's default, subscribe to PictureCached
|
//Get cover art. If it's default, subscribe to PictureCached
|
||||||
var picDef = new FileManager.PictureDefinition(Book.PictureId, FileManager.PictureSize._80x80);
|
{
|
||||||
(bool isDefault, byte[] picture) = FileManager.PictureStorage.GetPicture(picDef);
|
(bool isDefault, byte[] picture) = FileManager.PictureStorage.GetPicture(new FileManager.PictureDefinition(Book.PictureId, FileManager.PictureSize._80x80));
|
||||||
|
|
||||||
if (isDefault)
|
if (isDefault)
|
||||||
FileManager.PictureStorage.PictureCached += PictureStorage_PictureCached;
|
FileManager.PictureStorage.PictureCached += PictureStorage_PictureCached;
|
||||||
|
|
||||||
//Mutable property. Set the field so PropertyChanged isn't fired.
|
//Mutable property. Set the field so PropertyChanged isn't fired.
|
||||||
_cover = ImageReader.ToImage(picture);
|
_cover = ImageReader.ToImage(picture);
|
||||||
|
}
|
||||||
|
|
||||||
//Immutable properties
|
//Immutable properties
|
||||||
{
|
{
|
||||||
@ -59,11 +59,11 @@ namespace LibationWinForms
|
|||||||
//DisplayTags and Liberate properties are live.
|
//DisplayTags and Liberate properties are live.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PictureStorage_PictureCached(object sender, string pictureId)
|
private void PictureStorage_PictureCached(object sender, FileManager.PictureCachedEventArgs e)
|
||||||
{
|
{
|
||||||
if (pictureId == Book.PictureId)
|
if (e.Definition.PictureId == Book.PictureId)
|
||||||
{
|
{
|
||||||
Cover = WindowsDesktopUtilities.WinAudibleImageServer.GetImage(pictureId, FileManager.PictureSize._80x80);
|
Cover = ImageReader.ToImage(e.Picture);
|
||||||
FileManager.PictureStorage.PictureCached -= PictureStorage_PictureCached;
|
FileManager.PictureStorage.PictureCached -= PictureStorage_PictureCached;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user