bitwarden-android/src/App/Models/Page/VaultListPageModel.cs

132 lines
4.8 KiB
C#
Raw Normal View History

2016-05-02 09:52:09 +03:00
using System;
using System.Collections.Generic;
using Bit.App.Resources;
using System.Linq;
using Bit.App.Enums;
2016-05-02 09:52:09 +03:00
namespace Bit.App.Models.Page
2016-05-02 09:52:09 +03:00
{
public class VaultListPageModel
2016-05-02 09:52:09 +03:00
{
public class Cipher
2016-05-02 09:52:09 +03:00
{
public Cipher(Models.Cipher cipher)
2016-05-02 09:52:09 +03:00
{
Id = cipher.Id;
Shared = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
HasAttachments = cipher.Attachments?.Any() ?? false;
FolderId = cipher.FolderId;
Name = cipher.Name?.Decrypt(cipher.OrganizationId);
Type = cipher.Type;
switch(cipher.Type)
{
case CipherType.Login:
2017-10-20 19:47:05 +03:00
LoginUsername = cipher.Login?.Username?.Decrypt(cipher.OrganizationId) ?? " ";
LoginPassword = new Lazy<string>(() => cipher.Login?.Password?.Decrypt(cipher.OrganizationId));
LoginUri = new Lazy<string>(() => cipher.Login?.Uri?.Decrypt(cipher.OrganizationId));
LoginTotp = new Lazy<string>(() => cipher.Login?.Totp?.Decrypt(cipher.OrganizationId));
2017-10-20 19:47:05 +03:00
Subtitle = LoginUsername;
break;
case CipherType.SecureNote:
Subtitle = " ";
break;
case CipherType.Card:
2017-10-20 19:47:05 +03:00
CardNumber = cipher.Card?.Number?.Decrypt(cipher.OrganizationId) ?? " ";
var cardBrand = cipher.Card?.Brand?.Decrypt(cipher.OrganizationId) ?? " ";
CardCode = new Lazy<string>(() => cipher.Card?.Code?.Decrypt(cipher.OrganizationId));
2017-10-20 19:47:05 +03:00
Subtitle = cardBrand;
if(!string.IsNullOrWhiteSpace(CardNumber) && CardNumber.Length >= 4)
{
if(!string.IsNullOrWhiteSpace(CardNumber))
{
Subtitle += ", ";
}
Subtitle += ("*" + CardNumber.Substring(CardNumber.Length - 4));
}
break;
case CipherType.Identity:
var firstName = cipher.Identity?.FirstName?.Decrypt(cipher.OrganizationId) ?? " ";
var lastName = cipher.Identity?.LastName?.Decrypt(cipher.OrganizationId) ?? " ";
2017-10-20 19:47:05 +03:00
Subtitle = " ";
if(!string.IsNullOrWhiteSpace(firstName))
{
Subtitle = firstName;
}
if(!string.IsNullOrWhiteSpace(lastName))
{
if(!string.IsNullOrWhiteSpace(Subtitle))
{
Subtitle += " ";
}
Subtitle += lastName;
}
break;
default:
break;
}
2016-05-02 09:52:09 +03:00
}
2016-05-03 09:08:50 +03:00
public string Id { get; set; }
2017-04-24 22:00:55 +03:00
public bool Shared { get; set; }
public bool HasAttachments { get; set; }
2016-05-04 02:49:49 +03:00
public string FolderId { get; set; }
2016-05-02 09:52:09 +03:00
public string Name { get; set; }
public string Subtitle { get; set; }
public CipherType Type { get; set; }
// Login metadata
2017-10-20 19:47:05 +03:00
public string LoginUsername { get; set; }
public Lazy<string> LoginPassword { get; set; }
public Lazy<string> LoginUri { get; set; }
public Lazy<string> LoginTotp { get; set; }
// Login metadata
public string CardNumber { get; set; }
public Lazy<string> CardCode { get; set; }
2016-05-02 09:52:09 +03:00
}
public class AutofillCipher : Cipher
2017-02-14 06:10:34 +03:00
{
public AutofillCipher(Models.Cipher cipher, bool fuzzy = false)
: base(cipher)
2017-02-14 06:10:34 +03:00
{
Fuzzy = fuzzy;
}
public bool Fuzzy { get; set; }
}
public class Folder : List<Cipher>
2016-05-02 09:52:09 +03:00
{
2016-07-11 08:12:31 +03:00
public Folder(Models.Folder folder)
2016-05-02 09:52:09 +03:00
{
2016-07-11 08:12:31 +03:00
Id = folder.Id;
Name = folder.Name?.Decrypt();
2016-05-02 09:52:09 +03:00
}
public Folder(List<Cipher> ciphers)
2016-05-02 09:52:09 +03:00
{
AddRange(ciphers);
2016-05-02 09:52:09 +03:00
}
2016-05-03 09:08:50 +03:00
public string Id { get; set; }
public string Name { get; set; } = AppResources.FolderNone;
2016-05-02 09:52:09 +03:00
}
public class AutofillGrouping : List<AutofillCipher>
{
public AutofillGrouping(List<AutofillCipher> logins, string name)
{
AddRange(logins);
Name = name;
}
public string Name { get; set; }
}
2016-05-02 09:52:09 +03:00
}
}