Skip to content

Commit

Permalink
Fix Game artworks not loading and refactor professional mode and post…
Browse files Browse the repository at this point in the history
…er mode image loading by replacing bitmap loading with direct thumbnail url
  • Loading branch information
DineshSolanki committed Jul 24, 2024
1 parent 8884356 commit 33a0544
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
10 changes: 5 additions & 5 deletions FoliCon/Models/Data/DArtImageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
public class DArtImageList : BindableBase
{
private string _url;
private BitmapSource _image;
private string _thumbnailUrl;
private string _deviationId;

public DArtImageList(string url, BitmapSource bmp)
public DArtImageList(string url, string thumbnailUrl)
{
Url = url ?? throw new ArgumentNullException(nameof(url));
Image = bmp ?? throw new ArgumentNullException(nameof(bmp));
ThumbnailUrl = thumbnailUrl ?? throw new ArgumentNullException(nameof(thumbnailUrl));
}

public DArtImageList(string url, BitmapSource bmp, string deviationId) : this(url, bmp)
public DArtImageList(string url, string thumbnailUrl, string deviationId) : this(url, thumbnailUrl)
{
DeviationId = deviationId ?? throw new ArgumentNullException(nameof(deviationId));
}

public string Url { get => _url; set => SetProperty(ref _url, value); }
public BitmapSource Image { get => _image; set => SetProperty(ref _image, value); }
public string ThumbnailUrl { get => _thumbnailUrl; set => SetProperty(ref _thumbnailUrl, value); }
public string DeviationId { get => _deviationId; set => SetProperty(ref _deviationId, value); }
}
12 changes: 4 additions & 8 deletions FoliCon/ViewModels/PosterPickerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ private async void LoadImages(ImagesWithId images)

continue;
}
var bm = await response.GetBitmap();
ImageUrl.Add(new DArtImageList(qualityPath, ImageUtils.LoadBitmap(bm)));
bm.Dispose();
ImageUrl.Add(new DArtImageList(qualityPath, posterPath));
}

if (!_stopSearch) continue;
Expand Down Expand Up @@ -240,9 +238,7 @@ private async void LoadImages(Artwork[] images)
.Property("Response", response).Log();
continue;
}
var bm = await response.GetBitmap();
ImageUrl.Add(new DArtImageList(image.ImageId, ImageUtils.LoadBitmap(bm)));
bm.Dispose();
ImageUrl.Add(new DArtImageList(posterPath, posterPath, image.ImageId));
}

if (!_stopSearch) continue;
Expand All @@ -268,8 +264,8 @@ private void PickMethod(DArtImageList pickedImage)
_resultList[PickedIndex].SetInitialPoster();
if (Result.MediaType == MediaTypes.Game)
{
result.Cover.Value.ImageId = link;
_resultList[PickedIndex].Poster = "https://" + ImageHelper.GetImageUrl(link, ImageSize.HD720)[2..];
result.Cover.Value.ImageId = pickedImage.DeviationId;
_resultList[PickedIndex].Poster = "https://" + ImageHelper.GetImageUrl(pickedImage.DeviationId, ImageSize.HD720)[2..];
Logger.Trace("Poster Path: {PosterPath}", _resultList[PickedIndex].Poster);
}
else
Expand Down
13 changes: 2 additions & 11 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,8 @@ private async Task Search(string query, int offset = 0)
Logger.Warn("Poster {Index} is not downloadable", item.Value.Url);
continue;
}
var response = await Services.HttpC.GetAsync(item.Value.Thumbs[0].Src);
if (response.StatusCode != HttpStatusCode.OK)
{
Logger.ForErrorEvent().Message("Could not download image {Image}", item.Value.Thumbs[0].Src)
.Property("Response", response).Log();
continue;
}
using (var bm = await response.GetBitmap())
{
ImageUrl.Add(new DArtImageList(item.Value.Content.Src, ImageUtils.LoadBitmap(bm), item.Value.Deviationid));
}

ImageUrl.Add(new DArtImageList(item.Value.Content.Src, item.Value.Thumbs[0].Src, item.Value.Deviationid));
if (_stopSearch)
{
Logger.Debug("Search Stopped by user at {Index}", Index);
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Views/ProSearchResult.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<ItemsControl ItemsSource="{Binding ImageUrl}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Image}" Tag="{Binding }" Height="128" Width="128"
<Image Source="{Binding ThumbnailUrl}" Tag="{Binding }" Height="128" Width="128"
RenderOptions.BitmapScalingMode="HighQuality" Margin="5, 5, 5, 5">
<i:Interaction.Behaviors>
<ui:ClickBehavior CommandParameter="{Binding Path=Tag.Url, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" DoubleClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
Expand Down

0 comments on commit 33a0544

Please sign in to comment.