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