2019-05-11 06:43:35 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using System;
|
|
|
|
|
using Xamarin.Forms;
|
2019-05-10 21:33:33 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public partial class AttachmentsPage : BaseContentPage
|
|
|
|
|
{
|
|
|
|
|
private AttachmentsPageViewModel _vm;
|
2019-05-11 06:43:35 +03:00
|
|
|
|
private readonly IBroadcasterService _broadcasterService;
|
2019-05-10 21:33:33 +03:00
|
|
|
|
|
|
|
|
|
public AttachmentsPage(string cipherId)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-05-11 06:43:35 +03:00
|
|
|
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
2019-05-10 21:33:33 +03:00
|
|
|
|
_vm = BindingContext as AttachmentsPageViewModel;
|
|
|
|
|
_vm.Page = this;
|
|
|
|
|
_vm.CipherId = cipherId;
|
|
|
|
|
SetActivityIndicator();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
2019-06-12 04:31:51 +03:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.RemoveAt(0);
|
|
|
|
|
}
|
2019-05-10 21:33:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async void OnAppearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnAppearing();
|
2019-05-23 03:54:44 +03:00
|
|
|
|
_broadcasterService.Subscribe(nameof(AttachmentsPage), (message) =>
|
2019-05-11 06:43:35 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (message.Command == "selectFileResult")
|
2019-05-11 06:43:35 +03:00
|
|
|
|
{
|
2019-05-30 18:40:33 +03:00
|
|
|
|
Device.BeginInvokeOnMainThread(() =>
|
|
|
|
|
{
|
|
|
|
|
var data = message.Data as Tuple<byte[], string>;
|
|
|
|
|
_vm.FileData = data.Item1;
|
|
|
|
|
_vm.FileName = data.Item2;
|
|
|
|
|
});
|
2019-05-11 06:43:35 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
await LoadOnAppearedAsync(_scrollView, true, () => _vm.InitAsync());
|
2019-05-10 21:33:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
|
|
|
|
base.OnDisappearing();
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (Device.RuntimePlatform != Device.iOS)
|
2019-06-26 00:46:37 +03:00
|
|
|
|
{
|
|
|
|
|
_broadcasterService.Unsubscribe(nameof(AttachmentsPage));
|
|
|
|
|
}
|
2019-05-10 21:33:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-11 06:43:35 +03:00
|
|
|
|
private async void Save_Clicked(object sender, EventArgs e)
|
2019-05-10 21:33:33 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (DoOnce())
|
2019-05-10 21:33:33 +03:00
|
|
|
|
{
|
|
|
|
|
await _vm.SubmitAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-11 06:43:35 +03:00
|
|
|
|
|
|
|
|
|
private async void ChooseFile_Clicked(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (DoOnce())
|
2019-05-11 06:43:35 +03:00
|
|
|
|
{
|
|
|
|
|
await _vm.ChooseFileAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-12 04:31:51 +03:00
|
|
|
|
|
|
|
|
|
private async void Close_Clicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (DoOnce())
|
2019-06-12 04:31:51 +03:00
|
|
|
|
{
|
|
|
|
|
await Navigation.PopModalAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-10 21:33:33 +03:00
|
|
|
|
}
|
|
|
|
|
}
|