private void Init()
        {
            var noDataLabel = new Label
            {
                Text = string.Format(AppResources.NoLoginsForUri, _name ?? "--"),
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                Style    = (Style)Application.Current.Resources["text-muted"]
            };

            var addLoginButton = new ExtendedButton
            {
                Text    = AppResources.AddALogin,
                Command = new Command(() => AddLoginAsync()),
                Style   = (Style)Application.Current.Resources["btn-primaryAccent"]
            };

            NoDataStackLayout = new StackLayout
            {
                Children        = { noDataLabel, addLoginButton },
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Padding         = new Thickness(20, 0),
                Spacing         = 20
            };

            AddLoginItem = new AddLoginToolBarItem(this);
            ToolbarItems.Add(AddLoginItem);
            SearchItem = new SearchToolBarItem(this);
            ToolbarItems.Add(SearchItem);

            ListView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                IsGroupingEnabled   = true,
                ItemsSource         = PresentationLoginsGroup,
                HasUnevenRows       = true,
                GroupHeaderTemplate = new DataTemplate(() => new HeaderViewCell()),
                ItemTemplate        = new DataTemplate(() => new VaultListViewCell(
                                                           (VaultListPageModel.Login l) => MoreClickedAsync(l)))
            };

            if (Device.OS == TargetPlatform.iOS)
            {
                ListView.RowHeight = -1;
            }

            Title = string.Format(AppResources.LoginsForUri, _name ?? "--");

            LoadingIndicator = new ActivityIndicator
            {
                IsRunning         = true,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Center
            };

            Content = LoadingIndicator;
        }
Пример #2
0
        private void Init()
        {
            MessagingCenter.Subscribe <Application, bool>(Application.Current, "SyncCompleted", (sender, success) =>
            {
                if (success)
                {
                    _filterResultsCancellationTokenSource = FetchAndLoadVault();
                }
            });

            if (!_favorites)
            {
                AddLoginItem = new AddLoginToolBarItem(this);
                ToolbarItems.Add(AddLoginItem);
            }

            ListView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                IsGroupingEnabled   = true,
                ItemsSource         = PresentationFolders,
                HasUnevenRows       = true,
                GroupHeaderTemplate = new DataTemplate(() => new VaultListHeaderViewCell(this)),
                ItemTemplate        = new DataTemplate(() => new VaultListViewCell(
                                                           (VaultListPageModel.Login l) => MoreClickedAsync(l)))
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                ListView.RowHeight = -1;
            }

            Search = new SearchBar
            {
                Placeholder       = AppResources.SearchVault,
                FontSize          = Device.GetNamedSize(NamedSize.Small, typeof(Button)),
                CancelButtonColor = Color.FromHex("3c8dbc")
            };
            // Bug with searchbar on android 7, ref https://bugzilla.xamarin.com/show_bug.cgi?id=43975
            if (Device.RuntimePlatform == Device.Android && _deviceInfoService.Version >= 24)
            {
                Search.HeightRequest = 50;
            }

            Title = _favorites ? AppResources.Favorites : AppResources.MyVault;

            ResultsStackLayout = new StackLayout
            {
                Children = { Search, ListView },
                Spacing  = 0
            };

            var noDataLabel = new Label
            {
                Text = _favorites ? AppResources.NoFavorites : AppResources.NoLogins,
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
                Style    = (Style)Application.Current.Resources["text-muted"]
            };

            NoDataStackLayout = new StackLayout
            {
                Children        = { noDataLabel },
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Padding         = new Thickness(20, 0),
                Spacing         = 20
            };

            if (!_favorites)
            {
                var addLoginButton = new ExtendedButton
                {
                    Text    = AppResources.AddALogin,
                    Command = new Command(() => AddLogin()),
                    Style   = (Style)Application.Current.Resources["btn-primaryAccent"]
                };

                NoDataStackLayout.Children.Add(addLoginButton);
            }

            LoadingIndicator = new ActivityIndicator
            {
                IsRunning         = true,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.Center
            };

            Content = LoadingIndicator;
        }