1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-27 12:26:31 +01:00

layout updates

This commit is contained in:
Kyle Spearrin 2017-11-16 22:34:19 -05:00
parent 1694b5d6fd
commit 0a6767209d
6 changed files with 47 additions and 66 deletions

View File

@ -4,60 +4,13 @@ using Android.Content;
using Android.Service.Autofill;
using Android.Views;
using Android.Widget;
using System.Diagnostics;
using System.Linq;
namespace Bit.Android.Autofill
{
public static class AutofillHelpers
{
/**
* Wraps autofill data in a LoginCredential Dataset object which can then be sent back to the
* client View.
*/
public static Dataset NewDataset(Context context, FieldCollection fields, IFilledItem filledItem, bool auth)
{
var itemName = filledItem.Name;
if(itemName != null)
{
Dataset.Builder datasetBuilder;
if(auth)
{
datasetBuilder = new Dataset.Builder(
NewRemoteViews(context.PackageName, itemName, filledItem.Subtitle, Resource.Drawable.fa_lock));
//IntentSender sender = AuthActivity.getAuthIntentSenderForDataset(context, datasetName);
//datasetBuilder.SetAuthentication(sender);
}
else
{
datasetBuilder = new Dataset.Builder(
NewRemoteViews(context.PackageName, itemName, filledItem.Subtitle, Resource.Drawable.user));
}
var setValue = filledItem.ApplyToFields(fields, datasetBuilder);
if(setValue)
{
return datasetBuilder.Build();
}
}
return null;
}
public static RemoteViews NewRemoteViews(string packageName, string text, string subtext, int iconId)
{
var views = new RemoteViews(packageName, Resource.Layout.autofill_listitem);
views.SetTextViewText(Resource.Id.text, text);
views.SetTextViewText(Resource.Id.text2, subtext);
views.SetImageViewResource(Resource.Id.icon, iconId);
return views;
}
/**
* Wraps autofill data in a Response object (essentially a series of Datasets) which can then
* be sent back to the client View.
*/
public static FillResponse NewResponse(Context context, bool auth, FieldCollection fields,
public static FillResponse BuildFillResponse(Context context, bool auth, FieldCollection fields,
IDictionary<string, IFilledItem> items)
{
var responseBuilder = new FillResponse.Builder();
@ -65,7 +18,7 @@ namespace Bit.Android.Autofill
{
foreach(var datasetName in items.Keys)
{
var dataset = NewDataset(context, fields, items[datasetName], auth);
var dataset = BuildDataset(context, fields, items[datasetName], auth);
if(dataset != null)
{
responseBuilder.AddDataset(dataset);
@ -73,27 +26,47 @@ namespace Bit.Android.Autofill
}
}
if(true || fields.SaveType != SaveDataType.Generic)
var info = new SaveInfo.Builder(fields.SaveType, fields.AutofillIds.ToArray()).Build();
responseBuilder.SetSaveInfo(info);
return responseBuilder.Build();
}
public static Dataset BuildDataset(Context context, FieldCollection fields, IFilledItem filledItem, bool auth)
{
Dataset.Builder datasetBuilder;
if(auth)
{
var info = new SaveInfo.Builder(fields.SaveType, fields.AutofillIds.ToArray()).Build();
responseBuilder.SetSaveInfo(info);
return responseBuilder.Build();
datasetBuilder = new Dataset.Builder(
BuildListView(context.PackageName, filledItem.Name, filledItem.Subtitle, Resource.Drawable.fa_lock));
//IntentSender sender = AuthActivity.getAuthIntentSenderForDataset(context, datasetName);
//datasetBuilder.SetAuthentication(sender);
}
else
{
Debug.WriteLine("These fields are not meant to be saved by autofill.");
return null;
datasetBuilder = new Dataset.Builder(
BuildListView(context.PackageName, filledItem.Name, filledItem.Subtitle, filledItem.Icon));
}
if(filledItem.ApplyToFields(fields, datasetBuilder))
{
return datasetBuilder.Build();
}
return null;
}
public static RemoteViews BuildListView(string packageName, string text, string subtext, int iconId)
{
var view = new RemoteViews(packageName, Resource.Layout.autofill_listitem);
view.SetTextViewText(Resource.Id.text, text);
view.SetTextViewText(Resource.Id.text2, subtext);
view.SetImageViewResource(Resource.Id.icon, iconId);
return view;
}
public static List<string> FilterForSupportedHints(string[] hints)
{
if(hints == null)
{
return new List<string>();
}
return hints.Where(h => IsValidHint(h)).ToList();
return hints?.Where(h => IsValidHint(h)).ToList() ?? new List<string>();
}
public static bool IsValidHint(string hint)

View File

@ -60,7 +60,7 @@ namespace Bit.Android.Autofill
return;
}
var response = AutofillHelpers.NewResponse(this, false, parser.FieldCollection, items);
var response = AutofillHelpers.BuildFillResponse(this, false, parser.FieldCollection, items);
callback.OnSuccess(response);
}

View File

@ -23,6 +23,7 @@ namespace Bit.Android.Autofill
{
case CipherType.Login:
Subtitle = _cipher.Login.Username?.Decrypt() ?? string.Empty;
Icon = Resource.Drawable.login;
break;
default:
break;
@ -31,6 +32,7 @@ namespace Bit.Android.Autofill
public string Name { get; set; }
public string Subtitle { get; set; } = string.Empty;
public int Icon { get; set; } = Resource.Drawable.login;
public bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder)
{

View File

@ -18,12 +18,14 @@ namespace Bit.Android.Autofill
{
HintToFieldMap = hintMap;
Name = datasetName;
Subtitle = "username";
Subtitle = "subtitle";
Icon = Resource.Drawable.login;
}
public IDictionary<string, FilledField> HintToFieldMap { get; private set; }
public string Name { get; set; }
public string Subtitle { get; set; }
public int Icon { get; set; }
public void Add(FilledField filledField)
{

View File

@ -7,6 +7,7 @@ namespace Bit.Android.Autofill
{
string Name { get; set; }
string Subtitle { get; set; }
int Icon { get; set; }
bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder);
}
}

View File

@ -2,7 +2,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="?android:attr/listPreferredItemPaddingEnd"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@color/lightgray"
android:orientation="horizontal">
<ImageView
@ -10,8 +13,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
android:src="@drawable/user" />
android:layout_marginEnd="10dp"
android:src="@drawable/login" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"