1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-04 08:50:18 +01:00
bitwarden-mobile/src/App/Pages/Vault/GroupingsPage/GroupingsPage.xaml.cs

105 lines
3.3 KiB
C#
Raw Normal View History

2019-04-19 22:45:16 +02:00
using Bit.Core.Abstractions;
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()
: 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;
_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);
}
else if(item.Folder != null)
{
await _viewModel.SelectFolderAsync(item.Folder);
}
else if(item.Collection != null)
2019-04-24 17:23:03 +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
}
private async void Search_Clicked(object sender, System.EventArgs e)
{
await Navigation.PushModalAsync(new CiphersPage(), false);
}
2019-03-29 18:24:44 +01:00
}
}