diff --git a/FoliCon/Modules/ClickBehavior.cs b/FoliCon/Modules/ClickBehavior.cs new file mode 100644 index 00000000..a7a3292b --- /dev/null +++ b/FoliCon/Modules/ClickBehavior.cs @@ -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 + { + 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(); + } + } + } +} \ No newline at end of file diff --git a/FoliCon/ViewModels/PosterPickerViewModel.cs b/FoliCon/ViewModels/PosterPickerViewModel.cs index 032ff4c5..9672565d 100644 --- a/FoliCon/ViewModels/PosterPickerViewModel.cs +++ b/FoliCon/ViewModels/PosterPickerViewModel.cs @@ -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) diff --git a/FoliCon/ViewModels/ProSearchResultViewModel.cs b/FoliCon/ViewModels/ProSearchResultViewModel.cs index 890a800c..10bdbc75 100644 --- a/FoliCon/ViewModels/ProSearchResultViewModel.cs +++ b/FoliCon/ViewModels/ProSearchResultViewModel.cs @@ -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(); } @@ -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)) diff --git a/FoliCon/ViewModels/SearchResultViewModel.cs b/FoliCon/ViewModels/SearchResultViewModel.cs index 6bc5eb8b..a1cdf0ae 100644 --- a/FoliCon/ViewModels/SearchResultViewModel.cs +++ b/FoliCon/ViewModels/SearchResultViewModel.cs @@ -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 diff --git a/FoliCon/Views/PosterPicker.xaml b/FoliCon/Views/PosterPicker.xaml index 1186873f..153bb25d 100644 --- a/FoliCon/Views/PosterPicker.xaml +++ b/FoliCon/Views/PosterPicker.xaml @@ -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 }"> @@ -46,16 +48,12 @@ - - - - + + + diff --git a/FoliCon/Views/ProSearchResult.xaml b/FoliCon/Views/ProSearchResult.xaml index ff0d3a40..112d433f 100644 --- a/FoliCon/Views/ProSearchResult.xaml +++ b/FoliCon/Views/ProSearchResult.xaml @@ -69,16 +69,12 @@ - - - - + + +