2021-02-11 03:50:10 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Resources;
|
|
|
|
|
using Bit.App.Utilities;
|
2022-01-21 12:31:03 +03:00
|
|
|
|
using Bit.Core;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
using Bit.Core.Models.View;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Xamarin.Essentials;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Pages
|
|
|
|
|
{
|
|
|
|
|
public class SendAddEditPageViewModel : BaseViewModel
|
|
|
|
|
{
|
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
|
|
|
|
private readonly IPlatformUtilsService _platformUtilsService;
|
2021-02-23 01:45:41 +03:00
|
|
|
|
private readonly IMessagingService _messagingService;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
private readonly IStateService _stateService;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private readonly ISendService _sendService;
|
2022-03-02 20:15:16 +03:00
|
|
|
|
private readonly ILogger _logger;
|
2021-02-19 00:58:20 +03:00
|
|
|
|
private bool _sendEnabled;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private bool _canAccessPremium;
|
2021-04-07 23:42:00 +03:00
|
|
|
|
private bool _emailVerified;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private SendView _send;
|
2021-02-12 22:20:07 +03:00
|
|
|
|
private string _fileName;
|
2021-02-16 23:24:51 +03:00
|
|
|
|
private bool _showOptions;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private bool _showPassword;
|
|
|
|
|
private int _deletionDateTypeSelectedIndex;
|
|
|
|
|
private int _expirationDateTypeSelectedIndex;
|
2021-03-12 04:52:35 +03:00
|
|
|
|
private DateTime _simpleDeletionDateTime;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private DateTime _deletionDate;
|
|
|
|
|
private TimeSpan _deletionTime;
|
2021-03-12 04:52:35 +03:00
|
|
|
|
private DateTime? _simpleExpirationDateTime;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
private DateTime? _expirationDate;
|
|
|
|
|
private TimeSpan? _expirationTime;
|
|
|
|
|
private bool _isOverridingPickers;
|
|
|
|
|
private int? _maxAccessCount;
|
|
|
|
|
private string[] _additionalSendProperties = new []
|
|
|
|
|
{
|
|
|
|
|
nameof(IsText),
|
|
|
|
|
nameof(IsFile),
|
|
|
|
|
};
|
2021-03-29 19:01:42 +03:00
|
|
|
|
private bool _disableHideEmail;
|
|
|
|
|
private bool _sendOptionsPolicyInEffect;
|
2022-01-25 23:41:56 +03:00
|
|
|
|
private bool _copyInsteadOfShareAfterSaving;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
|
|
|
|
|
public SendAddEditPageViewModel()
|
|
|
|
|
{
|
|
|
|
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
|
|
|
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
2021-02-23 01:45:41 +03:00
|
|
|
|
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
2022-02-23 20:40:17 +03:00
|
|
|
|
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
2021-02-11 03:50:10 +03:00
|
|
|
|
_sendService = ServiceContainer.Resolve<ISendService>("sendService");
|
2022-03-02 20:15:16 +03:00
|
|
|
|
_logger = ServiceContainer.Resolve<ILogger>("logger");
|
|
|
|
|
|
2021-02-11 03:50:10 +03:00
|
|
|
|
TogglePasswordCommand = new Command(TogglePassword);
|
|
|
|
|
|
|
|
|
|
TypeOptions = new List<KeyValuePair<string, SendType>>
|
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<string, SendType>(AppResources.TypeText, SendType.Text),
|
|
|
|
|
new KeyValuePair<string, SendType>(AppResources.TypeFile, SendType.File),
|
|
|
|
|
};
|
|
|
|
|
DeletionTypeOptions = new List<KeyValuePair<string, string>>
|
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.OneHour, AppResources.OneHour),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.OneDay, AppResources.OneDay),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.TwoDays, AppResources.TwoDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.ThreeDays, AppResources.ThreeDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.SevenDays, AppResources.SevenDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.ThirtyDays, AppResources.ThirtyDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.Custom, AppResources.Custom),
|
|
|
|
|
};
|
|
|
|
|
ExpirationTypeOptions = new List<KeyValuePair<string, string>>
|
|
|
|
|
{
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.Never, AppResources.Never),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.OneHour, AppResources.OneHour),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.OneDay, AppResources.OneDay),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.TwoDays, AppResources.TwoDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.ThreeDays, AppResources.ThreeDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.SevenDays, AppResources.SevenDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.ThirtyDays, AppResources.ThirtyDays),
|
|
|
|
|
new KeyValuePair<string, string>(AppResources.Custom, AppResources.Custom),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Command TogglePasswordCommand { get; set; }
|
|
|
|
|
public string SendId { get; set; }
|
2021-02-11 22:38:30 +03:00
|
|
|
|
public int SegmentedButtonHeight { get; set; }
|
|
|
|
|
public int SegmentedButtonFontSize { get; set; }
|
|
|
|
|
public Thickness SegmentedButtonMargins { get; set; }
|
|
|
|
|
public bool ShowEditorSeparators { get; set; }
|
|
|
|
|
public Thickness EditorMargins { get; set; }
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public SendType? Type { get; set; }
|
|
|
|
|
public byte[] FileData { get; set; }
|
|
|
|
|
public string NewPassword { get; set; }
|
|
|
|
|
public bool ShareOnSave { get; set; }
|
2021-03-29 19:01:42 +03:00
|
|
|
|
public bool DisableHideEmailControl { get; set; }
|
2021-03-31 17:19:05 +03:00
|
|
|
|
public bool IsAddFromShare { get; set; }
|
2022-01-25 23:41:56 +03:00
|
|
|
|
public string ShareOnSaveText => CopyInsteadOfShareAfterSaving ? AppResources.CopySendLinkOnSave : AppResources.ShareOnSave;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public List<KeyValuePair<string, SendType>> TypeOptions { get; }
|
|
|
|
|
public List<KeyValuePair<string, string>> DeletionTypeOptions { get; }
|
|
|
|
|
public List<KeyValuePair<string, string>> ExpirationTypeOptions { get; }
|
2021-02-19 00:58:20 +03:00
|
|
|
|
public bool SendEnabled
|
|
|
|
|
{
|
|
|
|
|
get => _sendEnabled;
|
|
|
|
|
set => SetProperty(ref _sendEnabled, value);
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public int DeletionDateTypeSelectedIndex
|
|
|
|
|
{
|
|
|
|
|
get => _deletionDateTypeSelectedIndex;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _deletionDateTypeSelectedIndex, value))
|
|
|
|
|
{
|
|
|
|
|
DeletionTypeChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public DateTime DeletionDate
|
|
|
|
|
{
|
|
|
|
|
get => _deletionDate;
|
|
|
|
|
set => SetProperty(ref _deletionDate, value);
|
|
|
|
|
}
|
|
|
|
|
public TimeSpan DeletionTime
|
|
|
|
|
{
|
|
|
|
|
get => _deletionTime;
|
|
|
|
|
set => SetProperty(ref _deletionTime, value);
|
|
|
|
|
}
|
2021-02-16 23:24:51 +03:00
|
|
|
|
public bool ShowOptions
|
|
|
|
|
{
|
|
|
|
|
get => _showOptions;
|
|
|
|
|
set => SetProperty(ref _showOptions, value);
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public int ExpirationDateTypeSelectedIndex
|
|
|
|
|
{
|
|
|
|
|
get => _expirationDateTypeSelectedIndex;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _expirationDateTypeSelectedIndex, value))
|
|
|
|
|
{
|
|
|
|
|
ExpirationTypeChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public DateTime? ExpirationDate
|
|
|
|
|
{
|
|
|
|
|
get => _expirationDate;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _expirationDate, value))
|
|
|
|
|
{
|
|
|
|
|
ExpirationDateChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public TimeSpan? ExpirationTime
|
|
|
|
|
{
|
|
|
|
|
get => _expirationTime;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _expirationTime, value))
|
|
|
|
|
{
|
|
|
|
|
ExpirationTimeChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int? MaxAccessCount
|
|
|
|
|
{
|
|
|
|
|
get => _maxAccessCount;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _maxAccessCount, value))
|
|
|
|
|
{
|
|
|
|
|
MaxAccessCountChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-25 23:41:56 +03:00
|
|
|
|
public bool CopyInsteadOfShareAfterSaving
|
|
|
|
|
{
|
|
|
|
|
get => _copyInsteadOfShareAfterSaving;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetProperty(ref _copyInsteadOfShareAfterSaving, value);
|
|
|
|
|
TriggerPropertyChanged(nameof(ShareOnSaveText));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public SendView Send
|
|
|
|
|
{
|
|
|
|
|
get => _send;
|
|
|
|
|
set => SetProperty(ref _send, value, additionalPropertyNames: _additionalSendProperties);
|
|
|
|
|
}
|
2021-02-12 22:20:07 +03:00
|
|
|
|
public string FileName
|
|
|
|
|
{
|
|
|
|
|
get => _fileName;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (SetProperty(ref _fileName, value))
|
|
|
|
|
{
|
|
|
|
|
Send.File.FileName = _fileName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public bool ShowPassword
|
|
|
|
|
{
|
|
|
|
|
get => _showPassword;
|
|
|
|
|
set => SetProperty(ref _showPassword, value,
|
|
|
|
|
additionalPropertyNames: new []
|
|
|
|
|
{
|
|
|
|
|
nameof(ShowPasswordIcon)
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-03-29 19:01:42 +03:00
|
|
|
|
public bool DisableHideEmail
|
|
|
|
|
{
|
|
|
|
|
get => _disableHideEmail;
|
|
|
|
|
set => SetProperty(ref _disableHideEmail, value);
|
|
|
|
|
}
|
|
|
|
|
public bool SendOptionsPolicyInEffect
|
|
|
|
|
{
|
|
|
|
|
get => _sendOptionsPolicyInEffect;
|
|
|
|
|
set => SetProperty(ref _sendOptionsPolicyInEffect, value);
|
|
|
|
|
}
|
2021-03-31 17:19:05 +03:00
|
|
|
|
public bool ShowTypeButtons => !EditMode && !IsAddFromShare;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public bool EditMode => !string.IsNullOrWhiteSpace(SendId);
|
|
|
|
|
public bool IsText => Send?.Type == SendType.Text;
|
|
|
|
|
public bool IsFile => Send?.Type == SendType.File;
|
|
|
|
|
public bool ShowDeletionCustomPickers => EditMode || DeletionDateTypeSelectedIndex == 6;
|
|
|
|
|
public bool ShowExpirationCustomPickers => EditMode || ExpirationDateTypeSelectedIndex == 7;
|
2022-01-21 12:31:03 +03:00
|
|
|
|
public string ShowPasswordIcon => ShowPassword ? BitwardenIcons.EyeSlash : BitwardenIcons.Eye;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
|
2021-02-19 00:58:20 +03:00
|
|
|
|
public async Task InitAsync()
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
|
|
|
|
PageTitle = EditMode ? AppResources.EditSend : AppResources.AddSend;
|
2022-02-23 20:40:17 +03:00
|
|
|
|
_canAccessPremium = await _stateService.CanAccessPremiumAsync();
|
|
|
|
|
_emailVerified = await _stateService.GetEmailVerifiedAsync();
|
2021-02-19 00:58:20 +03:00
|
|
|
|
SendEnabled = ! await AppHelpers.IsSendDisabledByPolicyAsync();
|
2021-03-29 19:01:42 +03:00
|
|
|
|
DisableHideEmail = await AppHelpers.IsHideEmailDisabledByPolicyAsync();
|
|
|
|
|
SendOptionsPolicyInEffect = SendEnabled && DisableHideEmail;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> LoadAsync()
|
|
|
|
|
{
|
|
|
|
|
if (Send == null)
|
|
|
|
|
{
|
2021-02-12 22:20:07 +03:00
|
|
|
|
_isOverridingPickers = true;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
if (EditMode)
|
|
|
|
|
{
|
|
|
|
|
var send = await _sendService.GetAsync(SendId);
|
|
|
|
|
if (send == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Send = await send.DecryptAsync();
|
2021-02-12 22:20:07 +03:00
|
|
|
|
DeletionDate = Send.DeletionDate.ToLocalTime();
|
2021-03-12 04:52:35 +03:00
|
|
|
|
DeletionTime = DeletionDate.TimeOfDay;
|
2021-02-12 22:20:07 +03:00
|
|
|
|
ExpirationDate = Send.ExpirationDate?.ToLocalTime();
|
2021-03-12 04:52:35 +03:00
|
|
|
|
ExpirationTime = ExpirationDate?.TimeOfDay;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-07 23:42:00 +03:00
|
|
|
|
var defaultType = _canAccessPremium && _emailVerified ? SendType.File : SendType.Text;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
Send = new SendView
|
|
|
|
|
{
|
2021-02-12 00:27:22 +03:00
|
|
|
|
Type = Type.GetValueOrDefault(defaultType),
|
2021-02-11 03:50:10 +03:00
|
|
|
|
};
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_deletionDate = DateTimeNow().AddDays(7);
|
|
|
|
|
_deletionTime = DeletionDate.TimeOfDay;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
DeletionDateTypeSelectedIndex = 4;
|
|
|
|
|
ExpirationDateTypeSelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaxAccessCount = Send.MaxAccessCount;
|
|
|
|
|
_isOverridingPickers = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 19:01:42 +03:00
|
|
|
|
DisableHideEmailControl = !SendEnabled ||
|
|
|
|
|
(!EditMode && DisableHideEmail) ||
|
|
|
|
|
(EditMode && DisableHideEmail && !Send.HideEmail);
|
|
|
|
|
|
2021-02-11 03:50:10 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ChooseFileAsync()
|
|
|
|
|
{
|
|
|
|
|
await _deviceActionService.SelectFileAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearExpirationDate()
|
|
|
|
|
{
|
|
|
|
|
_isOverridingPickers = true;
|
|
|
|
|
ExpirationDate = null;
|
|
|
|
|
ExpirationTime = null;
|
|
|
|
|
_isOverridingPickers = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateSendData()
|
|
|
|
|
{
|
|
|
|
|
// filename
|
|
|
|
|
if (Send.File != null && FileName != null)
|
|
|
|
|
{
|
|
|
|
|
Send.File.FileName = FileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deletion date
|
|
|
|
|
if (ShowDeletionCustomPickers)
|
|
|
|
|
{
|
|
|
|
|
Send.DeletionDate = DeletionDate.Date.Add(DeletionTime).ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-12 04:52:35 +03:00
|
|
|
|
Send.DeletionDate = _simpleDeletionDateTime.ToUniversalTime();
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// expiration date
|
2021-03-12 04:52:35 +03:00
|
|
|
|
if (ShowExpirationCustomPickers && ExpirationDate.HasValue && ExpirationTime.HasValue)
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
2021-03-12 04:52:35 +03:00
|
|
|
|
Send.ExpirationDate = ExpirationDate.Value.Date.Add(ExpirationTime.Value).ToUniversalTime();
|
|
|
|
|
}
|
|
|
|
|
else if (_simpleExpirationDateTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
Send.ExpirationDate = _simpleExpirationDateTime.Value.ToUniversalTime();
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Send.ExpirationDate = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> SubmitAsync()
|
|
|
|
|
{
|
2021-02-19 00:58:20 +03:00
|
|
|
|
if (Send == null || !SendEnabled)
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (Connectivity.NetworkAccess == NetworkAccess.None)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.InternetConnectionRequiredMessage,
|
|
|
|
|
AppResources.InternetConnectionRequiredTitle);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrWhiteSpace(Send.Name))
|
|
|
|
|
{
|
|
|
|
|
await Page.DisplayAlert(AppResources.AnErrorHasOccurred,
|
|
|
|
|
string.Format(AppResources.ValidationFieldRequired, AppResources.Name),
|
|
|
|
|
AppResources.Ok);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (IsFile)
|
|
|
|
|
{
|
|
|
|
|
if (!_canAccessPremium)
|
|
|
|
|
{
|
2021-03-31 17:19:05 +03:00
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.SendFilePremiumRequired);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-07 23:42:00 +03:00
|
|
|
|
if (!_emailVerified)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.SendFileEmailVerificationRequired);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-12 22:20:07 +03:00
|
|
|
|
if (!EditMode)
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
2021-02-12 22:20:07 +03:00
|
|
|
|
if (FileData == null)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(
|
|
|
|
|
string.Format(AppResources.ValidationFieldRequired, AppResources.File),
|
|
|
|
|
AppResources.AnErrorHasOccurred);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-27 23:14:54 +03:00
|
|
|
|
if (FileData.Length > 104857600) // 100 MB
|
2021-02-12 22:20:07 +03:00
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.MaxFileSize,
|
|
|
|
|
AppResources.AnErrorHasOccurred);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateSendData();
|
|
|
|
|
|
2021-03-01 20:07:04 +03:00
|
|
|
|
if (string.IsNullOrWhiteSpace(NewPassword))
|
|
|
|
|
{
|
|
|
|
|
NewPassword = null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 03:50:10 +03:00
|
|
|
|
var (send, encryptedFileData) = await _sendService.EncryptAsync(Send, FileData, NewPassword);
|
|
|
|
|
if (send == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _deviceActionService.ShowLoadingAsync(AppResources.Saving);
|
|
|
|
|
var sendId = await _sendService.SaveWithServerAsync(send, encryptedFileData);
|
|
|
|
|
await _deviceActionService.HideLoadingAsync();
|
|
|
|
|
|
2021-02-23 01:45:41 +03:00
|
|
|
|
if (Device.RuntimePlatform == Device.Android && IsFile)
|
|
|
|
|
{
|
|
|
|
|
// Workaround for https://github.com/xamarin/Xamarin.Forms/issues/5418
|
|
|
|
|
// Exiting and returning (file picker) calls OnAppearing on list page instead of this modal, and
|
|
|
|
|
// it doesn't get called again when the model is dismissed, so the list isn't updated.
|
|
|
|
|
_messagingService.Send("sendUpdated");
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 00:49:01 +03:00
|
|
|
|
if (!ShareOnSave)
|
2021-03-31 17:19:05 +03:00
|
|
|
|
{
|
|
|
|
|
_platformUtilsService.ShowToast("success", null,
|
|
|
|
|
EditMode ? AppResources.SendUpdated : AppResources.NewSendCreated);
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
|
2022-01-25 23:41:56 +03:00
|
|
|
|
if (!CopyInsteadOfShareAfterSaving)
|
2021-11-19 23:00:54 +03:00
|
|
|
|
{
|
2022-01-25 23:41:56 +03:00
|
|
|
|
await CloseAsync();
|
2021-11-19 23:00:54 +03:00
|
|
|
|
}
|
2022-01-25 23:41:56 +03:00
|
|
|
|
|
2021-04-28 00:49:01 +03:00
|
|
|
|
if (ShareOnSave)
|
|
|
|
|
{
|
|
|
|
|
var savedSend = await _sendService.GetAsync(sendId);
|
|
|
|
|
if (savedSend != null)
|
|
|
|
|
{
|
|
|
|
|
var savedSendView = await savedSend.DecryptAsync();
|
2022-01-25 23:41:56 +03:00
|
|
|
|
if (CopyInsteadOfShareAfterSaving)
|
|
|
|
|
{
|
|
|
|
|
await AppHelpers.CopySendUrlAsync(savedSendView);
|
|
|
|
|
|
|
|
|
|
// wait so that the user sees the message before the view gets dismissed
|
|
|
|
|
await Task.Delay(1300);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await AppHelpers.ShareSendUrlAsync(savedSendView);
|
|
|
|
|
}
|
2021-04-28 00:49:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-25 23:41:56 +03:00
|
|
|
|
|
|
|
|
|
if (CopyInsteadOfShareAfterSaving)
|
|
|
|
|
{
|
|
|
|
|
await CloseAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 03:50:10 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (ApiException e)
|
|
|
|
|
{
|
|
|
|
|
await _deviceActionService.HideLoadingAsync();
|
|
|
|
|
if (e?.Error != null)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(e.Error.GetSingleMessage(),
|
|
|
|
|
AppResources.AnErrorHasOccurred);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-25 23:41:56 +03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await _deviceActionService.HideLoadingAsync();
|
2022-03-02 20:15:16 +03:00
|
|
|
|
_logger.Exception(ex);
|
2022-01-25 23:41:56 +03:00
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.AnErrorHasOccurred);
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 23:41:56 +03:00
|
|
|
|
private async Task CloseAsync()
|
|
|
|
|
{
|
|
|
|
|
if (IsAddFromShare)
|
|
|
|
|
{
|
|
|
|
|
if (Device.RuntimePlatform == Device.Android)
|
|
|
|
|
{
|
|
|
|
|
_deviceActionService.CloseMainApp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Page is SendAddEditPage sendPage && sendPage.OnClose != null)
|
|
|
|
|
{
|
|
|
|
|
sendPage.OnClose();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Page.Navigation.PopModalAsync();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 03:50:10 +03:00
|
|
|
|
public async Task<bool> RemovePasswordAsync()
|
|
|
|
|
{
|
|
|
|
|
return await AppHelpers.RemoveSendPasswordAsync(SendId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task CopyLinkAsync()
|
|
|
|
|
{
|
2021-02-19 00:58:20 +03:00
|
|
|
|
await AppHelpers.CopySendUrlAsync(Send);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task ShareLinkAsync()
|
|
|
|
|
{
|
2021-02-19 00:58:20 +03:00
|
|
|
|
await AppHelpers.ShareSendUrlAsync(Send);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DeleteAsync()
|
|
|
|
|
{
|
|
|
|
|
return await AppHelpers.DeleteSendAsync(SendId);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 00:58:20 +03:00
|
|
|
|
public async Task TypeChangedAsync(SendType type)
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
2021-03-31 17:19:05 +03:00
|
|
|
|
if (!SendEnabled)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.SendDisabledWarning);
|
2022-01-25 23:41:56 +03:00
|
|
|
|
await CloseAsync();
|
2021-03-31 17:19:05 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-11 22:38:30 +03:00
|
|
|
|
if (Send != null)
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
2021-04-07 23:42:00 +03:00
|
|
|
|
if (!EditMode && type == SendType.File && (!_canAccessPremium || !_emailVerified))
|
2021-02-11 03:50:10 +03:00
|
|
|
|
{
|
2021-04-07 23:42:00 +03:00
|
|
|
|
if (!_canAccessPremium)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.SendFilePremiumRequired);
|
|
|
|
|
}
|
|
|
|
|
else if (!_emailVerified)
|
|
|
|
|
{
|
|
|
|
|
await _platformUtilsService.ShowDialogAsync(AppResources.SendFileEmailVerificationRequired);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 17:19:05 +03:00
|
|
|
|
if (IsAddFromShare && Device.RuntimePlatform == Device.Android)
|
|
|
|
|
{
|
|
|
|
|
_deviceActionService.CloseMainApp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-11 22:38:30 +03:00
|
|
|
|
type = SendType.Text;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
2021-02-11 22:38:30 +03:00
|
|
|
|
Send.Type = type;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
TriggerPropertyChanged(nameof(Send), _additionalSendProperties);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-17 18:46:04 +03:00
|
|
|
|
|
2021-02-16 23:24:51 +03:00
|
|
|
|
public void ToggleOptions()
|
|
|
|
|
{
|
|
|
|
|
ShowOptions = !ShowOptions;
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
|
|
|
|
|
private void DeletionTypeChanged()
|
|
|
|
|
{
|
|
|
|
|
if (Send != null && DeletionDateTypeSelectedIndex > -1)
|
|
|
|
|
{
|
|
|
|
|
_isOverridingPickers = true;
|
|
|
|
|
switch (DeletionDateTypeSelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddHours(1);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddDays(1);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddDays(2);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddDays(3);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddDays(7);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleDeletionDateTime = DateTimeNow().AddDays(30);
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
// custom option, initial values already set elsewhere
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_isOverridingPickers = false;
|
|
|
|
|
TriggerPropertyChanged(nameof(ShowDeletionCustomPickers));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExpirationTypeChanged()
|
|
|
|
|
{
|
|
|
|
|
if (Send != null && ExpirationDateTypeSelectedIndex > -1)
|
|
|
|
|
{
|
|
|
|
|
_isOverridingPickers = true;
|
|
|
|
|
switch (ExpirationDateTypeSelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = null;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddHours(1);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddDays(1);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddDays(2);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddDays(3);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddDays(7);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 6:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
_simpleExpirationDateTime = DateTimeNow().AddDays(30);
|
2021-02-11 03:50:10 +03:00
|
|
|
|
break;
|
|
|
|
|
case 7:
|
2021-03-12 04:52:35 +03:00
|
|
|
|
// custom option, clear all expiration values
|
|
|
|
|
_simpleExpirationDateTime = null;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
ClearExpirationDate();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_isOverridingPickers = false;
|
|
|
|
|
TriggerPropertyChanged(nameof(ShowExpirationCustomPickers));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExpirationDateChanged()
|
|
|
|
|
{
|
|
|
|
|
if (!_isOverridingPickers && !ExpirationTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// auto-set time to current time upon setting date
|
2021-02-12 22:20:07 +03:00
|
|
|
|
ExpirationTime = DateTimeNow().TimeOfDay;
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ExpirationTimeChanged()
|
|
|
|
|
{
|
|
|
|
|
if (!_isOverridingPickers && !ExpirationDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
// auto-set date to current date upon setting time
|
|
|
|
|
ExpirationDate = DateTime.Today;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MaxAccessCountChanged()
|
|
|
|
|
{
|
|
|
|
|
Send.MaxAccessCount = _maxAccessCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TogglePassword()
|
|
|
|
|
{
|
|
|
|
|
ShowPassword = !ShowPassword;
|
|
|
|
|
}
|
2021-02-12 22:20:07 +03:00
|
|
|
|
|
|
|
|
|
private DateTime DateTimeNow()
|
|
|
|
|
{
|
|
|
|
|
var dtn = DateTime.Now;
|
|
|
|
|
return new DateTime(
|
|
|
|
|
dtn.Year,
|
|
|
|
|
dtn.Month,
|
|
|
|
|
dtn.Day,
|
|
|
|
|
dtn.Hour,
|
|
|
|
|
dtn.Minute,
|
|
|
|
|
0,
|
|
|
|
|
DateTimeKind.Local
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-02-11 03:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|