mirror of
https://github.com/bitwarden/android.git
synced 2026-05-22 12:32:16 -05:00
90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using System.Runtime.CompilerServices;
|
|
using Bit.App.Behaviors;
|
|
using CommunityToolkit.Maui.Views;
|
|
|
|
namespace Bit.App.Pages
|
|
{
|
|
public partial class SendAddOnlyOptionsView : ContentView
|
|
{
|
|
public SendAddOnlyOptionsView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private SendAddEditPageViewModel ViewModel => BindingContext as SendAddEditPageViewModel;
|
|
|
|
public void SetMainScrollView(ScrollView scrollView)
|
|
{
|
|
_notesEditor.Behaviors.Add(new EditorPreventAutoBottomScrollingOnFocusedBehavior { ParentScrollView = scrollView });
|
|
}
|
|
|
|
private void OnMaxAccessCountTextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
if (ViewModel is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(e.NewTextValue))
|
|
{
|
|
ViewModel.MaxAccessCount = null;
|
|
_maxAccessCountStepper.Value = 0;
|
|
return;
|
|
}
|
|
// accept only digits
|
|
if (!int.TryParse(e.NewTextValue, out int _))
|
|
{
|
|
((Entry)sender).Text = e.OldTextValue;
|
|
}
|
|
}
|
|
|
|
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
|
|
if (propertyName == nameof(BindingContext)
|
|
&&
|
|
ViewModel != null)
|
|
{
|
|
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
|
}
|
|
}
|
|
|
|
private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
{
|
|
if (!_lazyDeletionDateTimePicker.HasLazyViewLoaded
|
|
&&
|
|
e.PropertyName == nameof(SendAddEditPageViewModel.ShowDeletionCustomPickers)
|
|
&&
|
|
ViewModel.ShowDeletionCustomPickers)
|
|
{
|
|
_lazyDeletionDateTimePicker.LoadViewAsync();
|
|
}
|
|
|
|
if (!_lazyExpirationDateTimePicker.HasLazyViewLoaded
|
|
&&
|
|
e.PropertyName == nameof(SendAddEditPageViewModel.ShowExpirationCustomPickers)
|
|
&&
|
|
ViewModel.ShowExpirationCustomPickers)
|
|
{
|
|
_lazyExpirationDateTimePicker.LoadViewAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SendAddOnlyOptionsLazyView : LazyView<SendAddOnlyOptionsView>
|
|
{
|
|
public ScrollView MainScrollView { get; set; }
|
|
|
|
public override async ValueTask LoadViewAsync()
|
|
{
|
|
await base.LoadViewAsync();
|
|
|
|
if (Content is SendAddOnlyOptionsView optionsView)
|
|
{
|
|
optionsView.SetMainScrollView(MainScrollView);
|
|
}
|
|
}
|
|
}
|
|
}
|