From b6e4f945670b9c10735793a29c3c4f9d8a4c5944 Mon Sep 17 00:00:00 2001 From: Jamie Hodgson Date: Mon, 30 Nov 2020 12:31:24 +0100 Subject: [PATCH] improve meaning of trydeletecustomicon --- .../Source/Activity/MainActivity.cs | 20 ++++++++++--------- .../Source/Data/AuthenticatorSource.cs | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/AuthenticatorPro/Source/Activity/MainActivity.cs b/AuthenticatorPro/Source/Activity/MainActivity.cs index 92c129e968..8e3a559144 100644 --- a/AuthenticatorPro/Source/Activity/MainActivity.cs +++ b/AuthenticatorPro/Source/Activity/MainActivity.cs @@ -560,10 +560,10 @@ private void OpenDeleteDialog(int position) builder.SetTitle(Resource.String.warning); builder.SetPositiveButton(Resource.String.delete, async delegate { - var auth = _authSource.Get(position); - await TryCleanupCustomIcon(auth.Icon); - + var icon = _authSource.Get(position).Icon; await _authSource.Delete(position); + await TryCleanupCustomIcon(icon); + _authListAdapter.NotifyItemRemoved(position); await NotifyWearAppOfChange(); @@ -1233,10 +1233,12 @@ private async void OnIconDialogIconSelected(object sender, ChangeIconBottomSheet if(auth == null) return; - await TryCleanupCustomIcon(auth.Icon); + var oldIcon = auth.Icon; auth.Icon = e.Icon; - await _connection.UpdateAsync(auth); + + await TryCleanupCustomIcon(oldIcon); + _authListAdapter.NotifyItemChanged(e.ItemPosition); await NotifyWearAppOfChange(); @@ -1278,11 +1280,11 @@ private async Task SetCustomIcon(Uri uri) if(!_customIconSource.IsDuplicate(icon.Id)) await _connection.InsertAsync(icon); - - await TryCleanupCustomIcon(auth.Icon); - + + var oldIcon = auth.Icon; auth.Icon = CustomIcon.Prefix + icon.Id; await _connection.UpdateAsync(auth); + await TryCleanupCustomIcon(oldIcon); await _customIconSource.Update(); RunOnUiThread(() => @@ -1299,7 +1301,7 @@ private async Task TryCleanupCustomIcon(string icon) { var id = icon.Substring(1); - if(_authSource.CountUsesOfCustomIcon(id) == 1) + if(!_authSource.IsCustomIconInUse(id)) await _customIconSource.Delete(id); } } diff --git a/AuthenticatorPro/Source/Data/AuthenticatorSource.cs b/AuthenticatorPro/Source/Data/AuthenticatorSource.cs index 440e1131e7..8480cffc55 100644 --- a/AuthenticatorPro/Source/Data/AuthenticatorSource.cs +++ b/AuthenticatorPro/Source/Data/AuthenticatorSource.cs @@ -233,9 +233,9 @@ await _connection.ExecuteAsync( CategoryBindings.Remove(binding); } - public int CountUsesOfCustomIcon(string id) + public bool IsCustomIconInUse(string id) { - return _all.Count(a => a.Icon == CustomIcon.Prefix + id); + return _all.Any(a => a.Icon == CustomIcon.Prefix + id); } public List GetView()