mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-22 16:18:21 +01:00
TableView to add site page
This commit is contained in:
parent
15be1cbf43
commit
6fd81fc40e
@ -45,7 +45,6 @@
|
||||
<Compile Include="Behaviors\ConnectivityBehavior.cs" />
|
||||
<Compile Include="Behaviors\RequiredValidationBehavior.cs" />
|
||||
<Compile Include="Controls\EntryLabel.cs" />
|
||||
<Compile Include="Controls\BottomBorderEntry.cs" />
|
||||
<Compile Include="Controls\ExtendedPicker.cs" />
|
||||
<Compile Include="Controls\ExtendedEntry.cs" />
|
||||
<Compile Include="Controls\ExtendedTabbedPage.cs" />
|
||||
|
@ -1,13 +0,0 @@
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class BottomBorderEntry : ExtendedEntry
|
||||
{
|
||||
public BottomBorderEntry()
|
||||
{
|
||||
HasBorder = HasOnlyBottomBorder = true;
|
||||
BottomBorderColor = Color.FromHex("d2d6de");
|
||||
}
|
||||
}
|
||||
}
|
@ -8,28 +8,10 @@ namespace Bit.App.Controls
|
||||
public static readonly BindableProperty HasBorderProperty =
|
||||
BindableProperty.Create(nameof(HasBorder), typeof(bool), typeof(ExtendedEntry), true);
|
||||
|
||||
public static readonly BindableProperty HasOnlyBottomBorderProperty =
|
||||
BindableProperty.Create(nameof(HasOnlyBottomBorder), typeof(bool), typeof(ExtendedEntry), false);
|
||||
|
||||
public static readonly BindableProperty BottomBorderColorProperty =
|
||||
BindableProperty.Create(nameof(BottomBorderColor), typeof(Color), typeof(ExtendedEntry), Color.Default);
|
||||
|
||||
public bool HasBorder
|
||||
{
|
||||
get { return (bool)GetValue(HasBorderProperty); }
|
||||
set { SetValue(HasBorderProperty, value); }
|
||||
}
|
||||
|
||||
public bool HasOnlyBottomBorder
|
||||
{
|
||||
get { return (bool)GetValue(HasOnlyBottomBorderProperty); }
|
||||
set { SetValue(HasOnlyBottomBorderProperty, value); }
|
||||
}
|
||||
|
||||
public Color BottomBorderColor
|
||||
{
|
||||
get { return (Color)GetValue(BottomBorderColorProperty); }
|
||||
set { SetValue(BottomBorderColorProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,27 +19,12 @@ namespace Bit.App.Pages
|
||||
|
||||
private void Init()
|
||||
{
|
||||
var foldersLayout = new StackLayout { Orientation = StackOrientation.Horizontal };
|
||||
foldersLayout.Children.Add(new Label
|
||||
{
|
||||
Text = "Folders",
|
||||
HorizontalOptions = LayoutOptions.StartAndExpand,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(10, 0, 0, 0)
|
||||
});
|
||||
foldersLayout.Children.Add(new Image
|
||||
{
|
||||
Source = ImageSource.FromFile("ion-chevron-right.png"),
|
||||
Opacity = 0.3,
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(0, 0, 10, 0)
|
||||
});
|
||||
var foldersCell = new ViewCell { View = foldersLayout };
|
||||
var foldersCell = new TextCell { Text = "Folders" };
|
||||
foldersCell.Tapped += FoldersCell_Tapped;
|
||||
|
||||
var table = new TableView
|
||||
{
|
||||
Intent = TableIntent.Menu,
|
||||
Root = new TableRoot
|
||||
{
|
||||
new TableSection("Manage Folders")
|
||||
|
@ -30,25 +30,25 @@ namespace Bit.App.Pages
|
||||
var syncButton = new Button
|
||||
{
|
||||
Text = "Sync Vault",
|
||||
Command = new Command( async () => await SyncAsync() )
|
||||
Command = new Command(async () => await SyncAsync())
|
||||
};
|
||||
|
||||
var stackLayout = new StackLayout { };
|
||||
stackLayout.Children.Add( syncButton );
|
||||
stackLayout.Children.Add( new ExtendedEntry
|
||||
stackLayout.Children.Add(syncButton);
|
||||
stackLayout.Children.Add(new ExtendedEntry
|
||||
{
|
||||
BottomBorderColor = Color.Black,
|
||||
HasBorder = true,
|
||||
HasOnlyBottomBorder = true,
|
||||
Placeholder = "Some placeholder",
|
||||
PlaceholderColor = Color.Red
|
||||
} );
|
||||
});
|
||||
|
||||
Title = "Sync";
|
||||
Content = stackLayout;
|
||||
Icon = "fa-refresh";
|
||||
|
||||
if( !_connectivity.IsConnected )
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
}
|
||||
@ -56,28 +56,28 @@ namespace Bit.App.Pages
|
||||
|
||||
public async Task SyncAsync()
|
||||
{
|
||||
if( !_connectivity.IsConnected )
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
_userDialogs.ShowLoading( "Syncing...", MaskType.Black );
|
||||
_userDialogs.ShowLoading("Syncing...", MaskType.Black);
|
||||
var succeeded = await _syncService.SyncAsync();
|
||||
_userDialogs.HideLoading();
|
||||
if( succeeded )
|
||||
if(succeeded)
|
||||
{
|
||||
_userDialogs.SuccessToast( "Syncing complete." );
|
||||
_userDialogs.SuccessToast("Syncing complete.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_userDialogs.ErrorToast( "Syncing failed." );
|
||||
_userDialogs.ErrorToast("Syncing failed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void AlertNoConnection()
|
||||
{
|
||||
DisplayAlert( AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok );
|
||||
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,94 +30,130 @@ namespace Bit.App.Pages
|
||||
|
||||
private void Init()
|
||||
{
|
||||
var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy( f => f.Name?.Decrypt() );
|
||||
var folders = _folderService.GetAllAsync().GetAwaiter().GetResult().OrderBy(f => f.Name?.Decrypt());
|
||||
|
||||
var uriEntry = new BottomBorderEntry { Keyboard = Keyboard.Url };
|
||||
var nameEntry = new BottomBorderEntry();
|
||||
var folderPicker = new ExtendedPicker
|
||||
{
|
||||
Title = AppResources.Folder,
|
||||
BottomBorderColor = Color.FromHex( "d2d6de" ),
|
||||
HasOnlyBottomBorder = true
|
||||
};
|
||||
folderPicker.Items.Add( AppResources.FolderNone );
|
||||
var uriEntry = new ExtendedEntry { Keyboard = Keyboard.Url, HasBorder = false };
|
||||
var nameEntry = new ExtendedEntry { HasBorder = false };
|
||||
var folderPicker = new ExtendedPicker { Title = AppResources.Folder, HasBorder = false };
|
||||
folderPicker.Items.Add(AppResources.FolderNone);
|
||||
folderPicker.SelectedIndex = 0;
|
||||
foreach( var folder in folders )
|
||||
foreach(var folder in folders)
|
||||
{
|
||||
folderPicker.Items.Add( folder.Name.Decrypt() );
|
||||
folderPicker.Items.Add(folder.Name.Decrypt());
|
||||
}
|
||||
var usernameEntry = new BottomBorderEntry();
|
||||
var passwordEntry = new BottomBorderEntry { IsPassword = true };
|
||||
var usernameEntry = new ExtendedEntry { HasBorder = false };
|
||||
var passwordEntry = new ExtendedEntry { IsPassword = true, HasBorder = false };
|
||||
var notesEditor = new Editor { HeightRequest = 75 };
|
||||
|
||||
var stackLayout = new StackLayout { Padding = new Thickness( 15 ) };
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.URI } );
|
||||
stackLayout.Children.Add( uriEntry );
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.Name, Margin = new Thickness( 0, 15, 0, 0 ) } );
|
||||
stackLayout.Children.Add( nameEntry );
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.Folder, Margin = new Thickness( 0, 15, 0, 0 ) } );
|
||||
stackLayout.Children.Add( folderPicker );
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.Username, Margin = new Thickness( 0, 15, 0, 0 ) } );
|
||||
stackLayout.Children.Add( usernameEntry );
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.Password, Margin = new Thickness( 0, 15, 0, 0 ) } );
|
||||
stackLayout.Children.Add( passwordEntry );
|
||||
stackLayout.Children.Add( new EntryLabel { Text = AppResources.Notes, Margin = new Thickness( 0, 15, 0, 0 ) } );
|
||||
stackLayout.Children.Add( notesEditor );
|
||||
var uriStackLayout = new FormEntryStackLayout();
|
||||
uriStackLayout.Children.Add(new EntryLabel { Text = AppResources.URI });
|
||||
uriStackLayout.Children.Add(uriEntry);
|
||||
var uriCell = new ViewCell();
|
||||
uriCell.View = uriStackLayout;
|
||||
|
||||
var nameStackLayout = new FormEntryStackLayout();
|
||||
nameStackLayout.Children.Add(new EntryLabel { Text = AppResources.Name });
|
||||
nameStackLayout.Children.Add(nameEntry);
|
||||
var nameCell = new ViewCell();
|
||||
nameCell.View = nameStackLayout;
|
||||
|
||||
var folderStackLayout = new FormEntryStackLayout();
|
||||
folderStackLayout.Children.Add(new EntryLabel { Text = AppResources.Folder });
|
||||
folderStackLayout.Children.Add(folderPicker);
|
||||
var folderCell = new ViewCell();
|
||||
folderCell.View = folderStackLayout;
|
||||
|
||||
var usernameStackLayout = new FormEntryStackLayout();
|
||||
usernameStackLayout.Children.Add(new EntryLabel { Text = AppResources.Username });
|
||||
usernameStackLayout.Children.Add(usernameEntry);
|
||||
var usernameCell = new ViewCell();
|
||||
usernameCell.View = usernameStackLayout;
|
||||
|
||||
var passwordStackLayout = new FormEntryStackLayout();
|
||||
passwordStackLayout.Children.Add(new EntryLabel { Text = AppResources.Password });
|
||||
passwordStackLayout.Children.Add(passwordEntry);
|
||||
var passwordCell = new ViewCell();
|
||||
passwordCell.View = passwordStackLayout;
|
||||
|
||||
var notesStackLayout = new FormEntryStackLayout();
|
||||
notesStackLayout.Children.Add(new EntryLabel { Text = AppResources.Notes });
|
||||
notesStackLayout.Children.Add(notesEditor);
|
||||
var notesCell = new ViewCell();
|
||||
notesCell.View = notesStackLayout;
|
||||
|
||||
var table = new TableView
|
||||
{
|
||||
Intent = TableIntent.Form,
|
||||
RowHeight = 65,
|
||||
HasUnevenRows = true,
|
||||
Root = new TableRoot
|
||||
{
|
||||
new TableSection
|
||||
{
|
||||
uriCell,
|
||||
nameCell,
|
||||
folderCell,
|
||||
usernameCell,
|
||||
passwordCell,
|
||||
notesCell
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var scrollView = new ScrollView
|
||||
{
|
||||
Content = stackLayout,
|
||||
Content = table,
|
||||
Orientation = ScrollOrientation.Vertical
|
||||
};
|
||||
|
||||
var saveToolBarItem = new ToolbarItem( AppResources.Save, null, async () =>
|
||||
{
|
||||
if( !_connectivity.IsConnected )
|
||||
{
|
||||
AlertNoConnection();
|
||||
return;
|
||||
}
|
||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||
{
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
if( string.IsNullOrWhiteSpace( uriEntry.Text ) )
|
||||
{
|
||||
await DisplayAlert( AppResources.AnErrorHasOccurred, string.Format( AppResources.ValidationFieldRequired, AppResources.URI ), AppResources.Ok );
|
||||
return;
|
||||
}
|
||||
if(string.IsNullOrWhiteSpace(uriEntry.Text))
|
||||
{
|
||||
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.URI), AppResources.Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
if( string.IsNullOrWhiteSpace( nameEntry.Text ) )
|
||||
{
|
||||
await DisplayAlert( AppResources.AnErrorHasOccurred, string.Format( AppResources.ValidationFieldRequired, AppResources.Name ), AppResources.Ok );
|
||||
return;
|
||||
}
|
||||
if(string.IsNullOrWhiteSpace(nameEntry.Text))
|
||||
{
|
||||
await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.Name), AppResources.Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
var site = new Site
|
||||
{
|
||||
Uri = uriEntry.Text.Encrypt(),
|
||||
Name = nameEntry.Text.Encrypt(),
|
||||
Username = usernameEntry.Text?.Encrypt(),
|
||||
Password = passwordEntry.Text?.Encrypt(),
|
||||
Notes = notesEditor.Text?.Encrypt(),
|
||||
};
|
||||
var site = new Site
|
||||
{
|
||||
Uri = uriEntry.Text.Encrypt(),
|
||||
Name = nameEntry.Text.Encrypt(),
|
||||
Username = usernameEntry.Text?.Encrypt(),
|
||||
Password = passwordEntry.Text?.Encrypt(),
|
||||
Notes = notesEditor.Text?.Encrypt(),
|
||||
};
|
||||
|
||||
if( folderPicker.SelectedIndex > 0 )
|
||||
{
|
||||
site.FolderId = folders.ElementAt( folderPicker.SelectedIndex - 1 ).Id;
|
||||
}
|
||||
if(folderPicker.SelectedIndex > 0)
|
||||
{
|
||||
site.FolderId = folders.ElementAt(folderPicker.SelectedIndex - 1).Id;
|
||||
}
|
||||
|
||||
var saveTask = _siteService.SaveAsync( site );
|
||||
_userDialogs.ShowLoading( "Saving...", MaskType.Black );
|
||||
await saveTask;
|
||||
var saveTask = _siteService.SaveAsync(site);
|
||||
_userDialogs.ShowLoading("Saving...", MaskType.Black);
|
||||
await saveTask;
|
||||
|
||||
_userDialogs.HideLoading();
|
||||
await Navigation.PopAsync();
|
||||
_userDialogs.SuccessToast( nameEntry.Text, "New site created." );
|
||||
}, ToolbarItemOrder.Default, 0 );
|
||||
_userDialogs.HideLoading();
|
||||
await Navigation.PopAsync();
|
||||
_userDialogs.SuccessToast(nameEntry.Text, "New site created.");
|
||||
}, ToolbarItemOrder.Default, 0);
|
||||
|
||||
Title = AppResources.AddSite;
|
||||
Content = scrollView;
|
||||
ToolbarItems.Add( saveToolBarItem );
|
||||
ToolbarItems.Add(saveToolBarItem);
|
||||
|
||||
if( !_connectivity.IsConnected )
|
||||
if(!_connectivity.IsConnected)
|
||||
{
|
||||
AlertNoConnection();
|
||||
}
|
||||
@ -125,7 +161,15 @@ namespace Bit.App.Pages
|
||||
|
||||
private void AlertNoConnection()
|
||||
{
|
||||
DisplayAlert( AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok );
|
||||
DisplayAlert(AppResources.InternetConnectionRequiredTitle, AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
|
||||
}
|
||||
|
||||
private class FormEntryStackLayout : StackLayout
|
||||
{
|
||||
public FormEntryStackLayout()
|
||||
{
|
||||
Padding = new Thickness(15, 15, 15, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,8 @@ namespace Bit.App.Pages
|
||||
}
|
||||
|
||||
Model.Update(site);
|
||||
|
||||
base.OnAppearing();
|
||||
}
|
||||
|
||||
private void Copy(string copyText, string alertLabel)
|
||||
|
@ -8,7 +8,7 @@ using SQLite;
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public abstract class Repository<T, TId> : IRepository<T, TId>
|
||||
where TId : IEquatable<TId>
|
||||
where TId : IEquatable<TId>
|
||||
where T : class, IDataObject<TId>, new()
|
||||
{
|
||||
public Repository(ISqlService sqlService)
|
||||
|
@ -8,7 +8,7 @@ using Foundation;
|
||||
|
||||
namespace Bit.iOS.Extension
|
||||
{
|
||||
[Register("ActionViewController")]
|
||||
[Register("ActionViewController")]
|
||||
partial class ActionViewController
|
||||
{
|
||||
[Outlet]
|
||||
|
@ -2,13 +2,11 @@
|
||||
using System.ComponentModel;
|
||||
using Bit.App.Controls;
|
||||
using Bit.iOS.Controls;
|
||||
using CoreAnimation;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ExtendedPicker), typeof( ExtendedPickerRenderer ) )]
|
||||
[assembly: ExportRenderer(typeof(ExtendedPicker), typeof(ExtendedPickerRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
{
|
||||
public class ExtendedPickerRenderer : PickerRenderer
|
||||
@ -30,35 +28,15 @@ namespace Bit.iOS.Controls
|
||||
|
||||
var view = (ExtendedPicker)Element;
|
||||
|
||||
if(e.PropertyName == ExtendedPicker.HasBorderProperty.PropertyName
|
||||
|| e.PropertyName == ExtendedPicker.HasOnlyBottomBorderProperty.PropertyName
|
||||
|| e.PropertyName == ExtendedPicker.BottomBorderColorProperty.PropertyName)
|
||||
if(e.PropertyName == ExtendedPicker.HasBorderProperty.PropertyName)
|
||||
{
|
||||
SetBorder(view);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetBorder( ExtendedPicker view )
|
||||
private void SetBorder(ExtendedPicker view)
|
||||
{
|
||||
if(view.HasOnlyBottomBorder)
|
||||
{
|
||||
var borderLayer = new CALayer();
|
||||
borderLayer.MasksToBounds = true;
|
||||
borderLayer.Frame = new CGRect( 0f, Frame.Height / 2, Frame.Width * 2, 1f );
|
||||
borderLayer.BorderColor = view.BottomBorderColor.ToCGColor();
|
||||
borderLayer.BorderWidth = 1f;
|
||||
|
||||
Control.Layer.AddSublayer( borderLayer );
|
||||
Control.BorderStyle = UITextBorderStyle.None;
|
||||
}
|
||||
else if(view.HasBorder)
|
||||
{
|
||||
Control.BorderStyle = UITextBorderStyle.RoundedRect;
|
||||
}
|
||||
else
|
||||
{
|
||||
Control.BorderStyle = UITextBorderStyle.None;
|
||||
}
|
||||
Control.BorderStyle = view.HasBorder ? UITextBorderStyle.RoundedRect : UITextBorderStyle.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using Xamarin.Forms.Platform.iOS;
|
||||
[assembly: ExportRenderer(typeof(ExtendedTabbedPage), typeof(ExtendedTabbedPageRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
{
|
||||
public class ExtendedTabbedPageRenderer: TabbedRenderer
|
||||
public class ExtendedTabbedPageRenderer : TabbedRenderer
|
||||
{
|
||||
protected override void OnElementChanged(VisualElementChangedEventArgs e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user