1
1
using NETworkManager . Settings ;
2
- using MahApps . Metro . Controls . Dialogs ;
3
2
using System ;
4
3
using NETworkManager . Models . Network ;
5
4
using System . ComponentModel ;
@@ -18,10 +17,8 @@ public class BitCalculatorViewModel : ViewModelBase
18
17
{
19
18
#region Variables
20
19
private static readonly ILog Log = LogManager . GetLogger ( typeof ( BitCalculatorViewModel ) ) ;
21
- private readonly IDialogCoordinator _dialogCoordinator ;
22
-
23
- private readonly bool _isLoading = true ;
24
- private bool _isViewActive = true ;
20
+
21
+ private readonly bool _isLoading ;
25
22
26
23
private string _input ;
27
24
public string Input
@@ -39,11 +36,11 @@ public string Input
39
36
40
37
public ICollectionView InputHistoryView { get ; }
41
38
42
- private List < BitCaluclatorUnit > _units = new ( ) ;
39
+ private readonly List < BitCaluclatorUnit > _units = new ( ) ;
43
40
public List < BitCaluclatorUnit > Units
44
41
{
45
42
get => _units ;
46
- set
43
+ private init
47
44
{
48
45
if ( value == _units )
49
46
return ;
@@ -70,16 +67,16 @@ public BitCaluclatorUnit Unit
70
67
}
71
68
}
72
69
73
- private bool _isCalculationRunning ;
74
- public bool IsCalculationRunning
70
+ private bool _isRunning ;
71
+ public bool IsRunning
75
72
{
76
- get => _isCalculationRunning ;
73
+ get => _isRunning ;
77
74
set
78
75
{
79
- if ( value == _isCalculationRunning )
76
+ if ( value == _isRunning )
80
77
return ;
81
78
82
- _isCalculationRunning = value ;
79
+ _isRunning = value ;
83
80
OnPropertyChanged ( ) ;
84
81
}
85
82
}
@@ -103,7 +100,7 @@ public bool IsResultVisible
103
100
public BitCaluclatorInfo Result
104
101
{
105
102
get => _result ;
106
- set
103
+ private set
107
104
{
108
105
if ( value == _result )
109
106
return ;
@@ -115,9 +112,9 @@ public BitCaluclatorInfo Result
115
112
#endregion
116
113
117
114
#region Constructor, load settings
118
- public BitCalculatorViewModel ( IDialogCoordinator instance )
115
+ public BitCalculatorViewModel ( )
119
116
{
120
- _dialogCoordinator = instance ;
117
+ _isLoading = true ;
121
118
122
119
InputHistoryView = CollectionViewSource . GetDefaultView ( SettingsManager . Current . BitCalculator_InputHistory ) ;
123
120
@@ -137,11 +134,11 @@ private void LoadSettings()
137
134
#endregion
138
135
139
136
#region ICommands & Actions
140
- public ICommand CalculateCommand => new RelayCommand ( p => CalcualateAction ( ) , Calculate_CanExecute ) ;
137
+ public ICommand CalculateCommand => new RelayCommand ( _ => CalculateAction ( ) , Calculate_CanExecute ) ;
141
138
142
- private bool Calculate_CanExecute ( object paramter ) => Application . Current . MainWindow != null && ! ( ( MetroWindow ) Application . Current . MainWindow ) . IsAnyDialogOpen ;
139
+ private bool Calculate_CanExecute ( object parameter ) => Application . Current . MainWindow != null && ! ( ( MetroWindow ) Application . Current . MainWindow ) . IsAnyDialogOpen ;
143
140
144
- private void CalcualateAction ( )
141
+ private void CalculateAction ( )
145
142
{
146
143
Calculate ( ) ;
147
144
}
@@ -151,9 +148,9 @@ private void CalcualateAction()
151
148
private async void Calculate ( )
152
149
{
153
150
IsResultVisible = false ;
154
- IsCalculationRunning = true ;
151
+ IsRunning = true ;
155
152
156
- if ( double . TryParse ( Input . Replace ( '.' , ',' ) , out double input ) )
153
+ if ( double . TryParse ( Input . Replace ( '.' , ',' ) , out var input ) )
157
154
{
158
155
Result = await BitCaluclator . CalculateAsync ( input , Unit , SettingsManager . Current . BitCalculator_Notation ) ;
159
156
}
@@ -166,7 +163,7 @@ private async void Calculate()
166
163
167
164
AddInputToHistory ( Input ) ;
168
165
169
- IsCalculationRunning = false ;
166
+ IsRunning = false ;
170
167
}
171
168
172
169
private void AddInputToHistory ( string input )
@@ -184,18 +181,14 @@ private void AddInputToHistory(string input)
184
181
185
182
public void OnViewVisible ( )
186
183
{
187
- _isViewActive = true ;
184
+
188
185
}
189
186
190
187
public void OnViewHide ( )
191
188
{
192
- _isViewActive = false ;
189
+
193
190
}
194
191
195
192
196
- #endregion
197
-
198
- #region Event
199
-
200
193
#endregion
201
194
}
0 commit comments