1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-17 16:53:26 +00:00

wire up shared view controllers

This commit is contained in:
kspearrin
2018-09-20 22:53:23 -04:00
parent d32eb9c9bc
commit f57db917d1
15 changed files with 475 additions and 220 deletions

View File

@@ -17,6 +17,7 @@ using Bit.App.Resources;
using Bit.App.Models;
using Bit.App.Utilities;
using Bit.iOS.Core.Models;
using Bit.iOS.Core.Views;
namespace Bit.iOS.Autofill
{
@@ -62,14 +63,12 @@ namespace Bit.iOS.Autofill
var navController = segue.DestinationViewController as UINavigationController;
if(navController != null)
{
/*
var addLoginController = navController.TopViewController as LoginAddViewController;
if(addLoginController != null)
{
addLoginController.Context = Context;
addLoginController.LoginListController = this;
}
*/
}
}
@@ -82,87 +81,16 @@ namespace Bit.iOS.Autofill
});
}
public class TableSource : UITableViewSource
public class TableSource : ExtensionTableSource
{
private const string CellIdentifier = "TableCell";
private IEnumerable<CipherViewModel> _tableItems = new List<CipherViewModel>();
private Context _context;
private LoginListViewController _controller;
private ICipherService _cipherService;
private ISettings _settings;
private bool _accessPremium;
public TableSource(LoginListViewController controller)
:base(controller.Context, controller)
{
_context = controller.Context;
_controller = controller;
_accessPremium = Helpers.CanAccessPremium();
_cipherService = Resolver.Resolve<ICipherService>();
_settings = Resolver.Resolve<ISettings>();
}
public async Task LoadItemsAsync()
{
var combinedLogins = new List<Cipher>();
var logins = await _cipherService.GetAllAsync(_context.UrlString);
if(logins?.Item1 != null)
{
combinedLogins.AddRange(logins.Item1);
}
if(logins?.Item2 != null)
{
combinedLogins.AddRange(logins.Item2);
}
_tableItems = combinedLogins.Select(s => new CipherViewModel(s))
.OrderBy(s => s.Name)
.ThenBy(s => s.Username)
.ToList() ?? new List<CipherViewModel>();
}
public IEnumerable<CipherViewModel> TableItems { get; set; }
public override nint RowsInSection(UITableView tableview, nint section)
{
return _tableItems == null || _tableItems.Count() == 0 ? 1 : _tableItems.Count();
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
if(_tableItems == null || _tableItems.Count() == 0)
{
var noDataCell = new UITableViewCell(UITableViewCellStyle.Default, "NoDataCell");
noDataCell.TextLabel.Text = AppResources.NoItemsTap;
noDataCell.TextLabel.TextAlignment = UITextAlignment.Center;
noDataCell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
noDataCell.TextLabel.Lines = 0;
return noDataCell;
}
var cell = tableView.DequeueReusableCell(CellIdentifier);
// if there are no cells to reuse, create a new one
if(cell == null)
{
Debug.WriteLine("BW Log, Make new cell for list.");
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier);
cell.DetailTextLabel.TextColor = cell.DetailTextLabel.TintColor = new UIColor(red: 0.47f, green: 0.47f, blue: 0.47f, alpha: 1.0f);
}
return cell;
}
public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
if(_tableItems == null || _tableItems.Count() == 0 || cell == null)
{
return;
}
var item = _tableItems.ElementAt(indexPath.Row);
cell.TextLabel.Text = item.Name;
cell.DetailTextLabel.Text = item.Username;
}
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
@@ -254,20 +182,6 @@ namespace Bit.iOS.Autofill
_controller.PresentViewController(alert, true, null);
}
}
private string GetTotp(CipherViewModel item)
{
string totp = null;
if(_accessPremium)
{
if(item != null && !string.IsNullOrWhiteSpace(item.Totp.Value))
{
totp = Crypto.Totp(item.Totp.Value);
}
}
return totp;
}
}
}
}