From 7c83d7b37b70739e462695d17b8ede591ad7b9d3 Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Tue, 15 Mar 2022 11:19:34 -0300 Subject: [PATCH] Removed grouping from Settings to fix a crash on iOS 15.4 (#1845) --- .../SettingsPage/ISettingsPageListItem.cs | 6 +++ .../Settings/SettingsPage/SettingsPage.xaml | 39 +++++++++---------- .../SettingsPageHeaderListItem.cs | 12 ++++++ .../SettingsPage/SettingsPageListItem.cs | 3 +- .../SettingsPageListItemSelector.cs | 14 +++---- .../SettingsPage/SettingsPageViewModel.cs | 19 ++++++--- 6 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 src/App/Pages/Settings/SettingsPage/ISettingsPageListItem.cs create mode 100644 src/App/Pages/Settings/SettingsPage/SettingsPageHeaderListItem.cs diff --git a/src/App/Pages/Settings/SettingsPage/ISettingsPageListItem.cs b/src/App/Pages/Settings/SettingsPage/ISettingsPageListItem.cs new file mode 100644 index 000000000..e8edc5063 --- /dev/null +++ b/src/App/Pages/Settings/SettingsPage/ISettingsPageListItem.cs @@ -0,0 +1,6 @@ +namespace Bit.App.Pages +{ + public interface ISettingsPageListItem + { + } +} diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPage.xaml b/src/App/Pages/Settings/SettingsPage/SettingsPage.xaml index c7238146f..b3964fe3e 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPage.xaml +++ b/src/App/Pages/Settings/SettingsPage/SettingsPage.xaml @@ -82,8 +82,26 @@ + + + + + + + + + @@ -93,27 +111,8 @@ ItemsSource="{Binding GroupedItems}" VerticalOptions="FillAndExpand" ItemTemplate="{StaticResource listItemDataTemplateSelector}" - IsGrouped="True" SelectionMode="Single" SelectionChanged="RowSelected" - StyleClass="list, list-platform"> - - - - - - - - - - - - + StyleClass="list, list-platform" /> diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageHeaderListItem.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageHeaderListItem.cs new file mode 100644 index 000000000..ec3aafe16 --- /dev/null +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageHeaderListItem.cs @@ -0,0 +1,12 @@ +namespace Bit.App.Pages +{ + public class SettingsPageHeaderListItem : ISettingsPageListItem + { + public SettingsPageHeaderListItem(string title) + { + Title = title; + } + + public string Title { get; } + } +} diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageListItem.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageListItem.cs index b63efcf01..c1e8878f4 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageListItem.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageListItem.cs @@ -1,12 +1,11 @@ using System; using Bit.App.Resources; using Bit.App.Utilities; -using System.Collections.Generic; using Xamarin.Forms; namespace Bit.App.Pages { - public class SettingsPageListItem + public class SettingsPageListItem : ISettingsPageListItem { public string Icon { get; set; } public string Name { get; set; } diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageListItemSelector.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageListItemSelector.cs index 246967de1..74dae3f2d 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageListItemSelector.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageListItemSelector.cs @@ -4,21 +4,19 @@ namespace Bit.App.Pages { public class SettingsPageListItemSelector : DataTemplateSelector { + public DataTemplate HeaderTemplate { get; set; } public DataTemplate RegularTemplate { get; set; } public DataTemplate TimePickerTemplate { get; set; } protected override DataTemplate OnSelectTemplate(object item, BindableObject container) { + if (item is SettingsPageHeaderListItem) + { + return HeaderTemplate; + } if (item is SettingsPageListItem listItem) { - if (listItem.ShowTimeInput) - { - return TimePickerTemplate; - } - else - { - return RegularTemplate; - } + return listItem.ShowTimeInput ? TimePickerTemplate : RegularTemplate; } return null; } diff --git a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs index 3deb45673..85cd338b4 100644 --- a/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs +++ b/src/App/Pages/Settings/SettingsPage/SettingsPageViewModel.cs @@ -80,11 +80,11 @@ namespace Bit.App.Pages _keyConnectorService = ServiceContainer.Resolve("keyConnectorService"); _clipboardService = ServiceContainer.Resolve("clipboardService"); - GroupedItems = new ObservableRangeCollection(); + GroupedItems = new ObservableRangeCollection(); PageTitle = AppResources.Settings; } - public ObservableRangeCollection GroupedItems { get; set; } + public ObservableRangeCollection GroupedItems { get; set; } public async Task InitAsync() { @@ -401,8 +401,6 @@ namespace Bit.App.Pages public void BuildList() { - GroupedItems.Clear(); - var doUpper = Device.RuntimePlatform != Device.Android; var autofillItems = new List(); if (Device.RuntimePlatform == Device.Android) @@ -504,7 +502,9 @@ namespace Bit.App.Pages new SettingsPageListItem { Name = AppResources.RateTheApp }, new SettingsPageListItem { Name = AppResources.DeleteAccount } }; - GroupedItems.AddRange(new List + + // TODO: improve this. Leaving this as is to reduce error possibility on the hotfix. + var settingsListGroupItems = new List() { new SettingsPageListGroup(autofillItems, AppResources.Autofill, doUpper, true), new SettingsPageListGroup(manageItems, AppResources.Manage, doUpper), @@ -512,7 +512,14 @@ namespace Bit.App.Pages new SettingsPageListGroup(accountItems, AppResources.Account, doUpper), new SettingsPageListGroup(toolsItems, AppResources.Tools, doUpper), new SettingsPageListGroup(otherItems, AppResources.Other, doUpper) - }); + }; + var settingsItems = new List(); + foreach (var itemGroup in settingsListGroupItems) + { + settingsItems.Add(new SettingsPageHeaderListItem(itemGroup.Name)); + settingsItems.AddRange(itemGroup); + } + GroupedItems.ReplaceRange(settingsItems); } private bool IncludeLinksWithSubscriptionInfo()