bitwarden-android/src/App/Pages/Vault/ViewPage.xaml.cs

157 lines
5 KiB
C#
Raw Normal View History

2019-04-24 11:23:03 -04:00
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System.Collections.Generic;
2019-05-02 14:53:45 -04:00
using Xamarin.Forms;
2019-04-24 11:23:03 -04:00
namespace Bit.App.Pages
{
public partial class ViewPage : BaseContentPage
2019-04-24 11:23:03 -04: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 14:12:30 -04: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 11:23:03 -04:00
}
protected override async void OnAppearing()
2019-04-24 11:23:03 -04:00
{
base.OnAppearing();
2019-06-03 11:26:16 -04:00
_broadcasterService.Subscribe(nameof(ViewPage), (message) =>
2019-04-24 11:23:03 -04:00
{
if(message.Command == "syncCompleted")
{
2019-05-30 11:40:33 -04:00
Device.BeginInvokeOnMainThread(() =>
2019-04-24 11:23:03 -04:00
{
2019-05-30 11:40:33 -04:00
var data = message.Data as Dictionary<string, object>;
if(data.ContainsKey("successfully"))
2019-04-24 11:23:03 -04:00
{
2019-05-30 11:40:33 -04:00
var success = data["successfully"] as bool?;
if(success.HasValue && success.Value)
{
var task = _vm.LoadAsync();
}
2019-04-24 11:23:03 -04:00
}
2019-05-30 11:40:33 -04:00
});
2019-04-24 11:23:03 -04:00
}
});
2019-05-30 08:40:10 -04:00
await LoadOnAppearedAsync(_scrollView, true, async () =>
{
var success = await _vm.LoadAsync();
if(!success)
{
await Navigation.PopModalAsync();
}
}, _mainContent);
2019-05-10 13:47:59 -04: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 11:23:03 -04:00
}
protected override void OnDisappearing()
{
base.OnDisappearing();
_broadcasterService.Unsubscribe(nameof(ViewPage));
2019-04-26 00:26:09 -04:00
_vm.CleanUp();
2019-04-24 11:23:03 -04:00
}
2019-05-02 14:53:45 -04:00
private async void PasswordHistory_Tapped(object sender, System.EventArgs e)
{
2019-05-06 23:22:48 -04:00
if(DoOnce())
{
await Navigation.PushModalAsync(new NavigationPage(new PasswordHistoryPage(_vm.CipherId)));
}
2019-05-02 14:53:45 -04:00
}
2019-05-07 11:25:21 -04: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 14:12:30 -04:00
private void EditButton_Clicked(object sender, System.EventArgs e)
{
EditToolbarItem_Clicked(sender, e);
}
2019-05-10 13:47:59 -04:00
2019-05-10 23:43:35 -04:00
private async void Attachments_Clicked(object sender, System.EventArgs e)
2019-05-10 13:47:59 -04:00
{
if(DoOnce())
{
2019-05-10 23:43:35 -04:00
var page = new AttachmentsPage(_vm.CipherId);
await Navigation.PushModalAsync(new NavigationPage(page));
2019-05-10 13:47:59 -04: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())
{
2019-05-30 08:35:50 -04:00
if(await _vm.DeleteAsync())
{
await Navigation.PopModalAsync();
}
2019-05-10 13:47:59 -04:00
}
}
2019-05-10 14:28:17 -04:00
private async void Collections_Clicked(object sender, System.EventArgs e)
2019-05-10 13:47:59 -04:00
{
if(DoOnce())
{
2019-05-10 14:28:17 -04:00
var page = new CollectionsPage(_vm.CipherId);
await Navigation.PushModalAsync(new NavigationPage(page));
2019-05-10 13:47:59 -04:00
}
}
2019-04-24 11:23:03 -04:00
}
}