From 710d8e1d6c97c6181690bc8edac9f550cd797557 Mon Sep 17 00:00:00 2001 From: Vladislav Antonyuk Date: Sun, 20 Aug 2023 22:03:55 +0300 Subject: [PATCH 1/2] Fixes #353, #354 --- MauiMaps/MainPage.xaml | 3 +- .../Android/CustomInfoWindowClickListener.cs | 4 +-- .../Platforms/Android/CustomMapHandler.cs | 8 ++--- .../Android/CustomMarkerClickListener.cs | 4 +-- MauiMarkdown/MauiMarkdown.csproj | 2 +- MauiPaint/Platforms/Windows/DragDropHelper.cs | 31 ++++++++++++++++--- md/thankyou.mdpp | 2 +- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/MauiMaps/MainPage.xaml b/MauiMaps/MainPage.xaml index cf4021c9..0f1d69a8 100644 --- a/MauiMaps/MainPage.xaml +++ b/MauiMaps/MainPage.xaml @@ -5,7 +5,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:mauiMaps="clr-namespace:MauiMaps" xmlns:models="clr-namespace:MauiMaps.Models" - x:DataType="mauiMaps:MainPageViewModel"> + x:DataType="mauiMaps:MainPageViewModel" + Shell.NavBarIsVisible="False"> x.Value.Id == marker.Id); - pin.Key?.SendInfoWindowClick(); + var pin = mapHandler.Markers.FirstOrDefault(x => x.marker.Id == marker.Id); + pin.pin?.SendInfoWindowClick(); } } \ No newline at end of file diff --git a/MauiMaps/Platforms/Android/CustomMapHandler.cs b/MauiMaps/Platforms/Android/CustomMapHandler.cs index a91713f9..cb5b961c 100644 --- a/MauiMaps/Platforms/Android/CustomMapHandler.cs +++ b/MauiMaps/Platforms/Android/CustomMapHandler.cs @@ -25,7 +25,7 @@ public CustomMapHandler(IPropertyMapper? mapper = null, CommandMapper? commandMa { } - public Dictionary Markers { get; } = new(); + public List<(IMapPin pin, Marker marker)> Markers { get; } = new(); protected override void ConnectHandler(MapView platformView) { @@ -40,7 +40,7 @@ protected override void ConnectHandler(MapView platformView) { foreach (var marker in mapHandler.Markers) { - marker.Value.Remove(); + marker.marker.Remove(); } mapHandler.Markers.Clear(); @@ -65,7 +65,7 @@ private void AddPins(IEnumerable mapPins) { cp.ImageSource.LoadImage(MauiContext, result => { - if (result?.Value is BitmapDrawable bitmapDrawable && bitmapDrawable.Bitmap is not null) + if (result?.Value is BitmapDrawable { Bitmap: not null } bitmapDrawable) { markerOption.SetIcon(BitmapDescriptorFactory.FromBitmap(GetMaximumBitmap(bitmapDrawable.Bitmap, 100, 100))); } @@ -85,7 +85,7 @@ private void AddMarker(GoogleMap map, IMapPin pin, MarkerOptions markerOption) { var marker = map.AddMarker(markerOption); pin.MarkerId = marker.Id; - Markers.Add(pin, marker); + Markers.Add((pin, marker)); } private static Bitmap GetMaximumBitmap(in Bitmap sourceImage, in float maxWidth, in float maxHeight) diff --git a/MauiMaps/Platforms/Android/CustomMarkerClickListener.cs b/MauiMaps/Platforms/Android/CustomMarkerClickListener.cs index 08943383..93ba7ea5 100644 --- a/MauiMaps/Platforms/Android/CustomMarkerClickListener.cs +++ b/MauiMaps/Platforms/Android/CustomMarkerClickListener.cs @@ -13,8 +13,8 @@ public CustomMarkerClickListener(CustomMapHandler mapHandler) public bool OnMarkerClick(Android.Gms.Maps.Model.Marker marker) { - var pin = mapHandler.Markers.FirstOrDefault(x => x.Value.Id == marker.Id); - pin.Key?.SendMarkerClick(); + var pin = mapHandler.Markers.FirstOrDefault(x => x.marker.Id == marker.Id); + pin.pin?.SendMarkerClick(); marker.ShowInfoWindow(); return true; } diff --git a/MauiMarkdown/MauiMarkdown.csproj b/MauiMarkdown/MauiMarkdown.csproj index 32a653f0..79660227 100644 --- a/MauiMarkdown/MauiMarkdown.csproj +++ b/MauiMarkdown/MauiMarkdown.csproj @@ -32,7 +32,7 @@ - + diff --git a/MauiPaint/Platforms/Windows/DragDropHelper.cs b/MauiPaint/Platforms/Windows/DragDropHelper.cs index 047b67f6..701f91a6 100644 --- a/MauiPaint/Platforms/Windows/DragDropHelper.cs +++ b/MauiPaint/Platforms/Windows/DragDropHelper.cs @@ -9,14 +9,18 @@ namespace MauiPaint; using System.Diagnostics; using System.Text; using Windows.Foundation; -using Windows.Storage.Streams; +using DragStartingEventArgs = Microsoft.UI.Xaml.DragStartingEventArgs; public static class DragDropHelper { + private static readonly Dictionary> DragStartingEventHandlers = new(); + private static readonly Dictionary DragEventHandlers = new(); + public static void RegisterDrag(UIElement element, Func> content) { element.CanDrag = true; - element.DragStarting += async (s, e) => + + async void DragStartingHandler(UIElement s, DragStartingEventArgs e) { var stream = await content.Invoke(CancellationToken.None); var storageFile = await CreateStorageFile(stream); @@ -24,13 +28,16 @@ public static void RegisterDrag(UIElement element, Func? content) { element.AllowDrop = true; - element.Drop += async (s, e) => + async void DropHandler(object s, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { @@ -48,18 +55,32 @@ public static void RegisterDrop(UIElement element, Func? content) } } } - }; + } + + element.Drop += DropHandler; + DragEventHandlers[element] = DropHandler; element.DragOver += OnDragOver; } public static void UnRegisterDrag(UIElement element) { element.CanDrag = false; + if (DragStartingEventHandlers.TryGetValue(element, out var dragStartingEventHandler)) + { + element.DragStarting -= dragStartingEventHandler; + DragStartingEventHandlers.Remove(element); + } } public static void UnRegisterDrop(UIElement element) { element.AllowDrop = false; + if (DragEventHandlers.TryGetValue(element, out var dragEventHandler)) + { + element.Drop -= dragEventHandler; + DragEventHandlers.Remove(element); + } + element.DragOver -= OnDragOver; } diff --git a/md/thankyou.mdpp b/md/thankyou.mdpp index 911202a8..d2c4fb54 100644 --- a/md/thankyou.mdpp +++ b/md/thankyou.mdpp @@ -1,3 +1,3 @@ ## Thank You -Special thanks to my friends and sponsors: @PeterFucci, Gerald Versluis (jfversluis), @renatolopes, Glen Herman, Olexii, Brady, Yury Michurin, VToegel, Aleksander Rokic, Jeffrey Williams, TimKyn. \ No newline at end of file +Special thanks to my friends and sponsors: @PeterFucci, Gerald Versluis (jfversluis), @renatolopes, Glen Herman, Olexii, Brady, Yury Michurin, VToegel, Aleksander Rokic, Jeffrey Williams, TimKyn, Standa Mikeš, Aaron Schaefer. \ No newline at end of file From 38bce267d1b2e13e8866f3929e310dac657df7f0 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 20 Aug 2023 19:05:08 +0000 Subject: [PATCH 2/2] style: format code with dotnet-format Format code with dotnet-format This commit fixes the style issues introduced in 710d8e1 according to the output from dotnet-format. Details: None --- MauiPaint/Platforms/Windows/DragDropHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MauiPaint/Platforms/Windows/DragDropHelper.cs b/MauiPaint/Platforms/Windows/DragDropHelper.cs index 701f91a6..164dba22 100644 --- a/MauiPaint/Platforms/Windows/DragDropHelper.cs +++ b/MauiPaint/Platforms/Windows/DragDropHelper.cs @@ -80,7 +80,7 @@ public static void UnRegisterDrop(UIElement element) element.Drop -= dragEventHandler; DragEventHandlers.Remove(element); } - + element.DragOver -= OnDragOver; }