Moving to MVVM part 1.
MODIFY
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/LockScreen.xaml.cs
@@ -4,97 +4,10 @@ using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
-using ReactiveUI;
-using WalletWasabi.Gui.Models;
-
namespace WalletWasabi.Gui.Controls.LockScreen
{
public class LockScreen : UserControl
{
- private bool _isLocked;
- private string _pinHash;
-
- private LockScreenType _activeLockScreenType;
- private ContentControl LockScreenHost;
- private LockScreenBase CurrentLockScreen;
- private CompositeDisposable ScreenImplDisposables;
-
- public static readonly DirectProperty<LockScreen, LockScreenType> ActiveLockScreenTypeProperty =
- AvaloniaProperty.RegisterDirect<LockScreen, LockScreenType>(nameof(ActiveLockScreenType),
- o => o.ActiveLockScreenType,
- (o, v) => o.ActiveLockScreenType = v);
- public LockScreenType ActiveLockScreenType
- {
- get => _activeLockScreenType;
- set => this.SetAndRaise(ActiveLockScreenTypeProperty, ref _activeLockScreenType, value);
- }
-
- public static readonly DirectProperty<LockScreen, bool> IsLockedProperty =
- AvaloniaProperty.RegisterDirect<LockScreen, bool>(nameof(IsLocked),
- o => o.IsLocked,
- (o, v) => o.IsLocked = v);
- public bool IsLocked
- {
- get => _isLocked;
- set => this.SetAndRaise(IsLockedProperty, ref _isLocked, value);
- }
-
- public static readonly DirectProperty<LockScreen, string> PINHashProperty =
- AvaloniaProperty.RegisterDirect<LockScreen, string>(nameof(PINHash),
- o => o.PINHash,
- (o, v) => o.PINHash = v);
- public string PINHash
- {
- get => _pinHash;
- set => this.SetAndRaise(PINHashProperty, ref _pinHash, value);
- }
-
- public LockScreen()
- {
- InitializeComponent();
-
- this.LockScreenHost = this.FindControl<ContentControl>("LockScreenHost");
-
- this.WhenAnyValue(x => x.ActiveLockScreenType)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(OnActiveLockScreenTypeChanged);
- }
-
- private void OnActiveLockScreenTypeChanged(LockScreenType obj)
- {
- ScreenImplDisposables?.Dispose();
- ScreenImplDisposables = new CompositeDisposable();
-
- switch (obj)
- {
- case LockScreenType.PINLock:
- var pinLock = new PinLock();
- CurrentLockScreen = pinLock;
-
- this.WhenAnyValue(x => x.PINHash)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(y => pinLock.PINHash = y)
- .DisposeWith(ScreenImplDisposables);
-
- break;
- default:
- CurrentLockScreen = new SlideLock();
- break;
- }
-
- LockScreenHost.Content = CurrentLockScreen;
-
- this.WhenAnyValue(x => x.IsLocked)
- .ObserveOn(RxApp.MainThreadScheduler)
- .BindTo(CurrentLockScreen, y => y.IsLocked)
- .DisposeWith(ScreenImplDisposables);
-
- CurrentLockScreen.WhenAnyValue(x => x.IsLocked)
- .ObserveOn(RxApp.MainThreadScheduler)
- .BindTo(this, y => y.IsLocked)
- .DisposeWith(ScreenImplDisposables);
- }
-
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);

DELETE
WalletWasabi.Gui/Controls/LockScreen/LockScreenBase.cs
-using System;
-using System.Reactive.Linq;
-using Avalonia;
-using Avalonia.Controls;
-using ReactiveUI;
-
-namespace WalletWasabi.Gui.Controls.LockScreen
-{
- public abstract class LockScreenBase : UserControl
- {
- private bool _currentState;
- private bool _isLocked;
-
- public static readonly DirectProperty<LockScreenBase, bool> IsLockedProperty =
- AvaloniaProperty.RegisterDirect<LockScreenBase, bool>(nameof(IsLocked),
- o => o.IsLocked,
- (o, v) => o.IsLocked = v);
- public bool IsLocked
- {
- get => _isLocked;
- set => SetAndRaise(IsLockedProperty, ref _isLocked, value);
- }
-
- public LockScreenBase()
- {
- this.WhenAnyValue(x => x.IsLocked)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(IsLockedChanged);
- }
-
- private void IsLockedChanged(bool isLocked)
- {
- if (isLocked == _currentState) return;
-
- _currentState = isLocked;
-
- if (isLocked)
- {
- this.IsHitTestVisible = true;
- DoLock();
- }
- else
- {
- this.IsHitTestVisible = false;
- DoUnlock();
- }
- }
-
- public abstract void DoLock();
- public abstract void DoUnlock();
- }
-}

ADD
WalletWasabi.Gui/Controls/LockScreen/LockScreenViewModel.cs
+using System;
+using ReactiveUI;
+using System.Reactive.Disposables;
+using WalletWasabi.Helpers;
+using System.Reactive.Linq;
+using WalletWasabi.Gui.ViewModels;
+
+namespace WalletWasabi.Gui.Controls.LockScreen
+{
+ public class LockScreenViewModel : ViewModelBase
+ {
+ private CompositeDisposable Disposables { get; }
+
+ public Global Global { get; }
+
+ public LockScreenViewModel(Global global)
+ {
+ Global = Guard.NotNull(nameof(Global), global);
+ Disposables = new CompositeDisposable();
+ }
+
+ private ILockScreenViewModel _activeLockScreen;
+ public ILockScreenViewModel ActiveLockScreen
+ {
+ get => _activeLockScreen;
+ set => this.RaiseAndSetIfChanged(ref _activeLockScreen, value);
+ }
+
+ private ObservableAsPropertyHelper<string> _pinHash;
+ public string PINHash => _pinHash?.Value ?? default;
+
+ private bool _isLocked;
+ public bool IsLocked
+ {
+ get => _isLocked;
+ set => this.RaiseAndSetIfChanged(ref _isLocked, value);
+ }
+
+ public void Initialize()
+ {
+ Global.UiConfig.WhenAnyValue(x => x.LockScreenActive)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .BindTo(this, y => y.IsLocked)
+ .DisposeWith(Disposables);
+
+ this.WhenAnyValue(x => x.IsLocked)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .BindTo(Global.UiConfig, y => y.LockScreenActive)
+ .DisposeWith(Disposables);
+
+ _pinHash = Global.UiConfig
+ .WhenAnyValue(x => x.LockScreenPinHash)
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .ToProperty(this, x=>x.PINHash);
+ }
+
+ private void CheckLockScreenType(string currentHash)
+ {
+ if (currentHash != string.Empty)
+ {
+ ActiveLockScreen = new PinLockScreenViewModel(this);
+ }
+ else
+ {
+ ActiveLockScreen = new SlideLockScreenViewModel(this);
+ }
+ }
+ }
+}
\ No newline at end of file

RENAME
WalletWasabi.Gui/Controls/LockScreen/PinLock.xaml
WalletWasabi.Gui/Controls/LockScreen/PinLockScreen.xaml
RENAME
WalletWasabi.Gui/Controls/LockScreen/PinLock.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/PinLockScreen.xaml.cs
@@ -15,7 +15,7 @@ using System.Reactive;
namespace WalletWasabi.Gui.Controls.LockScreen
{
- public class PinLock : LockScreenBase
+ public class PinLockScreen : UserControl
{
public Grid Shade { get; }
@@ -25,7 +25,7 @@ namespace WalletWasabi.Gui.Controls.LockScreen
internal string PINHash { get; set; }
- public PinLock() : base()
+ public PinLockScreen() : base()
{
InitializeComponent();

ADD
WalletWasabi.Gui/Controls/LockScreen/PinLockScreenViewModel.cs
+using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Helpers;
+
+namespace WalletWasabi.Gui.Controls.LockScreen
+{
+ public class PinLockScreenViewModel : ViewModelBase, ILockScreenViewModel
+ {
+ private LockScreenViewModel _parentVM;
+
+ public PinLockScreenViewModel(LockScreenViewModel lockScreenViewModel)
+ {
+ _parentVM = Guard.NotNull(nameof(lockScreenViewModel),lockScreenViewModel);
+ }
+ }
+}

RENAME
WalletWasabi.Gui/Controls/LockScreen/SlideLock.xaml
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreen.xaml
RENAME
WalletWasabi.Gui/Controls/LockScreen/SlideLock.xaml.cs
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreen.xaml.cs
@@ -12,7 +12,7 @@ using System.Reactive.Disposables;
namespace WalletWasabi.Gui.Controls.LockScreen
{
- internal class SlideLock : LockScreenBase
+ internal class SlideLockScreen : UserControl
{
private CompositeDisposable Disposables { get; set; }
private Grid Shade;
@@ -31,7 +31,7 @@ namespace WalletWasabi.Gui.Controls.LockScreen
set => OnOffsetChanged(value);
}
- public SlideLock() : base()
+ public SlideLockScreen() : base()
{
InitializeComponent();

ADD
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
+using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Helpers;
+
+namespace WalletWasabi.Gui.Controls.LockScreen
+{
+ public class SlideLockScreenViewModel : ViewModelBase, ILockScreenViewModel
+ {
+ private LockScreenViewModel _parentVM;
+
+ public SlideLockScreenViewModel(LockScreenViewModel lockScreenViewModel)
+ {
+ _parentVM = Guard.NotNull(nameof(lockScreenViewModel),lockScreenViewModel);
+ }
+ }
+}

DELETE
WalletWasabi.Gui/ViewModels/LockScreenViewModel.cs
-using System;
-using ReactiveUI;
-using System.Reactive.Disposables;
-using WalletWasabi.Gui.Models;
-using WalletWasabi.Helpers;
-using System.Reactive.Linq;
-
-namespace WalletWasabi.Gui.ViewModels
-{
- public class LockScreenViewModel : ViewModelBase
- {
- private CompositeDisposable Disposables { get; } = new CompositeDisposable();
-
- public Global Global { get; }
-
- public LockScreenViewModel(Global global)
- {
- Global = Guard.NotNull(nameof(Global), global);
- }
-
- private LockScreenType _lockScreenType;
- public LockScreenType ActiveLockScreen
- {
- get => _lockScreenType;
- set => this.RaiseAndSetIfChanged(ref _lockScreenType, value);
- }
-
- private bool _isLocked;
- public bool IsLocked
- {
- get => _isLocked;
- set => this.RaiseAndSetIfChanged(ref _isLocked, value);
- }
-
- private string _pinHash;
- public string PINHash
- {
- get => _pinHash;
- set => this.RaiseAndSetIfChanged(ref _pinHash, value);
- }
-
- public void Initialize()
- {
- Global.UiConfig.WhenAnyValue(x => x.LockScreenActive)
- .ObserveOn(RxApp.MainThreadScheduler)
- .BindTo(this, y => y.IsLocked)
- .DisposeWith(Disposables);
-
- this.WhenAnyValue(x => x.IsLocked)
- .ObserveOn(RxApp.MainThreadScheduler)
- .BindTo(Global.UiConfig, y => y.LockScreenActive)
- .DisposeWith(Disposables);
-
- Global.UiConfig.WhenAnyValue(x => x.LockScreenPinHash)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(CheckLockScreenType)
- .DisposeWith(Disposables);
- }
-
- private void CheckLockScreenType(string currentHash)
- {
- if (currentHash != string.Empty)
- {
- ActiveLockScreen = LockScreenType.PINLock;
- }
- else
- {
- ActiveLockScreen = default(LockScreenType);
- }
-
- PINHash = currentHash;
- }
- }
-}
\ No newline at end of file

Moving to MVVM part 1.