1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-22 16:18:21 +01:00

Clipboard service and view site page

This commit is contained in:
Kyle Spearrin 2016-05-06 22:29:03 -04:00
parent 71be9f8780
commit d4b56e0e16
12 changed files with 192 additions and 39 deletions

View File

@ -197,6 +197,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Services\ClipboardService.cs" />
<Compile Include="Services\KeyStoreStorageService.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -50,6 +50,7 @@ namespace Bit.Android
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
// Repositories
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())

View File

@ -0,0 +1,15 @@
using Android.Content;
using Bit.App.Abstractions;
using Xamarin.Forms;
namespace Bit.Android.Services
{
public class ClipboardService : IClipboardService
{
public void CopyToClipboard(string text)
{
var clipboardManager = (ClipboardManager)Forms.Context.GetSystemService(Context.ClipboardService);
clipboardManager.Text = text;
}
}
}

View File

@ -0,0 +1,7 @@
namespace Bit.App.Abstractions
{
public interface IClipboardService
{
void CopyToClipboard(string text);
}
}

View File

@ -35,6 +35,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Abstractions\Services\IClipboardService.cs" />
<Compile Include="Abstractions\Services\ISiteService.cs" />
<Compile Include="Abstractions\Services\IFolderService.cs" />
<Compile Include="App.cs" />
@ -94,7 +95,6 @@
<Compile Include="Services\CryptoService.cs" />
<Compile Include="Models\View\VaultView.cs" />
<Compile Include="Pages\LoginPage.cs" />
<Compile Include="Pages\VaultEditFolderPage.cs" />
<Compile Include="Pages\VaultAddFolderPage.cs" />
<Compile Include="Pages\VaultAddSitePage.cs" />
<Compile Include="Pages\VaultViewSitePage.cs" />

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
namespace Bit.App.Pages
{
public class VaultEditFolderPage : ContentPage
{
public VaultEditFolderPage()
{
Title = "Edit Folder";
Content = null;
}
}
}

View File

@ -10,9 +10,9 @@ namespace Bit.App.Pages
{
public class VaultEditSitePage : ContentPage
{
public VaultEditSitePage()
public VaultEditSitePage(string siteId)
{
Title = "Edit Site";
Title = "Edit Site " + siteId;
Content = null;
}
}

View File

@ -67,7 +67,8 @@ namespace Bit.App.Pages
private void SiteSelected(object sender, SelectedItemChangedEventArgs e)
{
var site = e.SelectedItem as VaultView.Site;
Navigation.PushAsync(new VaultViewSitePage(site.Id));
}
private async void MoreClickedAsync(object sender, EventArgs e)
@ -121,17 +122,7 @@ namespace Bit.App.Pages
private async void ClickedItem(object sender, EventArgs e)
{
var selection = await _page.DisplayActionSheet("Add", "Cancel", null, "Add New Folder", "Add New Site");
if(selection == "Add New Folder")
{
var addFolderPage = new VaultAddFolderPage();
await _page.Navigation.PushAsync(addFolderPage);
}
else if(selection == "Add New Site")
{
var addSitePage = new VaultAddSitePage();
await _page.Navigation.PushAsync(addSitePage);
}
await _page.Navigation.PushAsync(new VaultAddSitePage());
}
}

View File

