2019-05-08 16:42:55 +02:00
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Bit.Core.Abstractions;
|
2019-04-24 22:50:34 +02:00
|
|
|
|
using Bit.Core.Enums;
|
2019-04-19 22:45:16 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
2019-05-14 15:48:40 +02:00
|
|
|
|
using System;
|
2019-03-29 18:24:44 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
2019-05-01 16:20:05 +02:00
|
|
|
|
public partial class GroupingsPage : BaseContentPage
|
2019-03-29 18:24:44 +01:00
|
|
|
|
{
|
2019-04-19 22:45:16 +02:00
|
|
|
|
private readonly IBroadcasterService _broadcasterService;
|
|
|
|
|
private readonly ISyncService _syncService;
|
2019-05-07 04:35:42 +02:00
|
|
|
|
private readonly GroupingsPageViewModel _vm;
|
2019-05-14 15:48:40 +02:00
|
|
|
|
private readonly string _pageName;
|
2019-04-24 22:50:34 +02:00
|
|
|
|
|
|
|
|
|
public GroupingsPage(bool mainPage, CipherType? type = null, string folderId = null,
|
|
|
|
|
string collectionId = null, string pageTitle = null)
|
2019-03-29 18:24:44 +01:00
|
|
|
|
{
|
2019-05-14 15:48:40 +02:00
|
|
|
|
_pageName = string.Concat(nameof(GroupingsPage), "_", DateTime.UtcNow.Ticks);
|
2019-03-29 18:24:44 +01:00
|
|
|
|
InitializeComponent();
|
2019-05-08 14:33:17 +02:00
|
|
|
|
SetActivityIndicator(_mainContent);
|
2019-04-19 22:45:16 +02:00
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
|
|
|
|
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
2019-05-07 04:35:42 +02:00
|
|
|
|
_vm = BindingContext as GroupingsPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
|
|
|
|
_vm.MainPage = mainPage;
|
|
|
|
|
_vm.Type = type;
|
|
|
|
|
_vm.FolderId = folderId;
|
|
|
|
|
_vm.CollectionId = collectionId;
|
2019-04-24 22:50:34 +02:00
|
|
|
|
if(pageTitle != null)
|
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
_vm.PageTitle = pageTitle;
|
2019-04-24 22:50:34 +02:00
|
|
|
|
}
|
2019-05-08 14:33:17 +02:00
|
|
|
|
|
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
|
|
|
|
{
|
|
|
|
|
_absLayout.Children.Remove(_fab);
|
|
|
|
|
}
|
2019-05-08 16:42:55 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_fab.Clicked = AddButton_Clicked;
|
|
|
|
|
}
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2019-05-14 15:48:40 +02:00
|
|
|
|
_broadcasterService.Subscribe(_pageName, async (message) =>
|
2019-04-19 22:45:16 +02:00
|
|
|
|
{
|
|
|
|
|
if(message.Command == "syncCompleted")
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(500);
|
|
|
|
|
// await _viewModel.LoadAsync();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-01 16:20:05 +02:00
|
|
|
|
await LoadOnAppearedAsync(_mainLayout, false, async () =>
|
2019-04-19 22:45:16 +02:00
|
|
|
|
{
|
2019-05-01 16:20:05 +02:00
|
|
|
|
if(!_syncService.SyncInProgress)
|
2019-04-19 22:45:16 +02:00
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.LoadAsync();
|
2019-04-19 22:45:16 +02:00
|
|
|
|
}
|
2019-05-01 16:20:05 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(5000);
|
2019-05-07 04:35:42 +02:00
|
|
|
|
if(!_vm.Loaded)
|
2019-05-01 16:20:05 +02:00
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.LoadAsync();
|
2019-05-01 16:20:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-08 14:33:17 +02:00
|
|
|
|
}, _mainContent);
|
2019-04-19 22:45:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
2019-05-14 15:48:40 +02:00
|
|
|
|
_broadcasterService.Unsubscribe(_pageName);
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
2019-04-24 17:23:03 +02:00
|
|
|
|
|
|
|
|
|
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
((ListView)sender).SelectedItem = null;
|
2019-05-07 04:49:57 +02:00
|
|
|
|
if(!DoOnce())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-24 17:23:03 +02:00
|
|
|
|
if(!(e.SelectedItem is GroupingsPageListItem item))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(item.Cipher != null)
|
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.SelectCipherAsync(item.Cipher);
|
2019-04-24 17:23:03 +02:00
|
|
|
|
}
|
2019-04-24 22:50:34 +02:00
|
|
|
|
else if(item.Folder != null)
|
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.SelectFolderAsync(item.Folder);
|
2019-04-24 22:50:34 +02:00
|
|
|
|
}
|
|
|
|
|
else if(item.Collection != null)
|
2019-04-24 17:23:03 +02:00
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.SelectCollectionAsync(item.Collection);
|
2019-04-24 17:23:03 +02:00
|
|
|
|
}
|
2019-05-01 17:31:00 +02:00
|
|
|
|
else if(item.Type != null)
|
|
|
|
|
{
|
2019-05-07 04:35:42 +02:00
|
|
|
|
await _vm.SelectTypeAsync(item.Type.Value);
|
2019-05-01 17:31:00 +02:00
|
|
|
|
}
|
2019-04-24 17:23:03 +02:00
|
|
|
|
}
|
2019-05-03 03:25:26 +02:00
|
|
|
|
|
|
|
|
|
private async void Search_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2019-05-07 05:07:47 +02:00
|
|
|
|
if(DoOnce())
|
|
|
|
|
{
|
|
|
|
|
var page = new CiphersPage(_vm.Filter, _vm.FolderId != null, _vm.CollectionId != null,
|
|
|
|
|
_vm.Type != null);
|
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page), false);
|
|
|
|
|
}
|
2019-05-03 03:25:26 +02:00
|
|
|
|
}
|
2019-05-08 16:42:55 +02:00
|
|
|
|
|
|
|
|
|
private async void AddButton_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2019-05-08 20:37:12 +02:00
|
|
|
|
var page = new AddEditPage(null, _vm.Type, _vm.FolderId, _vm.CollectionId);
|
2019-05-08 16:42:55 +02:00
|
|
|
|
await Navigation.PushModalAsync(new NavigationPage(page));
|
|
|
|
|
}
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|