1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-21 11:25:56 +01:00

Search bar adjustments. No data message and loading indicator for vault list.

This commit is contained in:
Kyle Spearrin 2016-08-24 23:57:45 -04:00
parent fe422a101a
commit a4a7d2180c
3 changed files with 88 additions and 7 deletions

View File

@ -283,6 +283,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\CustomSearchBarRenderer.cs" />
<Compile Include="Controls\CustomButtonRenderer.cs" />
<Compile Include="Controls\ExtendedButtonRenderer.cs" />
<Compile Include="Controls\ExtendedTabbedPageRenderer.cs" />

View File

@ -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<SearchBar> e)
{
base.OnElementChanged(e);
Control.SetPadding((int)global::Android.App.Application.Context.ToPixels(-8), 0, 0, 0);
}
}
}

View File

@ -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<DateTime?>(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();
}
}