@ -3,21 +3,162 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Acr.UserDialogs;
using Bit.App.Abstractions;
using Xamarin.Forms;
using XLabs.Ioc;
namespace Bit.App.Pages
{
public class VaultViewSitePage : ContentPage
{
private int _siteId;
private readonly string _siteId;
private readonly ISiteService _siteService;
private readonly IUserDialogs _userDialogs;
private readonly IClipboardService _clipboardService;
public VaultViewSitePage(int siteId)
public VaultViewSitePage(string siteId)
{
_siteId = siteId;
_siteService = Resolver.Resolve<ISiteService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_clipboardService = Resolver.Resolve<IClipboardService>();
Title = "View Site";
Content = null;
Init();
}
public void Init()
{
ToolbarItems.Add(new EditSiteToolBarItem(this, _siteId));
var site = _siteService.GetByIdAsync(_siteId).GetAwaiter().GetResult();
if(site == null)
{
// TODO: handle error. navigate back? should never happen...
return;
}
var usernameRow = new StackLayout { Orientation = StackOrientation.Horizontal };
var usernameLabel = new Label
{
Text = site.Username?.Decrypt(),
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
};
usernameRow.Children.Add(usernameLabel);
usernameRow.Children.Add(new Button
{
Text = "Copy",
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Copy(usernameLabel.Text, "Username"))
});
var passwordRow = new StackLayout { Orientation = StackOrientation.Horizontal };
var password = site.Password?.Decrypt();
var passwordLabel = new Label
{
Text = new string('●', password.Length),
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
};
passwordRow.Children.Add(passwordLabel);
var togglePasswordButton = new Button
{
Text = "Show",
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command((self) => TogglePassword(self as Button, passwordLabel, password))
};
togglePasswordButton.CommandParameter = togglePasswordButton;
passwordRow.Children.Add(togglePasswordButton);
passwordRow.Children.Add(new Button
{
Text = "Copy",
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Copy(password, "Password"))
});
var uriRow = new StackLayout { Orientation = StackOrientation.Horizontal };
var uri = site.Uri?.Decrypt();
uriRow.Children.Add(new Label
{
Text = uri,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
LineBreakMode = LineBreakMode.TailTruncation
});
uriRow.Children.Add(new Button
{
Text = "Launch",
HorizontalOptions = LayoutOptions.End,
VerticalOptions = LayoutOptions.Center,
Command = new Command(() => Device.OpenUri(new Uri(uri)))
});
var stackLayout = new StackLayout();
stackLayout.Children.Add(new Label { Text = "Username" });
stackLayout.Children.Add(usernameRow);
stackLayout.Children.Add(new Label { Text = "Password" });
stackLayout.Children.Add(passwordRow);
stackLayout.Children.Add(new Label { Text = "Website" });
stackLayout.Children.Add(uriRow);
if(site.Notes != null)
{
stackLayout.Children.Add(new Label { Text = "Notes" });
stackLayout.Children.Add(new Label { Text = site.Notes.Decrypt() });
}
var scrollView = new ScrollView
{
Content = stackLayout,
Orientation = ScrollOrientation.Vertical
};
Title = site.Name?.Decrypt() ?? "No Name";
Content = scrollView;
}
public void TogglePassword(Button toggleButton, Label passwordLabel, string password)
{
if(toggleButton.Text == "Show")
{
toggleButton.Text = "Hide";
passwordLabel.Text = password;
}
else
{
toggleButton.Text = "Show";
passwordLabel.Text = new string('●', password.Length);
}
}
public void Copy(string copyText, string alertLabel)
{
_clipboardService.CopyToClipboard(copyText);
_userDialogs.SuccessToast($"{alertLabel} has been copied.");
}
private class EditSiteToolBarItem : ToolbarItem
{
private readonly VaultViewSitePage _page;
private readonly string _siteId;
public EditSiteToolBarItem(VaultViewSitePage page, string siteId)
{
_page = page;
_siteId = siteId;
Text = "Edit";
Clicked += ClickedItem;
}
private async void ClickedItem(object sender, EventArgs e)
{
await _page.Navigation.PushAsync(new VaultEditSitePage(_siteId));
}
}
}
}

View File

@ -58,6 +58,7 @@ namespace Bit.iOS
.RegisterType<IFolderService, FolderService>(new ContainerControlledLifetimeManager())
.RegisterType<ISiteService, SiteService>(new ContainerControlledLifetimeManager())
.RegisterType<ISyncService, SyncService>(new ContainerControlledLifetimeManager())
.RegisterType<IClipboardService, ClipboardService>(new ContainerControlledLifetimeManager())
// Repositories
.RegisterType<IFolderRepository, FolderRepository>(new ContainerControlledLifetimeManager())
.RegisterType<IFolderApiRepository, FolderApiRepository>(new ContainerControlledLifetimeManager())

View File

@ -0,0 +1,14 @@
using Bit.App.Abstractions;
using UIKit;
namespace Bit.iOS.Services
{
public class ClipboardService : IClipboardService
{
public void CopyToClipboard(string text)
{
UIPasteboard clipboard = UIPasteboard.General;
clipboard.String = text;
}
}
}

View File

@ -91,6 +91,7 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
<ItemGroup>
<Compile Include="Services\ClipboardService.cs" />
<Compile Include="Services\KeyChainStorageService.cs" />
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />