mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
set custom icons server url
This commit is contained in:
parent
2d126300d8
commit
746a7c404b
9 changed files with 85 additions and 14 deletions
|
@ -15,5 +15,6 @@ namespace Bit.App.Abstractions
|
||||||
string WebVaultUrl { get; set; }
|
string WebVaultUrl { get; set; }
|
||||||
string ApiUrl { get; set; }
|
string ApiUrl { get; set; }
|
||||||
string IdentityUrl { get; set; }
|
string IdentityUrl { get; set; }
|
||||||
|
string IconsUrl { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,6 +40,7 @@
|
||||||
public const string WebVaultUrl = "other:webVaultUrl";
|
public const string WebVaultUrl = "other:webVaultUrl";
|
||||||
public const string ApiUrl = "other:apiUrl";
|
public const string ApiUrl = "other:apiUrl";
|
||||||
public const string IdentityUrl = "other:identityUrl";
|
public const string IdentityUrl = "other:identityUrl";
|
||||||
|
public const string IconsUrl = "other:iconsUrl";
|
||||||
|
|
||||||
public const int SelectFileRequestCode = 42;
|
public const int SelectFileRequestCode = 42;
|
||||||
public const int SelectFilePermissionRequestCode = 43;
|
public const int SelectFilePermissionRequestCode = 43;
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Bit.App.Enums;
|
using Bit.App.Enums;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
|
||||||
namespace Bit.App.Models.Page
|
namespace Bit.App.Models.Page
|
||||||
{
|
{
|
||||||
|
@ -10,7 +11,7 @@ namespace Bit.App.Models.Page
|
||||||
{
|
{
|
||||||
public class Cipher
|
public class Cipher
|
||||||
{
|
{
|
||||||
public Cipher(Models.Cipher cipher, bool imageEnabled)
|
public Cipher(Models.Cipher cipher, IAppSettingsService appSettings)
|
||||||
{
|
{
|
||||||
Id = cipher.Id;
|
Id = cipher.Id;
|
||||||
Shared = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
|
Shared = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
|
||||||
|
@ -30,6 +31,7 @@ namespace Bit.App.Models.Page
|
||||||
Icon = "login.png";
|
Icon = "login.png";
|
||||||
var hostnameUri = LoginUri;
|
var hostnameUri = LoginUri;
|
||||||
var isWebsite = false;
|
var isWebsite = false;
|
||||||
|
var imageEnabled = !appSettings.DisableWebsiteIcons;
|
||||||
if(hostnameUri.StartsWith("androidapp://"))
|
if(hostnameUri.StartsWith("androidapp://"))
|
||||||
{
|
{
|
||||||
Icon = "android.png";
|
Icon = "android.png";
|
||||||
|
@ -50,7 +52,20 @@ namespace Bit.App.Models.Page
|
||||||
|
|
||||||
if(imageEnabled && isWebsite && Uri.TryCreate(hostnameUri, UriKind.Absolute, out Uri u))
|
if(imageEnabled && isWebsite && Uri.TryCreate(hostnameUri, UriKind.Absolute, out Uri u))
|
||||||
{
|
{
|
||||||
Icon = "https://icons.bitwarden.com/" + u.Host + "/icon.png";
|
var iconsUrl = appSettings.IconsUrl;
|
||||||
|
if(string.IsNullOrWhiteSpace(iconsUrl))
|
||||||
|
{
|
||||||
|
if(!string.IsNullOrWhiteSpace(appSettings.BaseUrl))
|
||||||
|
{
|
||||||
|
iconsUrl = $"{appSettings.BaseUrl}/icons";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iconsUrl = "https://icons.bitwarden.com";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Icon = $"{iconsUrl}/{u.Host}/icon.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
Subtitle = LoginUsername;
|
Subtitle = LoginUsername;
|
||||||
|
@ -122,8 +137,8 @@ namespace Bit.App.Models.Page
|
||||||
|
|
||||||
public class AutofillCipher : Cipher
|
public class AutofillCipher : Cipher
|
||||||
{
|
{
|
||||||
public AutofillCipher(Models.Cipher cipher, bool imageEnabled, bool fuzzy = false)
|
public AutofillCipher(Models.Cipher cipher, IAppSettingsService appSettings, bool fuzzy = false)
|
||||||
: base(cipher, imageEnabled)
|
: base(cipher, appSettings)
|
||||||
{
|
{
|
||||||
Fuzzy = fuzzy;
|
Fuzzy = fuzzy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Bit.App.Pages
|
||||||
public FormEntryCell WebVaultUrlCell { get; set; }
|
public FormEntryCell WebVaultUrlCell { get; set; }
|
||||||
public FormEntryCell ApiUrlCell { get; set; }
|
public FormEntryCell ApiUrlCell { get; set; }
|
||||||
public FormEntryCell IdentityUrlCell { get; set; }
|
public FormEntryCell IdentityUrlCell { get; set; }
|
||||||
|
public FormEntryCell IconsUrlCell { get; set; }
|
||||||
public StackLayout StackLayout { get; set; }
|
public StackLayout StackLayout { get; set; }
|
||||||
public Label SelfHostLabel { get; set; }
|
public Label SelfHostLabel { get; set; }
|
||||||
public Label CustomLabel { get; set; }
|
public Label CustomLabel { get; set; }
|
||||||
|
@ -37,13 +38,23 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
MessagingCenter.Send(Application.Current, "ShowStatusBar", true);
|
MessagingCenter.Send(Application.Current, "ShowStatusBar", true);
|
||||||
|
|
||||||
IdentityUrlCell = new FormEntryCell(AppResources.IdentityUrl, entryKeyboard: Keyboard.Url);
|
IconsUrlCell = new FormEntryCell(AppResources.IconsUrl, entryKeyboard: Keyboard.Url);
|
||||||
|
IconsUrlCell.Entry.Text = _appSettings.IconsUrl;
|
||||||
|
|
||||||
|
IdentityUrlCell = new FormEntryCell(AppResources.IdentityUrl, nextElement: IconsUrlCell.Entry,
|
||||||
|
entryKeyboard: Keyboard.Url);
|
||||||
IdentityUrlCell.Entry.Text = _appSettings.IdentityUrl;
|
IdentityUrlCell.Entry.Text = _appSettings.IdentityUrl;
|
||||||
ApiUrlCell = new FormEntryCell(AppResources.ApiUrl, nextElement: IdentityUrlCell.Entry, entryKeyboard: Keyboard.Url);
|
|
||||||
|
ApiUrlCell = new FormEntryCell(AppResources.ApiUrl, nextElement: IdentityUrlCell.Entry,
|
||||||
|
entryKeyboard: Keyboard.Url);
|
||||||
ApiUrlCell.Entry.Text = _appSettings.ApiUrl;
|
ApiUrlCell.Entry.Text = _appSettings.ApiUrl;
|
||||||
WebVaultUrlCell = new FormEntryCell(AppResources.WebVaultUrl, nextElement: ApiUrlCell.Entry, entryKeyboard: Keyboard.Url);
|
|
||||||
|
WebVaultUrlCell = new FormEntryCell(AppResources.WebVaultUrl, nextElement: ApiUrlCell.Entry,
|
||||||
|
entryKeyboard: Keyboard.Url);
|
||||||
WebVaultUrlCell.Entry.Text = _appSettings.WebVaultUrl;
|
WebVaultUrlCell.Entry.Text = _appSettings.WebVaultUrl;
|
||||||
BaseUrlCell = new FormEntryCell(AppResources.ServerUrl, nextElement: WebVaultUrlCell.Entry, entryKeyboard: Keyboard.Url);
|
|
||||||
|
BaseUrlCell = new FormEntryCell(AppResources.ServerUrl, nextElement: WebVaultUrlCell.Entry,
|
||||||
|
entryKeyboard: Keyboard.Url);
|
||||||
BaseUrlCell.Entry.Text = _appSettings.BaseUrl;
|
BaseUrlCell.Entry.Text = _appSettings.BaseUrl;
|
||||||
|
|
||||||
var table = new FormTableView
|
var table = new FormTableView
|
||||||
|
@ -74,7 +85,8 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
WebVaultUrlCell,
|
WebVaultUrlCell,
|
||||||
ApiUrlCell,
|
ApiUrlCell,
|
||||||
IdentityUrlCell
|
IdentityUrlCell,
|
||||||
|
IconsUrlCell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -122,6 +134,7 @@ namespace Bit.App.Pages
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
MessagingCenter.Send(Application.Current, "ShowStatusBar", true);
|
MessagingCenter.Send(Application.Current, "ShowStatusBar", true);
|
||||||
BaseUrlCell.InitEvents();
|
BaseUrlCell.InitEvents();
|
||||||
|
IconsUrlCell.InitEvents();
|
||||||
IdentityUrlCell.InitEvents();
|
IdentityUrlCell.InitEvents();
|
||||||
ApiUrlCell.InitEvents();
|
ApiUrlCell.InitEvents();
|
||||||
WebVaultUrlCell.InitEvents();
|
WebVaultUrlCell.InitEvents();
|
||||||
|
@ -132,6 +145,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
BaseUrlCell.Dispose();
|
BaseUrlCell.Dispose();
|
||||||
|
IconsUrlCell.Dispose();
|
||||||
IdentityUrlCell.Dispose();
|
IdentityUrlCell.Dispose();
|
||||||
ApiUrlCell.Dispose();
|
ApiUrlCell.Dispose();
|
||||||
WebVaultUrlCell.Dispose();
|
WebVaultUrlCell.Dispose();
|
||||||
|
@ -204,7 +218,22 @@ namespace Bit.App.Pages
|
||||||
IdentityUrlCell.Entry.Text = null;
|
IdentityUrlCell.Entry.Text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!string.IsNullOrWhiteSpace(IconsUrlCell.Entry.Text))
|
||||||
|
{
|
||||||
|
IconsUrlCell.Entry.Text = FixUrl(IconsUrlCell.Entry.Text);
|
||||||
|
if(!Uri.TryCreate(IconsUrlCell.Entry.Text, UriKind.Absolute, out result))
|
||||||
|
{
|
||||||
|
_userDialogs.Alert(string.Format(AppResources.FormattedIncorrectly, AppResources.IconsUrl));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IconsUrlCell.Entry.Text = null;
|
||||||
|
}
|
||||||
|
|
||||||
_appSettings.BaseUrl = BaseUrlCell.Entry.Text;
|
_appSettings.BaseUrl = BaseUrlCell.Entry.Text;
|
||||||
|
_appSettings.IconsUrl = IconsUrlCell.Entry.Text;
|
||||||
_appSettings.IdentityUrl = IdentityUrlCell.Entry.Text;
|
_appSettings.IdentityUrl = IdentityUrlCell.Entry.Text;
|
||||||
_appSettings.ApiUrl = ApiUrlCell.Entry.Text;
|
_appSettings.ApiUrl = ApiUrlCell.Entry.Text;
|
||||||
_appSettings.WebVaultUrl = WebVaultUrlCell.Entry.Text;
|
_appSettings.WebVaultUrl = WebVaultUrlCell.Entry.Text;
|
||||||
|
|
|
@ -161,7 +161,6 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
_filterResultsCancellationTokenSource?.Cancel();
|
_filterResultsCancellationTokenSource?.Cancel();
|
||||||
var websiteIconsEnabled = !_appSettingsService.DisableWebsiteIcons;
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
@ -169,7 +168,7 @@ namespace Bit.App.Pages
|
||||||
var ciphers = await _cipherService.GetAllAsync(Uri);
|
var ciphers = await _cipherService.GetAllAsync(Uri);
|
||||||
|
|
||||||
var normalLogins = ciphers?.Item1.Select(l => new VaultListPageModel.AutofillCipher(
|
var normalLogins = ciphers?.Item1.Select(l => new VaultListPageModel.AutofillCipher(
|
||||||
l, websiteIconsEnabled, false))
|
l, _appSettingsService, false))
|
||||||
.OrderBy(s => s.Name)
|
.OrderBy(s => s.Name)
|
||||||
.ThenBy(s => s.Subtitle)
|
.ThenBy(s => s.Subtitle)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -179,7 +178,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
|
|
||||||
var fuzzyLogins = ciphers?.Item2.Select(l => new VaultListPageModel.AutofillCipher(
|
var fuzzyLogins = ciphers?.Item2.Select(l => new VaultListPageModel.AutofillCipher(
|
||||||
l, websiteIconsEnabled, true))
|
l, _appSettingsService, true))
|
||||||
.OrderBy(s => s.Name)
|
.OrderBy(s => s.Name)
|
||||||
.ThenBy(s => s.LoginUsername)
|
.ThenBy(s => s.LoginUsername)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
|
@ -311,7 +311,6 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
|
|
||||||
_filterResultsCancellationTokenSource?.Cancel();
|
_filterResultsCancellationTokenSource?.Cancel();
|
||||||
var websiteIconsEnabled = !_appSettingsService.DisableWebsiteIcons;
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
@ -328,7 +327,7 @@ namespace Bit.App.Pages
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
Ciphers = ciphers
|
Ciphers = ciphers
|
||||||
.Select(s => new VaultListPageModel.Cipher(s, websiteIconsEnabled))
|
.Select(s => new VaultListPageModel.Cipher(s, _appSettingsService))
|
||||||
.OrderBy(s => s.Name)
|
.OrderBy(s => s.Name)
|
||||||
.ThenBy(s => s.Subtitle)
|
.ThenBy(s => s.Subtitle)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
9
src/App/Resources/AppResources.Designer.cs
generated
9
src/App/Resources/AppResources.Designer.cs
generated
|
@ -1456,6 +1456,15 @@ namespace Bit.App.Resources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Icons Server URL.
|
||||||
|
/// </summary>
|
||||||
|
public static string IconsUrl {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("IconsUrl", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Identity Server URL.
|
/// Looks up a localized string similar to Identity Server URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1182,4 +1182,7 @@
|
||||||
<data name="DisableWebsiteIconsDescription" xml:space="preserve">
|
<data name="DisableWebsiteIconsDescription" xml:space="preserve">
|
||||||
<value>Website Icons provide a recognizable image next to each login item in your vault.</value>
|
<value>Website Icons provide a recognizable image next to each login item in your vault.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="IconsUrl" xml:space="preserve">
|
||||||
|
<value>Icons Server URL</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -169,5 +169,20 @@ namespace Bit.App.Services
|
||||||
_settings.AddOrUpdateValue(Constants.IdentityUrl, value);
|
_settings.AddOrUpdateValue(Constants.IdentityUrl, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string IconsUrl
|
||||||
|
{
|
||||||
|
get => _settings.GetValueOrDefault(Constants.IconsUrl, null);
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(value == null)
|
||||||
|
{
|
||||||
|
_settings.Remove(Constants.IconsUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_settings.AddOrUpdateValue(Constants.IconsUrl, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue