using Bit.Core.Abstractions; using Bit.Core.Utilities; using System; using Xamarin.Forms; namespace Bit.App.Pages { public partial class AttachmentsPage : BaseContentPage { private AttachmentsPageViewModel _vm; private readonly IBroadcasterService _broadcasterService; public AttachmentsPage(string cipherId) { InitializeComponent(); _broadcasterService = ServiceContainer.Resolve("broadcasterService"); _vm = BindingContext as AttachmentsPageViewModel; _vm.Page = this; _vm.CipherId = cipherId; SetActivityIndicator(); } protected override async void OnAppearing() { base.OnAppearing(); _broadcasterService.Subscribe(nameof(AttachmentsPage), (message) => { if(message.Command == "selectFileResult") { Device.BeginInvokeOnMainThread(() => { var data = message.Data as Tuple; _vm.FileData = data.Item1; _vm.FileName = data.Item2; }); } }); await LoadOnAppearedAsync(_scrollView, true, () => _vm.InitAsync()); } protected override void OnDisappearing() { base.OnDisappearing(); _broadcasterService.Unsubscribe(nameof(AttachmentsPage)); } private async void Save_Clicked(object sender, EventArgs e) { if(DoOnce()) { await _vm.SubmitAsync(); } } private async void ChooseFile_Clicked(object sender, EventArgs e) { if(DoOnce()) { await _vm.ChooseFileAsync(); } } } }