1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-29 12:45:20 +01:00

Send bugfixes & tweaks (#1262)

* bugfixes

* request name focus only if field is empty
This commit is contained in:
Matt Portune 2021-02-12 14:20:07 -05:00 committed by GitHub
parent d88695f5d5
commit a8acd36b1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 44 deletions

View File

@ -76,6 +76,19 @@
<ScrollView x:Key="scrollView" x:Name="_scrollView"> <ScrollView x:Key="scrollView" x:Name="_scrollView">
<StackLayout Spacing="20"> <StackLayout Spacing="20">
<StackLayout StyleClass="box"> <StackLayout StyleClass="box">
<StackLayout StyleClass="box-row">
<Label
Text="{u:I18n Name}"
StyleClass="box-label" />
<Entry
x:Name="_nameEntry"
Text="{Binding Send.Name}"
StyleClass="box-value" />
<Label
Text="{u:I18n NameInfo}"
StyleClass="box-footer-label"
Margin="0,5,0,0" />
</StackLayout>
<StackLayout StyleClass="box-row" <StackLayout StyleClass="box-row"
IsVisible="{Binding EditMode, Converter={StaticResource inverseBool}}"> IsVisible="{Binding EditMode, Converter={StaticResource inverseBool}}">
<Label <Label
@ -138,19 +151,6 @@
</Button> </Button>
</Grid> </Grid>
</StackLayout> </StackLayout>
<StackLayout StyleClass="box-row">
<Label
Text="{u:I18n Name}"
StyleClass="box-label" />
<Entry
x:Name="_nameEntry"
Text="{Binding Send.Name}"
StyleClass="box-value" />
<Label
Text="{u:I18n NameInfo}"
StyleClass="box-footer-label"
Margin="0,5,0,0" />
</StackLayout>
<StackLayout StyleClass="box-row" <StackLayout StyleClass="box-row"
IsVisible="{Binding IsText}"> IsVisible="{Binding IsText}">
<Label <Label
@ -244,13 +244,13 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<controls:ExtendedDatePicker <controls:ExtendedDatePicker
Date="{Binding DeletionDate}" NullableDate="{Binding DeletionDate, Mode=TwoWay}"
Format="d" Format="d"
AutomationProperties.IsInAccessibleTree="True" AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="{u:I18n DeletionDate}" AutomationProperties.Name="{u:I18n DeletionDate}"
Grid.Column="0" /> Grid.Column="0" />
<controls:ExtendedTimePicker <controls:ExtendedTimePicker
Time="{Binding DeletionTime}" NullableTime="{Binding DeletionTime, Mode=TwoWay}"
Format="t" Format="t"
AutomationProperties.IsInAccessibleTree="True" AutomationProperties.IsInAccessibleTree="True"
AutomationProperties.Name="{u:I18n DeletionTime}" AutomationProperties.Name="{u:I18n DeletionTime}"

View File

@ -111,11 +111,23 @@ namespace Bit.App.Pages
private void TextType_Clicked(object sender, EventArgs eventArgs) private void TextType_Clicked(object sender, EventArgs eventArgs)
{ {
_vm.TypeChanged(SendType.Text); _vm.TypeChanged(SendType.Text);
_nameEntry.ReturnType = ReturnType.Next;
_nameEntry.ReturnCommand = new Command(() => _textEditor.Focus());
if (string.IsNullOrWhiteSpace(_vm.Send.Name))
{
RequestFocus(_nameEntry);
}
} }
private void FileType_Clicked(object sender, EventArgs eventArgs) private void FileType_Clicked(object sender, EventArgs eventArgs)
{ {
_vm.TypeChanged(SendType.File); _vm.TypeChanged(SendType.File);
_nameEntry.ReturnType = ReturnType.Done;
_nameEntry.ReturnCommand = null;
if (string.IsNullOrWhiteSpace(_vm.Send.Name))
{
RequestFocus(_nameEntry);
}
} }
private void OnMaxAccessCountTextChanged(object sender, TextChangedEventArgs e) private void OnMaxAccessCountTextChanged(object sender, TextChangedEventArgs e)

View File

@ -21,6 +21,7 @@ namespace Bit.App.Pages
private readonly ISendService _sendService; private readonly ISendService _sendService;
private bool _canAccessPremium; private bool _canAccessPremium;
private SendView _send; private SendView _send;
private string _fileName;
private bool _showPassword; private bool _showPassword;
private int _deletionDateTypeSelectedIndex; private int _deletionDateTypeSelectedIndex;
private int _expirationDateTypeSelectedIndex; private int _expirationDateTypeSelectedIndex;
@ -79,7 +80,6 @@ namespace Bit.App.Pages
public bool ShowEditorSeparators { get; set; } public bool ShowEditorSeparators { get; set; }
public Thickness EditorMargins { get; set; } public Thickness EditorMargins { get; set; }
public SendType? Type { get; set; } public SendType? Type { get; set; }
public string FileName { get; set; }
public byte[] FileData { get; set; } public byte[] FileData { get; set; }
public string NewPassword { get; set; } public string NewPassword { get; set; }
public bool ShareOnSave { get; set; } public bool ShareOnSave { get; set; }
@ -156,6 +156,17 @@ namespace Bit.App.Pages
get => _send; get => _send;
set => SetProperty(ref _send, value, additionalPropertyNames: _additionalSendProperties); set => SetProperty(ref _send, value, additionalPropertyNames: _additionalSendProperties);
} }
public string FileName
{
get => _fileName;
set
{
if (SetProperty(ref _fileName, value))
{
Send.File.FileName = _fileName;
}
}
}
public bool ShowPassword public bool ShowPassword
{ {
get => _showPassword; get => _showPassword;
@ -184,6 +195,7 @@ namespace Bit.App.Pages
// TODO Policy Check // TODO Policy Check
if (Send == null) if (Send == null)
{ {
_isOverridingPickers = true;
if (EditMode) if (EditMode)
{ {
var send = await _sendService.GetAsync(SendId); var send = await _sendService.GetAsync(SendId);
@ -192,6 +204,8 @@ namespace Bit.App.Pages
return false; return false;
} }
Send = await send.DecryptAsync(); Send = await send.DecryptAsync();
DeletionDate = Send.DeletionDate.ToLocalTime();
ExpirationDate = Send.ExpirationDate?.ToLocalTime();
} }
else else
{ {
@ -199,17 +213,13 @@ namespace Bit.App.Pages
Send = new SendView Send = new SendView
{ {
Type = Type.GetValueOrDefault(defaultType), Type = Type.GetValueOrDefault(defaultType),
DeletionDate = DateTime.Now.AddDays(7),
}; };
DeletionDateTypeSelectedIndex = 4; DeletionDateTypeSelectedIndex = 4;
ExpirationDateTypeSelectedIndex = 0; ExpirationDateTypeSelectedIndex = 0;
} }
MaxAccessCount = Send.MaxAccessCount; MaxAccessCount = Send.MaxAccessCount;
_isOverridingPickers = true;
DeletionDate = Send.DeletionDate.ToLocalTime();
DeletionTime = DeletionDate.TimeOfDay; DeletionTime = DeletionDate.TimeOfDay;
ExpirationDate = Send.ExpirationDate?.ToLocalTime();
ExpirationTime = ExpirationDate?.TimeOfDay; ExpirationTime = ExpirationDate?.TimeOfDay;
_isOverridingPickers = false; _isOverridingPickers = false;
} }
@ -292,18 +302,21 @@ namespace Bit.App.Pages
await _platformUtilsService.ShowDialogAsync(AppResources.PremiumRequired); await _platformUtilsService.ShowDialogAsync(AppResources.PremiumRequired);
return false; return false;
} }
if (FileData == null) if (!EditMode)
{ {
await _platformUtilsService.ShowDialogAsync( if (FileData == null)
string.Format(AppResources.ValidationFieldRequired, AppResources.File), {
AppResources.AnErrorHasOccurred); await _platformUtilsService.ShowDialogAsync(
return false; string.Format(AppResources.ValidationFieldRequired, AppResources.File),
} AppResources.AnErrorHasOccurred);
if (FileData.Length > 104857600) // 100 MB return false;
{ }
await _platformUtilsService.ShowDialogAsync(AppResources.MaxFileSize, if (FileData.Length > 104857600) // 100 MB
AppResources.AnErrorHasOccurred); {
return false; await _platformUtilsService.ShowDialogAsync(AppResources.MaxFileSize,
AppResources.AnErrorHasOccurred);
return false;
}
} }
} }
@ -392,23 +405,23 @@ namespace Bit.App.Pages
switch (DeletionDateTypeSelectedIndex) switch (DeletionDateTypeSelectedIndex)
{ {
case 0: case 0:
DeletionDate = DateTime.Now.AddHours(1); DeletionDate = DateTimeNow().AddHours(1);
break; break;
case 1: case 1:
DeletionDate = DateTime.Now.AddDays(1); DeletionDate = DateTimeNow().AddDays(1);
break; break;
case 2: case 2:
DeletionDate = DateTime.Now.AddDays(2); DeletionDate = DateTimeNow().AddDays(2);
break; break;
case 3: case 3:
DeletionDate = DateTime.Now.AddDays(3); DeletionDate = DateTimeNow().AddDays(3);
break; break;
case 4: case 4:
case 6: case 6:
DeletionDate = DateTime.Now.AddDays(7); DeletionDate = DateTimeNow().AddDays(7);
break; break;
case 5: case 5:
DeletionDate = DateTime.Now.AddDays(30); DeletionDate = DateTimeNow().AddDays(30);
break; break;
} }
DeletionTime = DeletionDate.TimeOfDay; DeletionTime = DeletionDate.TimeOfDay;
@ -428,27 +441,27 @@ namespace Bit.App.Pages
ClearExpirationDate(); ClearExpirationDate();
break; break;
case 1: case 1:
ExpirationDate = DateTime.Now.AddHours(1); ExpirationDate = DateTimeNow().AddHours(1);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 2: case 2:
ExpirationDate = DateTime.Now.AddDays(1); ExpirationDate = DateTimeNow().AddDays(1);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 3: case 3:
ExpirationDate = DateTime.Now.AddDays(2); ExpirationDate = DateTimeNow().AddDays(2);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 4: case 4:
ExpirationDate = DateTime.Now.AddDays(3); ExpirationDate = DateTimeNow().AddDays(3);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 5: case 5:
ExpirationDate = DateTime.Now.AddDays(7); ExpirationDate = DateTimeNow().AddDays(7);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 6: case 6:
ExpirationDate = DateTime.Now.AddDays(30); ExpirationDate = DateTimeNow().AddDays(30);
ExpirationTime = ExpirationDate.Value.TimeOfDay; ExpirationTime = ExpirationDate.Value.TimeOfDay;
break; break;
case 7: case 7:
@ -465,7 +478,7 @@ namespace Bit.App.Pages
if (!_isOverridingPickers && !ExpirationTime.HasValue) if (!_isOverridingPickers && !ExpirationTime.HasValue)
{ {
// auto-set time to current time upon setting date // auto-set time to current time upon setting date
ExpirationTime = DateTime.Now.TimeOfDay; ExpirationTime = DateTimeNow().TimeOfDay;
} }
} }
@ -487,5 +500,19 @@ namespace Bit.App.Pages
{ {
ShowPassword = !ShowPassword; ShowPassword = !ShowPassword;
} }
private DateTime DateTimeNow()
{
var dtn = DateTime.Now;
return new DateTime(
dtn.Year,
dtn.Month,
dtn.Day,
dtn.Hour,
dtn.Minute,
0,
DateTimeKind.Local
);
}
} }
} }