Beispiel #1
0
        public void BuildList()
        {
            //TODO: Refactor this once navigation is abstracted so that it doesn't depend on Page, e.g. Page.Navigation.PushModalAsync...

            var doUpper       = Device.RuntimePlatform != Device.Android;
            var autofillItems = new List <SettingsPageListItem>();

            if (Device.RuntimePlatform == Device.Android)
            {
                autofillItems.Add(new SettingsPageListItem
                {
                    Name         = AppResources.AutofillServices,
                    SubLabel     = _deviceActionService.AutofillServicesEnabled() ? AppResources.On : AppResources.Off,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new AutofillServicesPage(Page as SettingsPage)))
                });
            }
            else
            {
                if (_deviceActionService.SystemMajorVersion() >= 12)
                {
                    autofillItems.Add(new SettingsPageListItem
                    {
                        Name         = AppResources.PasswordAutofill,
                        ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new AutofillPage()))
                    });
                }
                autofillItems.Add(new SettingsPageListItem
                {
                    Name         = AppResources.AppExtension,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new ExtensionPage()))
                });
            }
            var manageItems = new List <SettingsPageListItem>
            {
                new SettingsPageListItem
                {
                    Name         = AppResources.Folders,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new FoldersPage()))
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.Sync,
                    SubLabel     = _lastSyncDate,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new SyncPage()))
                }
            };
            var securityItems = new List <SettingsPageListItem>
            {
                new SettingsPageListItem
                {
                    Name         = AppResources.VaultTimeout,
                    SubLabel     = _vaultTimeoutDisplayValue,
                    ExecuteAsync = () => VaultTimeoutAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.VaultTimeoutAction,
                    SubLabel     = _vaultTimeoutActionDisplayValue,
                    ExecuteAsync = () => VaultTimeoutActionAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.UnlockWithPIN,
                    SubLabel     = _pin ? AppResources.On : AppResources.Off,
                    ExecuteAsync = () => UpdatePinAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.LockNow,
                    ExecuteAsync = () => LockAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.TwoStepLogin,
                    ExecuteAsync = () => TwoStepAsync()
                }
            };

            if (_supportsBiometric || _biometric)
            {
                var biometricName = AppResources.Biometrics;
                if (Device.RuntimePlatform == Device.iOS)
                {
                    biometricName = _deviceActionService.SupportsFaceBiometric() ? AppResources.FaceID :
                                    AppResources.TouchID;
                }
                var item = new SettingsPageListItem
                {
                    Name         = string.Format(AppResources.UnlockWith, biometricName),
                    SubLabel     = _biometric ? AppResources.On : AppResources.Off,
                    ExecuteAsync = () => UpdateBiometricAsync()
                };
                securityItems.Insert(2, item);
            }
            if (_vaultTimeoutDisplayValue == AppResources.Custom)
            {
                securityItems.Insert(1, new SettingsPageListItem
                {
                    Name = AppResources.Custom,
                    Time = TimeSpan.FromMinutes(Math.Abs((double)_vaultTimeout.GetValueOrDefault())),
                });
            }
            if (_vaultTimeoutPolicy != null)
            {
                var maximumTimeout = _policyService.GetPolicyInt(_vaultTimeoutPolicy, "minutes").GetValueOrDefault();
                securityItems.Insert(0, new SettingsPageListItem
                {
                    Name = string.Format(AppResources.VaultTimeoutPolicyInEffect,
                                         Math.Floor((float)maximumTimeout / 60),
                                         maximumTimeout % 60),
                    UseFrame = true,
                });
            }
            if (Device.RuntimePlatform == Device.Android)
            {
                securityItems.Add(new SettingsPageListItem
                {
                    Name         = AppResources.AllowScreenCapture,
                    SubLabel     = _screenCaptureAllowed ? AppResources.On : AppResources.Off,
                    ExecuteAsync = () => SetScreenCaptureAllowedAsync()
                });
            }
            var accountItems = new List <SettingsPageListItem>
            {
                new SettingsPageListItem
                {
                    Name         = AppResources.FingerprintPhrase,
                    ExecuteAsync = () => FingerprintAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.LogOut,
                    ExecuteAsync = () => LogOutAsync()
                }
            };

            if (_showChangeMasterPassword)
            {
                accountItems.Insert(0, new SettingsPageListItem
                {
                    Name         = AppResources.ChangeMasterPassword,
                    ExecuteAsync = () => ChangePasswordAsync()
                });
            }
            var toolsItems = new List <SettingsPageListItem>
            {
                new SettingsPageListItem
                {
                    Name         = AppResources.ImportItems,
                    ExecuteAsync = () => Device.InvokeOnMainThreadAsync(() => Import())
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.ExportVault,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new ExportVaultPage()))
                }
            };

            if (IncludeLinksWithSubscriptionInfo())
            {
                toolsItems.Add(new SettingsPageListItem
                {
                    Name         = AppResources.LearnOrg,
                    ExecuteAsync = () => ShareAsync()
                });
                toolsItems.Add(new SettingsPageListItem
                {
                    Name         = AppResources.WebVault,
                    ExecuteAsync = () => Device.InvokeOnMainThreadAsync(() => WebVault())
                });
            }

            var otherItems = new List <SettingsPageListItem>
            {
                new SettingsPageListItem
                {
                    Name         = AppResources.Options,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new OptionsPage()))
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.About,
                    ExecuteAsync = () => AboutAsync()
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.HelpAndFeedback,
                    ExecuteAsync = () => Device.InvokeOnMainThreadAsync(() => Help())
                },
