mirror of
https://github.com/bitwarden/android.git
synced 2024-12-19 07:41:52 +03:00
Search bar adjustments. No data message and loading indicator for vault list.
This commit is contained in:
parent
fe422a101a
commit
a4a7d2180c
3 changed files with 88 additions and 7 deletions
|
@ -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" />
|
||||
|
|
18
src/Android/Controls/CustomSearchBarRenderer.cs
Normal file
18
src/Android/Controls/CustomSearchBarRenderer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue