Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:FormsPinView.PCL.PinViewModel"/> class.
        /// </summary>
        public PinViewModel()
        {
            KeyPressCommand = new Command <string>(arg =>
            {
                if (arg == "Backspace")
                {
                    if (EnteredPin.Count > 0)
                    {
                        EnteredPin.RemoveAt(EnteredPin.Count - 1);
                        DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                    }
                }
                else if (arg == "Clear")
                {
                    if (EnteredPin.Count > 0)
                    {
                        _enteredPin = new List <char>();
                        DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                    }
                }
                else if (EnteredPin.Count < TargetPinLength)
                {
                    EnteredPin.Add(arg[0]);
                    if (EnteredPin.Count == TargetPinLength)
                    {
                        var pass = new string(EnteredPin.ToArray());

                        if (ValidatorFunc.Invoke(pass))
                        {
                            Success?.Invoke(this, new PinEventArgs()
                            {
                                EnteredPin = pass
                            });
                            EnteredPin.Clear();
                            DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                        }
                        else
                        {
                            EnteredPin.Clear();
                            Error?.Invoke(this, EventArgs.Empty);
                            DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                    }
                }
            });
        }
Beispiel #2
0
        public PinViewModel()
        {
            KeyPressCommand = new Command <string>(arg =>
            {
                var v = CrossVibrate.Current;
                v.Vibration(TimeSpan.FromMilliseconds(100));

                if (arg == "Backspace")
                {
                    if (EnteredPin.Count > 0)
                    {
                        EnteredPin.RemoveAt(EnteredPin.Count - 1);
                        DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                    }
                }
                else if (EnteredPin.Count < TargetPinLength)
                {
                    EnteredPin.Add(arg[0]);
                    if (EnteredPin.Count == TargetPinLength)
                    {
                        if (ValidatorFunc.Invoke(EnteredPin))
                        {
                            EnteredPin.Clear();
                            Success?.Invoke(this, EventArgs.Empty);
                            DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                        }
                        else
                        {
                            EnteredPin.Clear();
                            Error?.Invoke(this, EventArgs.Empty);
                            DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                    }
                }
            });
        }
        /// <summary>
        /// Updates the displayed PIN icons.
        /// </summary>
        protected void UpdateDisplayedText(bool resetUI)
        {
            if (PinLength <= 0)
            {
                // not expected to happen
                throw new InvalidOperationException($"{PinLengthProperty.PropertyName} property" +
                                                    $" is not a positive value but {PinLength}");
            }

            if (resetUI || _circlesStackLayout.Children.Count == 0)
            {
                _circlesStackLayout.Children.Clear();
                for (int i = 0; i < PinLength; ++i)
                {
                    _circlesStackLayout.Children.Add(new CircleView
                    {
                        HeightRequest        = 28,
                        WidthRequest         = 28,
                        MinimumWidthRequest  = 28,
                        MinimumHeightRequest = 28,
                        Color = Color
                    });
                }
            }

            if (EnteredPin != null)
            {
                for (int i = 0; i < EnteredPin.Count; ++i)
                {
                    (_circlesStackLayout.Children[i] as CircleView).IsFilledUp = true;
                }
                for (int i = EnteredPin.Count; i < PinLength; ++i)
                {
                    (_circlesStackLayout.Children[i] as CircleView).IsFilledUp = false;
                }
            }

            DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:FormsPinView.PCL.PinViewModel"/> class.
 /// </summary>
 public PinViewModel()
 {
     KeyPressCommand = new Command<string>(arg =>
     {
         if (arg == "Backspace")
         {
             if (EnteredPin.Count > 0)
             {
                 EnteredPin.RemoveAt(EnteredPin.Count - 1);
                 DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
             }
         }
         else if (EnteredPin.Count < TargetPinLength)
         {
             EnteredPin.Add(arg[0]);
             if (EnteredPin.Count == TargetPinLength)
             {
                 if (ValidatorFunc.Invoke(EnteredPin))
                 {
                     EnteredPin.Clear();
                     Success?.Invoke(this, EventArgs.Empty);
                     DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                 }
                 else
                 {
                     EnteredPin.Clear();
                     Error?.Invoke(this, EventArgs.Empty);
                     DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
                 }
             }
             else
             {
                 DisplayedTextUpdated?.Invoke(this, EventArgs.Empty);
             }
         }
     });
 }