From a4a7d2180cdd268c351257fe1700c6217f584b3f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 24 Aug 2016 23:57:45 -0400 Subject: [PATCH] Search bar adjustments. No data message and loading indicator for vault list. --- src/Android/Android.csproj | 1 + .../Controls/CustomSearchBarRenderer.cs | 18 +++++ src/App/Pages/Vault/VaultListSitesPage.cs | 76 +++++++++++++++++-- 3 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/Android/Controls/CustomSearchBarRenderer.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 561bf5dcd..c4657a0b3 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -283,6 +283,7 @@ + diff --git a/src/Android/Controls/CustomSearchBarRenderer.cs b/src/Android/Controls/CustomSearchBarRenderer.cs new file mode 100644 index 000000000..dd92711cd --- /dev/null +++ b/src/Android/Controls/CustomSearchBarRenderer.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel; +using Bit.Android.Controls; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; + +[assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))] +namespace Bit.Android.Controls +{ + public class CustomSearchBarRenderer : SearchBarRenderer + { + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + Control.SetPadding((int)global::Android.App.Application.Context.ToPixels(-8), 0, 0, 0); + } + } +} diff --git a/src/App/Pages/Vault/VaultListSitesPage.cs b/src/App/Pages/Vault/VaultListSitesPage.cs index 2559261f5..39d681188 100644 --- a/src/App/Pages/Vault/VaultListSitesPage.cs +++ b/src/App/Pages/Vault/VaultListSitesPage.cs @@ -56,6 +56,9 @@ namespace Bit.App.Pages public VaultListPageModel.Site[] Sites { get; set; } = new VaultListPageModel.Site[] { }; public VaultListPageModel.Folder[] Folders { get; set; } = new VaultListPageModel.Folder[] { }; public SearchBar Search { get; set; } + public StackLayout NoDataStackLayout { get; set; } + public StackLayout ResultsStackLayout { get; set; } + public ActivityIndicator LoadingIndicator { get; set; } private void Init() { @@ -98,11 +101,49 @@ namespace Bit.App.Pages Search.SearchButtonPressed += SearchBar_SearchButtonPressed; Title = _favorites ? AppResources.Favorites : AppResources.MyVault; - Content = new StackLayout + + ResultsStackLayout = new StackLayout { Children = { Search, ListView }, Spacing = 0 }; + + var noDataLabel = new Label + { + Text = _favorites ? "There are no favorites in your vault." : "There are no sites in your vault.", + 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 addSiteButton = new ExtendedButton + { + Text = "Add a site", + IsVisible = !_favorites, + Command = new Command(() => AddSite()) + }; + + NoDataStackLayout.Children.Add(addSiteButton); + } + + LoadingIndicator = new ActivityIndicator + { + IsRunning = true, + VerticalOptions = LayoutOptions.CenterAndExpand, + HorizontalOptions = LayoutOptions.Center + }; + + Content = LoadingIndicator; } private void SearchBar_SearchButtonPressed(object sender, EventArgs e) @@ -187,7 +228,7 @@ namespace Bit.App.Pages Action registerAction = () => { var lastPushRegistration = _settings.GetValueOrDefault(Constants.PushLastRegistrationDate); - if(!pushPromptShow || !lastPushRegistration.HasValue + if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.UtcNow - lastPushRegistration) > TimeSpan.FromDays(1)) { _pushNotification.Register(); @@ -215,6 +256,18 @@ namespace Bit.App.Pages } } + private void AdjustContent() + { + if(PresentationFolders.Count > 0) + { + Content = ResultsStackLayout; + } + else + { + Content = NoDataStackLayout; + } + } + private CancellationTokenSource FetchAndLoadVault() { var cts = new CancellationTokenSource(); @@ -294,7 +347,11 @@ namespace Bit.App.Pages .ToList(); ct.ThrowIfCancellationRequested(); - Device.BeginInvokeOnMainThread(() => PresentationFolders.ResetWithRange(foldersToAdd)); + Device.BeginInvokeOnMainThread(() => + { + PresentationFolders.ResetWithRange(foldersToAdd); + AdjustContent(); + }); } private void SiteSelected(object sender, SelectedItemChangedEventArgs e) @@ -315,7 +372,7 @@ namespace Bit.App.Pages { buttons.Add(AppResources.CopyUsername); } - if(!string.IsNullOrWhiteSpace(site.Uri.Value) && (site.Uri.Value.StartsWith("http://") + if(!string.IsNullOrWhiteSpace(site.Uri.Value) && (site.Uri.Value.StartsWith("http://") || site.Uri.Value.StartsWith("https://"))) { buttons.Add(AppResources.GoToWebsite); @@ -353,6 +410,12 @@ namespace Bit.App.Pages _userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel)); } + private async void AddSite() + { + var page = new ExtendedNavigationPage(new VaultAddSitePage()); + await Navigation.PushModalAsync(page); + } + private class AddSiteToolBarItem : ToolbarItem { private readonly VaultListSitesPage _page; @@ -365,10 +428,9 @@ namespace Bit.App.Pages Clicked += ClickedItem; } - private async void ClickedItem(object sender, EventArgs e) + private void ClickedItem(object sender, EventArgs e) { - var page = new ExtendedNavigationPage(new VaultAddSitePage()); - await _page.Navigation.PushModalAsync(page); + _page.AddSite(); } }