2019-04-19 22:45:16 +02:00
|
|
|
|
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-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;
|
|
|
|
|
private readonly GroupingsPageViewModel _viewModel;
|
2019-03-29 18:24:44 +01:00
|
|
|
|
|
|
|
|
|
public GroupingsPage()
|
2019-04-24 22:50:34 +02:00
|
|
|
|
: this(true)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public GroupingsPage(bool mainPage, CipherType? type = null, string folderId = null,
|
|
|
|
|
string collectionId = null, string pageTitle = null)
|
2019-03-29 18:24:44 +01:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-05-01 16:20:05 +02:00
|
|
|
|
SetActivityIndicator();
|
2019-04-19 22:45:16 +02:00
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
|
|
|
|
_syncService = ServiceContainer.Resolve<ISyncService>("syncService");
|
2019-03-29 18:24:44 +01:00
|
|
|
|
_viewModel = BindingContext as GroupingsPageViewModel;
|
2019-04-24 17:23:03 +02:00
|
|
|
|
_viewModel.Page = this;
|
2019-04-24 22:50:34 +02:00
|
|
|
|
_viewModel.MainPage = mainPage;
|
|
|
|
|
_viewModel.Type = type;
|
|
|
|
|
_viewModel.FolderId = folderId;
|
|
|
|
|
_viewModel.CollectionId = collectionId;
|
|
|
|
|
if(pageTitle != null)
|
|
|
|
|
{
|
|
|
|
|
_viewModel.PageTitle = pageTitle;
|
|
|
|
|
}
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected async override void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2019-04-26 22:58:20 +02:00
|
|
|
|
// await _syncService.FullSyncAsync(true);
|
2019-04-19 22:45:16 +02:00
|
|
|
|
_broadcasterService.Subscribe(nameof(GroupingsPage), async (message) =>
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
await _viewModel.LoadAsync();
|
|
|
|
|
}
|
2019-05-01 16:20:05 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(5000);
|
|
|
|
|
if(!_viewModel.Loaded)
|
|
|
|
|
{
|
|
|
|
|
await _viewModel.LoadAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-04-19 22:45:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
|
|
|
|
_broadcasterService.Unsubscribe(nameof(GroupingsPage));
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
2019-04-24 17:23:03 +02:00
|
|
|
|
|
|
|
|
|
private async void RowSelected(object sender, SelectedItemChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(!(e.SelectedItem is GroupingsPageListItem item))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(item.Cipher != null)
|
|
|
|
|
{
|
|
|
|
|
await _viewModel.SelectCipherAsync(item.Cipher);
|
|
|
|
|
}
|
2019-04-24 22:50:34 +02:00
|
|
|
|
else if(item.Folder != null)
|
|
|
|
|
{
|
|
|
|
|
await _viewModel.SelectFolderAsync(item.Folder);
|
|
|
|
|
}
|
|
|
|
|
else if(item.Collection != null)
|
2019-04-24 17:23:03 +02:00
|
|
|
|
{
|
2019-04-24 22:50:34 +02:00
|
|
|
|
await _viewModel.SelectCollectionAsync(item.Collection);
|
2019-04-24 17:23:03 +02:00
|
|
|
|
}
|
2019-05-01 17:31:00 +02:00
|
|
|
|
else if(item.Type != null)
|
|
|
|
|
{
|
|
|
|
|
await _viewModel.SelectTypeAsync(item.Type.Value);
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
await Navigation.PushModalAsync(new CiphersPage(), false);
|
|
|
|
|
}
|
2019-03-29 18:24:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|