1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-07 09:20:04 +01:00

custom field name prompt

This commit is contained in:
Kyle Spearrin 2019-05-09 11:44:27 -04:00
parent 866a20ed5a
commit a0e65fa75e
4 changed files with 80 additions and 7 deletions

View File

@ -6,7 +6,9 @@ using Android.Content;
using Android.Content.PM; using Android.Content.PM;
using Android.Support.V4.Content; using Android.Support.V4.Content;
using Android.Webkit; using Android.Webkit;
using Android.Widget;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
@ -147,6 +149,50 @@ namespace Bit.Droid.Services
catch(Exception) { } catch(Exception) { }
} }
public Task<string> DisplayPromptAync(string title = null, string description = null,
string text = null, string okButtonText = null, string cancelButtonText = null)
{
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
if(activity == null)
{
return Task.FromResult<string>(null);
}
var alertBuilder = new AlertDialog.Builder(activity);
alertBuilder.SetTitle(title);
alertBuilder.SetMessage(description);
var input = new EditText(activity)
{
InputType = Android.Text.InputTypes.ClassText
};
if(text == null)
{
text = string.Empty;
}
input.Text = text;
input.SetSelection(text.Length);
var container = new FrameLayout(activity);
var lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent,
LinearLayout.LayoutParams.MatchParent);
lp.SetMargins(25, 0, 25, 0);
input.LayoutParameters = lp;
container.AddView(input);
alertBuilder.SetView(container);
okButtonText = okButtonText ?? AppResources.Ok;
cancelButtonText = cancelButtonText ?? AppResources.Cancel;
var result = new TaskCompletionSource<string>();
alertBuilder.SetPositiveButton(okButtonText,
(sender, args) => result.TrySetResult(input.Text ?? string.Empty));
alertBuilder.SetNegativeButton(cancelButtonText, (sender, args) => result.TrySetResult(null));
var alert = alertBuilder.Create();
alert.Window.SetSoftInputMode(Android.Views.SoftInput.StateVisible);
alert.Show();
return result.Task;
}
private bool DeleteDir(Java.IO.File dir) private bool DeleteDir(Java.IO.File dir)
{ {
if(dir != null && dir.IsDirectory) if(dir != null && dir.IsDirectory)

View File

@ -13,5 +13,7 @@ namespace Bit.App.Abstractions
bool OpenFile(byte[] fileData, string id, string fileName); bool OpenFile(byte[] fileData, string id, string fileName);
bool CanOpenFile(string fileName); bool CanOpenFile(string fileName);
Task ClearCacheAsync(); Task ClearCacheAsync();
Task<string> DisplayPromptAync(string title = null, string description = null, string text = null,
string okButtonText = null, string cancelButtonText = null);
} }
} }

View File

@ -394,9 +394,9 @@ namespace Bit.App.Pages
} }
else if(selection == AppResources.Edit) else if(selection == AppResources.Edit)
{ {
var name = "new name"; var name = await _deviceActionService.DisplayPromptAync(AppResources.CustomFieldName,
// TODO: prompt for name null, field.Field.Name);
field.Field.Name = name; field.Field.Name = name ?? field.Field.Name;
field.TriggerFieldChanged(); field.TriggerFieldChanged();
} }
else if(selection == AppResources.MoveUp) else if(selection == AppResources.MoveUp)
@ -423,9 +423,7 @@ namespace Bit.App.Pages
_fieldTypeOptions.Select(f => f.Value).ToArray()); _fieldTypeOptions.Select(f => f.Value).ToArray());
if(typeSelection != null && typeSelection != AppResources.Cancel) if(typeSelection != null && typeSelection != AppResources.Cancel)
{ {
var name = "new field name"; var name = await _deviceActionService.DisplayPromptAync(AppResources.CustomFieldName);
// TODO: prompt for name
if(Fields == null) if(Fields == null)
{ {
Fields = new ExtendedObservableCollection<AddEditPageFieldViewModel>(); Fields = new ExtendedObservableCollection<AddEditPageFieldViewModel>();

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Resources;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Enums; using Bit.Core.Enums;
@ -125,6 +126,32 @@ namespace Bit.iOS.Services
await _storageService.SaveAsync(Constants.LastFileCacheClearKey, DateTime.UtcNow); await _storageService.SaveAsync(Constants.LastFileCacheClearKey, DateTime.UtcNow);
} }
public Task<string> DisplayPromptAync(string title = null, string description = null,
string text = null, string okButtonText = null, string cancelButtonText = null)
{
var result = new TaskCompletionSource<string>();
var alert = UIAlertController.Create(title ?? string.Empty, description, UIAlertControllerStyle.Alert);
UITextField input = null;
okButtonText = okButtonText ?? AppResources.Ok;
cancelButtonText = cancelButtonText ?? AppResources.Cancel;
alert.AddAction(UIAlertAction.Create(cancelButtonText, UIAlertActionStyle.Cancel, x =>
{
result.TrySetResult(null);
}));
alert.AddAction(UIAlertAction.Create(okButtonText, UIAlertActionStyle.Default, x =>
{
result.TrySetResult(input.Text ?? string.Empty);
}));
alert.AddTextField(x =>
{
input = x;
input.Text = text ?? string.Empty;
});
var vc = GetPresentedViewController();
vc?.PresentViewController(alert, true, null);
return result.Task;
}
private UIViewController GetVisibleViewController(UIViewController controller = null) private UIViewController GetVisibleViewController(UIViewController controller = null)
{ {
controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController; controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;
@ -160,7 +187,7 @@ namespace Bit.iOS.Services
return vc != null && (vc is UITabBarController || return vc != null && (vc is UITabBarController ||
(vc.ChildViewControllers?.Any(c => c is UITabBarController) ?? false)); (vc.ChildViewControllers?.Any(c => c is UITabBarController) ?? false));
} }
// ref: //https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/ // ref: //https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/
public string GetTempPath() public string GetTempPath()
{ {