diff --git a/src/App/Pages/Send/SendGroupingsPage/SendGroupingsPageViewModel.cs b/src/App/Pages/Send/SendGroupingsPage/SendGroupingsPageViewModel.cs index 66f207211..4c7e70c37 100644 --- a/src/App/Pages/Send/SendGroupingsPage/SendGroupingsPageViewModel.cs +++ b/src/App/Pages/Send/SendGroupingsPage/SendGroupingsPageViewModel.cs @@ -178,7 +178,9 @@ namespace Bit.App.Pages } // TODO: refactor this - if (Device.RuntimePlatform == Device.Android) + if (Device.RuntimePlatform == Device.Android + || + GroupedSends.Any()) { var items = new List(); foreach (var itemGroup in groupedSends) @@ -191,16 +193,30 @@ namespace Bit.App.Pages } else { - // HACK: This waitings are to avoid crash on iOS - GroupedSends.Clear(); - await Task.Delay(60); - + // HACK: we need this on iOS, so that it doesn't crash when adding coming from an empty list + var first = true; + var items = new List(); foreach (var itemGroup in groupedSends) { - GroupedSends.Add(new SendGroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); - await Task.Delay(60); + if (!first) + { + items.Add(new SendGroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); + } + else + { + first = false; + } + items.AddRange(itemGroup); + } - GroupedSends.AddRange(itemGroup); + if (groupedSends.Any()) + { + GroupedSends.ReplaceRange(new List { new SendGroupingsPageHeaderListItem(groupedSends[0].Name, groupedSends[0].ItemCount) }); + GroupedSends.AddRange(items); + } + else + { + GroupedSends.Clear(); } } } diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs index 0af8a2ea6..48b67bf1f 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs @@ -515,7 +515,9 @@ namespace Bit.App.Pages }; // TODO: refactor this - if (Device.RuntimePlatform == Device.Android) + if (Device.RuntimePlatform == Device.Android + || + GroupedItems.Any()) { var items = new List(); foreach (var itemGroup in settingsListGroupItems) @@ -528,20 +530,31 @@ namespace Bit.App.Pages } else { - Device.InvokeOnMainThreadAsync(async () => + // HACK: we need this on iOS, so that it doesn't crash when adding coming from an empty list + var first = true; + var items = new List(); + foreach (var itemGroup in settingsListGroupItems) { - // HACK: This waitings are to avoid crash on iOS - GroupedItems.Clear(); - await Task.Delay(60); - - foreach (var itemGroup in settingsListGroupItems) + if (!first) { - GroupedItems.Add(new SettingsPageHeaderListItem(itemGroup.Name)); - await Task.Delay(60); - - GroupedItems.AddRange(itemGroup); + items.Add(new SettingsPageHeaderListItem(itemGroup.Name)); } - }).FireAndForget(); + else + { + first = false; + } + items.AddRange(itemGroup); + } + + if (settingsListGroupItems.Any()) + { + GroupedItems.ReplaceRange(new List { new SettingsPageHeaderListItem(settingsListGroupItems[0].Name) }); + GroupedItems.AddRange(items); + } + else + { + GroupedItems.Clear(); + } } } diff --git a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs index 5cad8f53e..b90a144a2 100644 --- a/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs +++ b/src/App/Pages/Vault/AutofillCiphersPageViewModel.cs @@ -108,7 +108,9 @@ namespace Bit.App.Pages } // TODO: refactor this - if (Device.RuntimePlatform == Device.Android) + if (Device.RuntimePlatform == Device.Android + || + GroupedItems.Any()) { var items = new List(); foreach (var itemGroup in groupedItems) @@ -121,16 +123,30 @@ namespace Bit.App.Pages } else { - // HACK: This waitings are to avoid crash on iOS - GroupedItems.Clear(); - await Task.Delay(60); - + // HACK: we need this on iOS, so that it doesn't crash when adding coming from an empty list + var first = true; + var items = new List(); foreach (var itemGroup in groupedItems) { - GroupedItems.Add(new GroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); - await Task.Delay(60); + if (!first) + { + items.Add(new GroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); + } + else + { + first = false; + } + items.AddRange(itemGroup); + } - GroupedItems.AddRange(itemGroup); + if (groupedItems.Any()) + { + GroupedItems.ReplaceRange(new List { new GroupingsPageHeaderListItem(groupedItems[0].Name, groupedItems[0].ItemCount) }); + GroupedItems.AddRange(items); + } + else + { + GroupedItems.Clear(); } } ShowList = groupedItems.Any(); diff --git a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs index 7ffe1f982..57ee29f52 100644 --- a/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs +++ b/src/App/Pages/Vault/GroupingsPage/GroupingsPageViewModel.cs @@ -283,7 +283,9 @@ namespace Bit.App.Pages } // TODO: refactor this - if (Device.RuntimePlatform == Device.Android) + if (Device.RuntimePlatform == Device.Android + || + GroupedItems.Any()) { var items = new List(); foreach (var itemGroup in groupedItems) @@ -296,16 +298,30 @@ namespace Bit.App.Pages } else { - // HACK: This waitings are to avoid crash on iOS - GroupedItems.Clear(); - await Task.Delay(60); - + // HACK: we need this on iOS, so that it doesn't crash when adding coming from an empty list + var first = true; + var items = new List(); foreach (var itemGroup in groupedItems) { - GroupedItems.Add(new GroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); - await Task.Delay(60); + if (!first) + { + items.Add(new GroupingsPageHeaderListItem(itemGroup.Name, itemGroup.ItemCount)); + } + else + { + first = false; + } + items.AddRange(itemGroup); + } - GroupedItems.AddRange(itemGroup); + if (groupedItems.Any()) + { + GroupedItems.ReplaceRange(new List { new GroupingsPageHeaderListItem(groupedItems[0].Name, groupedItems[0].ItemCount) }); + GroupedItems.AddRange(items); + } + else + { + GroupedItems.Clear(); } } }