#if !FDROID
                new SettingsPageListItem
                {
                    Name         = AppResources.SubmitCrashLogs,
                    SubLabel     = _reportLoggingEnabled ? AppResources.On : AppResources.Off,
                    ExecuteAsync = () => LoggerReportingAsync()
                },
#endif
                new SettingsPageListItem
                {
                    Name         = AppResources.RateTheApp,
                    ExecuteAsync = () => Device.InvokeOnMainThreadAsync(() => Rate())
                },
                new SettingsPageListItem
                {
                    Name         = AppResources.DeleteAccount,
                    ExecuteAsync = () => Page.Navigation.PushModalAsync(new NavigationPage(new DeleteAccountPage()))
                }
            };

            // TODO: improve this. Leaving this as is to reduce error possibility on the hotfix.
            var settingsListGroupItems = new List <SettingsPageListGroup>()
            {
                new SettingsPageListGroup(autofillItems, AppResources.Autofill, doUpper, true),
                new SettingsPageListGroup(manageItems, AppResources.Manage, doUpper),
                new SettingsPageListGroup(securityItems, AppResources.Security, doUpper),
                new SettingsPageListGroup(accountItems, AppResources.Account, doUpper),
                new SettingsPageListGroup(toolsItems, AppResources.Tools, doUpper),
                new SettingsPageListGroup(otherItems, AppResources.Other, doUpper)
            };

            // TODO: refactor this
            if (Device.RuntimePlatform == Device.Android
                ||
                GroupedItems.Any())
            {
                var items = new List <ISettingsPageListItem>();
                foreach (var itemGroup in settingsListGroupItems)
                {
                    items.Add(new SettingsPageHeaderListItem(itemGroup.Name));
                    items.AddRange(itemGroup);
                }

                GroupedItems.ReplaceRange(items);
            }
            else
            {
                // 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 <ISettingsPageListItem>();
                foreach (var itemGroup in settingsListGroupItems)
                {
                    if (!first)
                    {
                        items.Add(new SettingsPageHeaderListItem(itemGroup.Name));
                    }
                    else
                    {
                        first = false;
                    }
                    items.AddRange(itemGroup);
                }

                if (settingsListGroupItems.Any())
                {
                    GroupedItems.ReplaceRange(new List <ISettingsPageListItem> {
                        new SettingsPageHeaderListItem(settingsListGroupItems[0].Name)
                    });
                    GroupedItems.AddRange(items);
                }
                else
                {
                    GroupedItems.Clear();
                }
            }
        }
Beispiel #2
0
 protected override IEnumerable <TimeEntryViewModel> GetGroupAt(nint section)
 => GroupedItems.ElementAtOrDefault((int)section);
Beispiel #3
0
 private MvxGroupedData GetItemAt(int groupIndex)
 => GroupedItems.ElementAt(groupIndex) as MvxGroupedData;