mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
layout updates
This commit is contained in:
parent
1694b5d6fd
commit
0a6767209d
6 changed files with 47 additions and 66 deletions
|
@ -4,60 +4,13 @@ using Android.Content;
|
||||||
using Android.Service.Autofill;
|
using Android.Service.Autofill;
|
||||||
using Android.Views;
|
using Android.Views;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Bit.Android.Autofill
|
namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
public static class AutofillHelpers
|
public static class AutofillHelpers
|
||||||
{
|
{
|
||||||
/**
|
public static FillResponse BuildFillResponse(Context context, bool auth, FieldCollection fields,
|
||||||
* 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,
|
|
||||||
IDictionary<string, IFilledItem> items)
|
IDictionary<string, IFilledItem> items)
|
||||||
{
|
{
|
||||||
var responseBuilder = new FillResponse.Builder();
|
var responseBuilder = new FillResponse.Builder();
|
||||||
|
@ -65,7 +18,7 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
foreach(var datasetName in items.Keys)
|
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)
|
if(dataset != null)
|
||||||
{
|
{
|
||||||
responseBuilder.AddDataset(dataset);
|
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();
|
datasetBuilder = new Dataset.Builder(
|
||||||
responseBuilder.SetSaveInfo(info);
|
BuildListView(context.PackageName, filledItem.Name, filledItem.Subtitle, Resource.Drawable.fa_lock));
|
||||||
return responseBuilder.Build();
|
//IntentSender sender = AuthActivity.getAuthIntentSenderForDataset(context, datasetName);
|
||||||
|
//datasetBuilder.SetAuthentication(sender);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine("These fields are not meant to be saved by autofill.");
|
datasetBuilder = new Dataset.Builder(
|
||||||
return null;
|
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)
|
public static List<string> FilterForSupportedHints(string[] hints)
|
||||||
{
|
{
|
||||||
if(hints == null)
|
return hints?.Where(h => IsValidHint(h)).ToList() ?? new List<string>();
|
||||||
{
|
|
||||||
return new List<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return hints.Where(h => IsValidHint(h)).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsValidHint(string hint)
|
public static bool IsValidHint(string hint)
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace Bit.Android.Autofill
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = AutofillHelpers.NewResponse(this, false, parser.FieldCollection, items);
|
var response = AutofillHelpers.BuildFillResponse(this, false, parser.FieldCollection, items);
|
||||||
callback.OnSuccess(response);
|
callback.OnSuccess(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
case CipherType.Login:
|
case CipherType.Login:
|
||||||
Subtitle = _cipher.Login.Username?.Decrypt() ?? string.Empty;
|
Subtitle = _cipher.Login.Username?.Decrypt() ?? string.Empty;
|
||||||
|
Icon = Resource.Drawable.login;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -31,6 +32,7 @@ namespace Bit.Android.Autofill
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Subtitle { get; set; } = string.Empty;
|
public string Subtitle { get; set; } = string.Empty;
|
||||||
|
public int Icon { get; set; } = Resource.Drawable.login;
|
||||||
|
|
||||||
public bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder)
|
public bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,12 +18,14 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
HintToFieldMap = hintMap;
|
HintToFieldMap = hintMap;
|
||||||
Name = datasetName;
|
Name = datasetName;
|
||||||
Subtitle = "username";
|
Subtitle = "subtitle";
|
||||||
|
Icon = Resource.Drawable.login;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDictionary<string, FilledField> HintToFieldMap { get; private set; }
|
public IDictionary<string, FilledField> HintToFieldMap { get; private set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Subtitle { get; set; }
|
public string Subtitle { get; set; }
|
||||||
|
public int Icon { get; set; }
|
||||||
|
|
||||||
public void Add(FilledField filledField)
|
public void Add(FilledField filledField)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Bit.Android.Autofill
|
||||||
{
|
{
|
||||||
string Name { get; set; }
|
string Name { get; set; }
|
||||||
string Subtitle { get; set; }
|
string Subtitle { get; set; }
|
||||||
|
int Icon { get; set; }
|
||||||
bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder);
|
bool ApplyToFields(FieldCollection fieldCollection, Dataset.Builder datasetBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,10 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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:background="@color/lightgray"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<ImageView
|
<ImageView
|
||||||
|
@ -10,8 +13,8 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
|
android:layout_marginEnd="10dp"
|
||||||
android:src="@drawable/user" />
|
android:src="@drawable/login" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue