Skip to content

Commit

Permalink
improve meaning of trydeletecustomicon
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-mh committed Nov 30, 2020
1 parent cfebe62 commit b6e4f94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions AuthenticatorPro/Source/Activity/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(() =>
Expand All @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions AuthenticatorPro/Source/Data/AuthenticatorSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Authenticator> GetView()
Expand Down

0 comments on commit b6e4f94

Please sign in to comment.