Added button to toggle password field visibility on site edit
This commit is contained in:
parent
4a0e3227fc
commit
db6ceea711
|
@ -16,11 +16,16 @@ namespace Bit.Android.Controls
|
||||||
{
|
{
|
||||||
public class ExtendedEntryRenderer : EntryRenderer
|
public class ExtendedEntryRenderer : EntryRenderer
|
||||||
{
|
{
|
||||||
|
private bool _isPassword;
|
||||||
|
private bool _toggledPassword;
|
||||||
|
|
||||||
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
|
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
|
||||||
{
|
{
|
||||||
base.OnElementChanged(e);
|
base.OnElementChanged(e);
|
||||||
|
|
||||||
var view = (ExtendedEntry)Element;
|
var view = (ExtendedEntry)Element;
|
||||||
|
_isPassword = view.IsPassword;
|
||||||
|
|
||||||
if(Control != null)
|
if(Control != null)
|
||||||
{
|
{
|
||||||
Control.SetIncludeFontPadding(false);
|
Control.SetIncludeFontPadding(false);
|
||||||
|
@ -56,8 +61,44 @@ namespace Bit.Android.Controls
|
||||||
{
|
{
|
||||||
Control.SetRawInputType(Control.InputType |= InputTypes.TextFlagNoSuggestions);
|
Control.SetRawInputType(Control.InputType |= InputTypes.TextFlagNoSuggestions);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
view.ToggleIsPassword += (object sender, EventArgs args) =>
|
||||||
|
{
|
||||||
|
var cursorStart = Control.SelectionStart;
|
||||||
|
var cursorEnd = Control.SelectionEnd;
|
||||||
|
|
||||||
|
Control.TransformationMethod = _isPassword ? null : new PasswordTransformationMethod();
|
||||||
|
|
||||||
|
// set focus
|
||||||
|
Control.RequestFocus();
|
||||||
|
|
||||||
|
if(_toggledPassword)
|
||||||
|
{
|
||||||
|
// restore cursor position
|
||||||
|
Control.SetSelection(cursorStart, cursorEnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// set cursor to end
|
||||||
|
Control.SetSelection(Control.Text.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// show keyboard
|
||||||
|
var app = XLabs.Ioc.Resolver.Resolve<global::Android.App.Application>();
|
||||||
|
var inputMethodManager =
|
||||||
|
app.GetSystemService(global::Android.Content.Context.InputMethodService) as InputMethodManager;
|
||||||
|
inputMethodManager.ShowSoftInput(Control, ShowFlags.Forced);
|
||||||
|
inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
|
||||||
|
|
||||||
|
_isPassword = view.IsPasswordFromToggled = !_isPassword;
|
||||||
|
_toggledPassword = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(view.FontFamily == "monospace")
|
||||||
|
{
|
||||||
|
Control.Typeface = Typeface.Monospace;
|
||||||
|
}
|
||||||
|
}
|
||||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var view = (ExtendedEntry)Element;
|
var view = (ExtendedEntry)Element;
|
||||||
|
@ -76,6 +117,11 @@ namespace Bit.Android.Controls
|
||||||
Control.SetBackgroundColor(view.BackgroundColor.ToAndroid());
|
Control.SetBackgroundColor(view.BackgroundColor.ToAndroid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(view.FontFamily == "monospace")
|
||||||
|
{
|
||||||
|
Control.Typeface = Typeface.Monospace;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetReturnType(ExtendedEntry view)
|
private void SetReturnType(ExtendedEntry view)
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Bit.App.Controls
|
||||||
{
|
{
|
||||||
PlaceholderColor = Color.FromHex("c7c7cd");
|
PlaceholderColor = Color.FromHex("c7c7cd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IsPasswordFromToggled = IsPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly BindableProperty HasBorderProperty =
|
public static readonly BindableProperty HasBorderProperty =
|
||||||
|
@ -62,5 +64,20 @@ namespace Bit.App.Controls
|
||||||
{
|
{
|
||||||
Completed?.Invoke(this, null);
|
Completed?.Invoke(this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void InvokeToggleIsPassword()
|
||||||
|
{
|
||||||
|
if(ToggleIsPassword == null)
|
||||||
|
{
|
||||||
|
IsPassword = IsPasswordFromToggled = !IsPassword;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ToggleIsPassword.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler ToggleIsPassword;
|
||||||
|
public bool IsPasswordFromToggled { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace Bit.App.Controls
|
||||||
VisualElement nextElement = null,
|
VisualElement nextElement = null,
|
||||||
bool useLabelAsPlaceholder = false,
|
bool useLabelAsPlaceholder = false,
|
||||||
string imageSource = null,
|
string imageSource = null,
|
||||||
Thickness? containerPadding = null)
|
Thickness? containerPadding = null,
|
||||||
|
bool useButton = false)
|
||||||
{
|
{
|
||||||
if(!useLabelAsPlaceholder)
|
if(!useLabelAsPlaceholder)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +113,12 @@ namespace Bit.App.Controls
|
||||||
formStackLayout.Children.Add(Entry);
|
formStackLayout.Children.Add(Entry);
|
||||||
imageStackLayout.Children.Add(formStackLayout);
|
imageStackLayout.Children.Add(formStackLayout);
|
||||||
|
|
||||||
|
if(useButton)
|
||||||
|
{
|
||||||
|
Button = new ExtendedButton();
|
||||||
|
imageStackLayout.Children.Add(Button);
|
||||||
|
}
|
||||||
|
|
||||||
Tapped += FormEntryCell_Tapped;
|
Tapped += FormEntryCell_Tapped;
|
||||||
|
|
||||||
View = imageStackLayout;
|
View = imageStackLayout;
|
||||||
|
@ -119,6 +126,7 @@ namespace Bit.App.Controls
|
||||||
|
|
||||||
public Label Label { get; private set; }
|
public Label Label { get; private set; }
|
||||||
public ExtendedEntry Entry { get; private set; }
|
public ExtendedEntry Entry { get; private set; }
|
||||||
|
public ExtendedButton Button { get; private set; }
|
||||||
|
|
||||||
private void Tgr_Tapped(object sender, EventArgs e)
|
private void Tgr_Tapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,15 +45,21 @@ namespace Bit.App.Pages
|
||||||
|
|
||||||
var notesCell = new FormEditorCell(height: 90);
|
var notesCell = new FormEditorCell(height: 90);
|
||||||
notesCell.Editor.Text = site.Notes?.Decrypt();
|
notesCell.Editor.Text = site.Notes?.Decrypt();
|
||||||
PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor);
|
|
||||||
|
PasswordCell = new FormEntryCell(AppResources.Password, IsPassword: true, nextElement: notesCell.Editor,
|
||||||
|
useButton: true);
|
||||||
PasswordCell.Entry.Text = site.Password?.Decrypt();
|
PasswordCell.Entry.Text = site.Password?.Decrypt();
|
||||||
|
PasswordCell.Button.Image = "eye";
|
||||||
|
PasswordCell.Button.Clicked += PasswordButton_Clicked;
|
||||||
|
|
||||||
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
|
var usernameCell = new FormEntryCell(AppResources.Username, nextElement: PasswordCell.Entry);
|
||||||
usernameCell.Entry.Text = site.Username?.Decrypt();
|
usernameCell.Entry.Text = site.Username?.Decrypt();
|
||||||
usernameCell.Entry.DisableAutocapitalize = true;
|
usernameCell.Entry.DisableAutocapitalize = true;
|
||||||
usernameCell.Entry.Autocorrect = false;
|
usernameCell.Entry.Autocorrect = false;
|
||||||
|
|
||||||
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = Device.OnPlatform(
|
|
||||||
iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily =
|
||||||
|
Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
||||||
|
|
||||||
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
|
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
|
||||||
uriCell.Entry.Text = site.Uri?.Decrypt();
|
uriCell.Entry.Text = site.Uri?.Decrypt();
|
||||||
|
@ -192,6 +198,12 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PasswordButton_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
PasswordCell.Entry.InvokeToggleIsPassword();
|
||||||
|
PasswordCell.Button.Image = "eye" + (!PasswordCell.Entry.IsPasswordFromToggled ? "_slash" : string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
{
|
{
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
|
|
Loading…
Reference in New Issue