Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions FoliCon/Models/Api/DArtBrowseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public class Author
public string Type { get; set; }
}

public class PremiumFolderData
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("has_access")]
public bool HasAccess { get; set; }

[JsonProperty("gallery_id")]
public string GalleryId { get; set; }
}

public class Stats
{
[JsonProperty("comments")]
Expand Down Expand Up @@ -108,6 +120,9 @@ public class Result

[JsonProperty("thumbs")]
public Thumb[] Thumbs { get; set; }

[JsonProperty("premium_folder_data")]
public PremiumFolderData PremiumFolderData { get; set; }
}

public class DArtBrowseResult
Expand Down
5 changes: 4 additions & 1 deletion FoliCon/Models/Data/DArtImageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ public class DArtImageList : BindableBase
private string _url;
private string _thumbnailUrl;
private string _deviationId;
private bool _mustWatch;

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

public DArtImageList(string url, string thumbnailUrl, string deviationId) : this(url, thumbnailUrl)
public DArtImageList(string url, string thumbnailUrl, string deviationId, bool mustWatch=false) : this(url, thumbnailUrl)
{
DeviationId = deviationId ?? throw new ArgumentNullException(nameof(deviationId));
MustWatch = mustWatch;
}

public string Url { get => _url; set => SetProperty(ref _url, value); }
public string ThumbnailUrl { get => _thumbnailUrl; set => SetProperty(ref _thumbnailUrl, value); }
public string DeviationId { get => _deviationId; set => SetProperty(ref _deviationId, value); }
public bool MustWatch { get => _mustWatch; set => SetProperty(ref _mustWatch, value); }
}
63 changes: 47 additions & 16 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public bool SubfolderProcessingEnabled
}

public DelegateCommand SkipCommand { get; set; }
public DelegateCommand<object> PickCommand { get; set; }
public DelegateCommand<object> OpenImageCommand { get; set; }
public DelegateCommand<DArtImageList> PickCommand { get; set; }
public DelegateCommand<DArtImageList> OpenImageCommand { get; set; }
public DelegateCommand<object> ExtractManuallyCommand { get; set; }
public DelegateCommand SearchAgainCommand { get; set; }
public DelegateCommand StopSearchCommand { get; set; }
Expand All @@ -77,14 +77,26 @@ public ProSearchResultViewModel(IDialogService dialogService)
Logger.Debug("ProSearchResultViewModel Constructor");
ImageUrl = [];
StopSearchCommand = new DelegateCommand(delegate { StopSearch = true; });
PickCommand = new DelegateCommand<object>(PickMethod);
OpenImageCommand = new DelegateCommand<object>(link=> UiUtils.ShowImageBrowser(link as string));
PickCommand = new DelegateCommand<DArtImageList>(PickMethod);
OpenImageCommand = new DelegateCommand<DArtImageList>(OpenImageMethod);
ExtractManuallyCommand = new DelegateCommand<object>(ExtractManually);
SkipCommand = new DelegateCommand(SkipMethod);
SearchAgainCommand = new DelegateCommand(PrepareForSearch);
_dialogService = dialogService;
}

private void OpenImageMethod(DArtImageList parameter)
{
Logger.Debug("Opening Image {Image}", parameter);
if (parameter.MustWatch)
{
//TODO:watch
parameter.MustWatch = false;
}
var link = parameter.Url;
UiUtils.ShowImageBrowser(link);
}

private void ExtractManually(object parameter)
{
Logger.Debug("Extracting manually from Deviation ID {DeviationId}", parameter);
Expand Down Expand Up @@ -194,16 +206,19 @@ private int ProcessSearchResults(string query, DArtBrowseResult searchResult, in
private void ProcessResultItems(EnumeratorWithIndex<Result> item)
{
Logger.Trace("Deviation {Index} is {@Item}", item.Index, item.Value);

if (IsItemDownloadable(item))
var mustWatch = false;
if (!IsItemDownloadable(item))
{
ImageUrl.Add(new DArtImageList(item.Value.Content.Src, item.Value.Thumbs[0].Src, item.Value.Deviationid));
Index++;
}
else
{
Logger.Warn("Poster {Index} is not downloadable", item.Value.Url);
if (item.Value.PremiumFolderData is null || item.Value.PremiumFolderData.Type != "watchers")
{
Logger.Warn("Poster {URL} is not downloadable", item.Value.Url);
return;
}
mustWatch = true;
Logger.Warn("Poster {URL} is not downloadable, but can be watched to download", item.Value.Url);
}
ImageUrl.Add(new DArtImageList(item.Value.Content.Src, item.Value.Thumbs[0].Src, item.Value.Deviationid, mustWatch));
Index++;
}

private static bool IsItemDownloadable(EnumeratorWithIndex<Result> item)
Expand All @@ -212,15 +227,31 @@ private static bool IsItemDownloadable(EnumeratorWithIndex<Result> item)
}


private void PickMethod(object parameter)
private void PickMethod(DArtImageList parameter)
{
if (parameter.MustWatch)
{
//TODO:Watch
parameter.MustWatch = false;
}
var link = parameter.Url;
ProcessPick(link);
}

private void PickMethod(string link)
{
ProcessPick(link);
}

private void ProcessPick(string link)
{
Logger.Debug("Picking Image {Image}", parameter);
Logger.Debug("Picking Image {Image}", link);
var extension = Path.GetExtension(new Uri(link).LocalPath) == ".ico" ? ".ico" : ".png";
SearchAgainTitle = null;
var link = (string)parameter;
var currentPath = $@"{_folderPath}\{Fnames[_i]}";
var tempImage = new ImageToDownload
{
LocalPath = $@"{currentPath}\{IconUtils.GetImageName()}.png",
LocalPath = $@"{currentPath}\{IconUtils.GetImageName()}{extension}",
RemotePath = new Uri(link)
};
Logger.Debug("Adding Image to Download List {@Image}", tempImage);
Expand Down
2 changes: 1 addition & 1 deletion FoliCon/Views/ProSearchResult.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<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,
<ui:ClickBehavior CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" DoubleClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.PickCommand)}"
ClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.OpenImageCommand)}"/>
Expand Down
Loading