2019-04-24 18:23:03 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using System.Collections.Generic;
|
2019-05-02 21:53:45 +03:00
|
|
|
|
using Xamarin.Forms;
|
2019-04-24 18:23:03 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2019-05-01 17:11:49 +03:00
|
|
|
|
public partial class ViewPage : BaseContentPage
|
2019-04-24 18:23:03 +03:00
|
|
|
|
{
|
|
|
|
|
private readonly IBroadcasterService _broadcasterService;
|
|
|
|
|
private ViewPageViewModel _vm;
|
|
|
|
|
|
|
|
|
|
public ViewPage(string cipherId)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
|
|
|
|
_vm = BindingContext as ViewPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
|
|
|
|
_vm.CipherId = cipherId;
|
2019-05-09 21:12:30 +03:00
|
|
|
|
SetActivityIndicator(_mainContent);
|
|
|
|
|
|
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
|
|
|
|
{
|
|
|
|
|
_absLayout.Children.Remove(_fab);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.RemoveAt(0);
|
|
|
|
|
_fab.Clicked = EditButton_Clicked;
|
|
|
|
|
_mainLayout.Padding = new Thickness(0, 0, 0, 75);
|
|
|
|
|
}
|
2019-04-24 18:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-01 17:11:49 +03:00
|
|
|
|
protected override async void OnAppearing()
|
2019-04-24 18:23:03 +03:00
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
|
|
|
|
_broadcasterService.Subscribe(nameof(ViewPage), async (message) =>
|
|
|
|
|
{
|
|
|
|
|
if(message.Command == "syncCompleted")
|
|
|
|
|
{
|
|
|
|
|
var data = message.Data as Dictionary<string, object>;
|
|
|
|
|
if(data.ContainsKey("successfully"))
|
|
|
|
|
{
|
|
|
|
|
var success = data["successfully"] as bool?;
|
|
|
|
|
if(success.HasValue && success.Value)
|
|
|
|
|
{
|
|
|
|
|
await _vm.LoadAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-05-09 21:12:30 +03:00
|
|
|
|
await LoadOnAppearedAsync(_scrollView, true, () => _vm.LoadAsync(), _mainContent);
|
2019-05-10 20:47:59 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.Android)
|
|
|
|
|
{
|
|
|
|
|
if(_vm.Cipher.OrganizationId == null)
|
|
|
|
|
{
|
|
|
|
|
if(ToolbarItems.Contains(_collectionsItem))
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Remove(_collectionsItem);
|
|
|
|
|
}
|
|
|
|
|
if(!ToolbarItems.Contains(_shareItem))
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Insert(1, _shareItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(ToolbarItems.Contains(_shareItem))
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Remove(_shareItem);
|
|
|
|
|
}
|
|
|
|
|
if(!ToolbarItems.Contains(_collectionsItem))
|
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Insert(1, _collectionsItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-24 18:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
_broadcasterService.Unsubscribe(nameof(ViewPage));
|
2019-04-26 07:26:09 +03:00
|
|
|
|
_vm.CleanUp();
|
2019-04-24 18:23:03 +03:00
|
|
|
|
}
|
2019-05-02 21:53:45 +03:00
|
|
|
|
|
|
|
|
|
private async void PasswordHistory_Tapped(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2019-05-07 06:22:48 +03:00
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new PasswordHistoryPage(_vm.CipherId)));
|
|
|
|
|
}
|
2019-05-02 21:53:45 +03:00
|
|
|
|
}
|
2019-05-07 18:25:21 +03:00
|
|
|
|
|
|
|
|
|
private async void EditToolbarItem_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(new AddEditPage(_vm.CipherId)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-09 21:12:30 +03:00
|
|
|
|
|
|
|
|
|
private void EditButton_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EditToolbarItem_Clicked(sender, e);
|
|
|
|
|
}
|
2019-05-10 20:47:59 +03:00
|
|
|
|
|
2019-05-11 06:43:35 +03:00
|
|
|
|
private async void Attachments_Clicked(object sender, System.EventArgs e)
|
2019-05-10 20:47:59 +03:00
|
|
|
|
{
|
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
2019-05-11 06:43:35 +03:00
|
|
|
|
var page = new AttachmentsPage(_vm.CipherId);
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
2019-05-10 20:47:59 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Share_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
|
|
|
|
var page = new SharePage(_vm.CipherId);
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Delete_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
|
|
|
|
await _vm.DeleteAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 21:28:17 +03:00
|
|
|
|
private async void Collections_Clicked(object sender, System.EventArgs e)
|
2019-05-10 20:47:59 +03:00
|
|
|
|
{
|
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
2019-05-10 21:28:17 +03:00
|
|
|
|
var page = new CollectionsPage(_vm.CipherId);
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
2019-05-10 20:47:59 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-24 18:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|