From c6a2708ac51b66ec166b0e5602e72086bd244fb4 Mon Sep 17 00:00:00 2001 From: Pavel Leonenko <1992leon@bk.ru> Date: Fri, 31 May 2024 14:42:51 +0200 Subject: [PATCH 1/2] Added possibility to call ReloadMapping from inheritants (#551) Co-authored-by: Pavel Leonenko --- .../Bindable/BindableRecyclerViewAdapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Softeq.XToolkit.Bindings.Droid/Bindable/BindableRecyclerViewAdapter.cs b/Softeq.XToolkit.Bindings.Droid/Bindable/BindableRecyclerViewAdapter.cs index 5e3a0703f..768bd2510 100644 --- a/Softeq.XToolkit.Bindings.Droid/Bindable/BindableRecyclerViewAdapter.cs +++ b/Softeq.XToolkit.Bindings.Droid/Bindable/BindableRecyclerViewAdapter.cs @@ -397,7 +397,7 @@ protected override void Dispose(bool disposing) _subscription?.Dispose(); } - private void ReloadMapping() + protected void ReloadMapping() { _flatMapping.Clear(); From ef82b6dbc4eaca27201c256781bc862ac97e314e Mon Sep 17 00:00:00 2001 From: Pavel Leonenko <1992leon@bk.ru> Date: Fri, 21 Jun 2024 10:18:45 +0200 Subject: [PATCH 2/2] Removed excess finalizers (according to https://vkontech.com/the-dispose-pattern-step-by-step/). Fixed IAsyncCommand interface (#552) Co-authored-by: Pavel Leonenko --- .../Commands/IAsyncCommand.cs | 2 +- .../ConnectivityService.cs | 18 ++------------- .../DroidPushNotificationsConsumer.cs | 22 ++++--------------- .../ImagePicker/ImagePickerResult.cs | 16 +------------- 4 files changed, 8 insertions(+), 50 deletions(-) diff --git a/Softeq.XToolkit.Common/Commands/IAsyncCommand.cs b/Softeq.XToolkit.Common/Commands/IAsyncCommand.cs index 7a79fe9ad..d96b59ad0 100644 --- a/Softeq.XToolkit.Common/Commands/IAsyncCommand.cs +++ b/Softeq.XToolkit.Common/Commands/IAsyncCommand.cs @@ -19,7 +19,7 @@ public interface IAsyncCommand : ICommand /// If the command does not require data to be passed, this object can be set to null. /// /// The Task to execute. - Task ExecuteAsync(object parameter); + Task ExecuteAsync(object? parameter); } /// diff --git a/Softeq.XToolkit.Connectivity/ConnectivityService.cs b/Softeq.XToolkit.Connectivity/ConnectivityService.cs index b9fdfbbd1..40ccd943d 100644 --- a/Softeq.XToolkit.Connectivity/ConnectivityService.cs +++ b/Softeq.XToolkit.Connectivity/ConnectivityService.cs @@ -19,11 +19,6 @@ public ConnectivityService() CrossConnectivity.Current.ConnectivityTypeChanged += CurrentConnectivityTypeChanged; } - ~ConnectivityService() - { - Dispose(false); - } - public virtual bool IsConnected => CrossConnectivity.Current.IsConnected; public bool IsSupported => CrossConnectivity.IsSupported; @@ -32,17 +27,8 @@ public ConnectivityService() public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected void Dispose(bool disposing) - { - if (disposing) - { - CrossConnectivity.Current.ConnectivityChanged -= CurrentConnectivityChanged; - CrossConnectivity.Current.ConnectivityTypeChanged -= CurrentConnectivityTypeChanged; - } + CrossConnectivity.Current.ConnectivityChanged -= CurrentConnectivityChanged; + CrossConnectivity.Current.ConnectivityTypeChanged -= CurrentConnectivityTypeChanged; } private void CurrentConnectivityChanged(object sender, ConnectivityChangedEventArgs e) diff --git a/Softeq.XToolkit.PushNotifications.Droid/Services/DroidPushNotificationsConsumer.cs b/Softeq.XToolkit.PushNotifications.Droid/Services/DroidPushNotificationsConsumer.cs index ff74f07e1..6bb9ea248 100644 --- a/Softeq.XToolkit.PushNotifications.Droid/Services/DroidPushNotificationsConsumer.cs +++ b/Softeq.XToolkit.PushNotifications.Droid/Services/DroidPushNotificationsConsumer.cs @@ -54,11 +54,6 @@ public DroidPushNotificationsConsumer( }); } - ~DroidPushNotificationsConsumer() - { - Dispose(false); - } - /// public bool TryHandleNotification(RemoteMessage message) { @@ -101,8 +96,10 @@ public Task OnUnregisterFromPushNotifications() public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); + Execute.BeginOnUIThread(() => + { + ProcessLifecycleOwner.Get().Lifecycle.RemoveObserver(_lifecycleObserver); + }); } private void OnMessageReceivedInternal(PushNotificationModel parsedNotification, bool inForeground) @@ -116,16 +113,5 @@ private void OnMessageReceivedInternal(PushNotificationModel parsedNotification, _pushNotificationsHandler.HandlePushNotificationReceived(parsedNotification, inForeground); } } - - private void Dispose(bool isDisposing) - { - if (isDisposing) - { - Execute.BeginOnUIThread(() => - { - ProcessLifecycleOwner.Get().Lifecycle.RemoveObserver(_lifecycleObserver); - }); - } - } } } diff --git a/Softeq.XToolkit.WhiteLabel.Essentials/ImagePicker/ImagePickerResult.cs b/Softeq.XToolkit.WhiteLabel.Essentials/ImagePicker/ImagePickerResult.cs index 8fe113a84..3d6ddcf0f 100644 --- a/Softeq.XToolkit.WhiteLabel.Essentials/ImagePicker/ImagePickerResult.cs +++ b/Softeq.XToolkit.WhiteLabel.Essentials/ImagePicker/ImagePickerResult.cs @@ -49,21 +49,7 @@ public string? Extension public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); - } - - ~ImagePickerResult() - { - Dispose(false); - } - - protected void Dispose(bool disposing) - { - if (disposing) - { - ImageObject?.Dispose(); - } + ImageObject?.Dispose(); } ///