Skip to content

Commit

Permalink
Professional mode count fixed,
Browse files Browse the repository at this point in the history
Crash on searching again if pickedById fixed.
Click issue fixed for poster screens.
  • Loading branch information
DineshSolanki committed Aug 7, 2021
1 parent 8991a0e commit a04fd21
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 25 deletions.
83 changes: 83 additions & 0 deletions FoliCon/Modules/ClickBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Microsoft.Xaml.Behaviors;
using Prism.Commands;

namespace FoliCon.Modules
{
public class ClickBehavior : Behavior<Image>
{
private readonly DispatcherTimer _timer = new();

public ClickBehavior()
{
_timer.Interval = TimeSpan.FromSeconds(0.2);
_timer.Tick += Timer_Tick;
}

public static readonly DependencyProperty ClickCommandProperty =
DependencyProperty.Register(nameof(ClickCommand), typeof(ICommand), typeof(ClickBehavior));
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(ClickBehavior));
public Object CommandParameter
{
get => GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
public ICommand ClickCommand
{
get => (ICommand)GetValue(ClickCommandProperty);
set => SetValue(ClickCommandProperty, value);
}

public static readonly DependencyProperty DoubleClickCommandProperty =
DependencyProperty.Register(nameof(DoubleClickCommand), typeof(ICommand), typeof(ClickBehavior));

public ICommand DoubleClickCommand
{
get => (ICommand)GetValue(DoubleClickCommandProperty);
set => SetValue(DoubleClickCommandProperty, value);
}

protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.Loaded += AssociatedObject_Loaded;
AssociatedObject.Unloaded += AssociatedObject_Unloaded;
}

private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
{
AssociatedObject.Loaded -= AssociatedObject_Loaded;
AssociatedObject.PreviewMouseLeftButtonDown += AssociatedObject_PreviewMouseLeftButtonDown;
}

private void AssociatedObject_Unloaded(object sender, RoutedEventArgs e)
{
AssociatedObject.Unloaded -= AssociatedObject_Unloaded;
AssociatedObject.PreviewMouseLeftButtonDown -= AssociatedObject_PreviewMouseLeftButtonDown;
}

private void Timer_Tick(object sender, EventArgs e)
{
_timer.Stop();
ClickCommand?.Execute(CommandParameter);
}

private void AssociatedObject_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
_timer.Stop();
DoubleClickCommand?.Execute(CommandParameter);
}
else
{
_timer.Start();
}
}
}
}
7 changes: 5 additions & 2 deletions FoliCon/ViewModels/PosterPickerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ public PosterPickerViewModel()
private void OpenImageMethod(object parameter)
{
var link = (string)parameter;
new ImageBrowser(Result.MediaType == MediaTypes.Game
var browser = new ImageBrowser(Result.MediaType == MediaTypes.Game
? $"https://{ImageHelper.GetImageUrl(link, ImageSize.HD720)[2..]}"
: link).Show();
: link);
browser.ShowTitle = false;
browser.IsFullScreen = true;
browser.Show();
}

protected virtual void CloseDialog(string parameter)
Expand Down
8 changes: 5 additions & 3 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ public ProSearchResultViewModel()
private void OpenImageMethod(object parameter)
{
var link = (string)parameter;
var browser = new ImageBrowser(link);
browser.IsFullScreen = true;
var browser = new ImageBrowser(link)
{
ShowTitle = false,
IsFullScreen = true
};
browser.Show();
}

Expand Down Expand Up @@ -113,7 +116,6 @@ private async Task Search(string query, int offset = 0)
TotalPosters = searchResult.Results.Count( result => result.IsDownloadable) + offset;
foreach (var item in searchResult.Results.GetEnumeratorWithIndex())
{
Index += lastIndex;
if (!item.Value.IsDownloadable)
continue;
using (var bm = await Util.GetBitmapFromUrlAsync(item.Value.Thumbs[0].Src))
Expand Down
1 change: 1 addition & 0 deletions FoliCon/ViewModels/SearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private async void StartSearch(bool useBusy)
IsBusy = true;
}

_isPickedById = false;
var titleToSearch = SearchAgainTitle ?? SearchTitle;
BusyContent = LangProvider.GetLang("SearchingWithName").Format(titleToSearch);
var result = SearchMode == MediaTypes.Game
Expand Down
18 changes: 8 additions & 10 deletions FoliCon/Views/PosterPicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:langs="clr-namespace:FoliCon.Properties.Langs"
xmlns:langExtension="clr-namespace:FoliCon.Modules.LangExtension"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:modules="clr-namespace:FoliCon.Modules"
mc:Ignorable="d"
prism:ViewModelLocator.AutoWireViewModel="True"
d:DataContext="{d:DesignInstance viewModels:PosterPickerViewModel }">
Expand Down Expand Up @@ -46,16 +48,12 @@
<DataTemplate>
<Image Source="{Binding Image}" Tag="{Binding Url}" Height="128" Width="128"
RenderOptions.BitmapScalingMode="HighQuality" Margin="5, 5, 5, 5">
<Image.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:PosterPickerViewModel.PickCommand)}"
CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" />
<MouseBinding MouseAction="LeftClick"
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:PosterPickerViewModel.OpenImageCommand)}"
CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" />
</Image.InputBindings>
<b:Interaction.Behaviors>
<modules:ClickBehavior CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" DoubleClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:PosterPickerViewModel.PickCommand)}"
ClickCommand="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:PosterPickerViewModel.OpenImageCommand)}"/>
</b:Interaction.Behaviors>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
16 changes: 6 additions & 10 deletions FoliCon/Views/ProSearchResult.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@
<DataTemplate>
<Image Source="{Binding Image}" Tag="{Binding Url}" Height="128" Width="128"
RenderOptions.BitmapScalingMode="HighQuality" Margin="5, 5, 5, 5">
<Image.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.PickCommand)}"
CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" />
<MouseBinding MouseAction="LeftClick"
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.(viewModels:ProSearchResultViewModel.OpenImageCommand)}"
CommandParameter="{Binding Path=Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Image}}}" />
</Image.InputBindings>
<i:Interaction.Behaviors>
<modules: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)}"/>
</i:Interaction.Behaviors>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down

0 comments on commit a04fd21

Please sign in to comment.