11using SimpleTimer . Clocks ;
2- using System ;
3- using System . ComponentModel ;
42using System . Globalization ;
5- using System . Windows . Input ;
63using static SimpleTimer . Clocks . UiUpdatedEventArgs ;
74
85namespace SimpleTimer . ClockUserControls
96{
10- public class StopwatchViewModel : IClockViewModel
7+ public class StopwatchViewModel : BaseViewModel
118 {
12- readonly IConfigurationValues _config ;
139 readonly IClock _clock ;
1410 readonly IUserInterface _ui ;
1511 readonly ILogger _logger ;
16- string _text ;
17- string _primaryButtonText ;
18- bool _isTextEnabled ;
19-
20- #region Datacontext
21- public string Text { get => _text ; set { _text = value ; OnPropertyChanged ( nameof ( Text ) ) ; } }
22- public bool IsTextEnabled { get => _isTextEnabled ; set { _isTextEnabled = value ; OnPropertyChanged ( nameof ( IsTextEnabled ) ) ; } }
23- public string PrimaryButtonText { get => _primaryButtonText ; set { _primaryButtonText = value ; OnPropertyChanged ( nameof ( PrimaryButtonText ) ) ; } }
24- public ICommand TextPressEnter { get => null ; }
25- public ICommand TextPressEscape { get => null ; }
26-
27- public event PropertyChangedEventHandler PropertyChanged ;
28-
29- private void OnPropertyChanged ( string name )
30- {
31- var handler = PropertyChanged ;
32- handler ? . Invoke ( this , new PropertyChangedEventArgs ( name ) ) ;
33- }
34- #endregion
35-
36- public StopwatchViewModel ( IUserInterface ui , IClock stopwatchclock , IConfigurationValues config , ILogger logger )
12+
13+ public StopwatchViewModel ( IUserInterface ui , IClock stopwatchclock , IConfigurationValues config , ILogger logger ) : base ( config )
3714 {
38- _config = config ;
3915 _ui = ui ;
4016 _clock = stopwatchclock ;
4117 _logger = logger ;
4218
4319 RegisterEvents ( ) ;
4420
45- _text = _config ? . InitialText ?? "" ;
46- _primaryButtonText = _config ? . PrimaryButtonStart ?? "" ;
21+ Text = Config ? . InitialText ?? "" ;
22+ PrimaryButtonText = Config ? . PrimaryButtonStart ?? "" ;
4723 IsTextEnabled = false ;
24+
25+ ChangeButtonBlue ( ) ;
26+ _ui ? . ChangeWindowTitle ( Config . WindowTitle ) ;
4827 }
4928
5029 private void RegisterEvents ( )
@@ -114,16 +93,26 @@ private void UpdateIU(UiUpdatedEventArgs e)
11493 return ;
11594 if ( e . Time . HasValue )
11695 {
117- Text = e . Time . Value . ToString ( _config . TimeFormat , CultureInfo . InvariantCulture ) ;
96+ Text = e . Time . Value . ToString ( Config . TimeFormat , CultureInfo . InvariantCulture ) ;
11897 }
11998 if ( e . PrimaryBtn . HasValue )
12099 {
121- PrimaryButtonText = e . PrimaryBtn . Value switch
100+ switch ( e . PrimaryBtn . Value )
122101 {
123- PrimaryButtonMode . Running => _config . PrimaryButtonStop ,
124- PrimaryButtonMode . Stopped => _config . PrimaryButtonStart ,
125- _ => e . PrimaryBtn . Value . ToString ( ) ,
126- } ;
102+ case PrimaryButtonMode . Running :
103+ PrimaryButtonText = Config . PrimaryButtonStop ;
104+ ChangeButtonRed ( ) ;
105+ _ui . ChangeWindowTitle ( Config . WindowTitleRunning ) ;
106+ break ;
107+ case PrimaryButtonMode . Stopped :
108+ PrimaryButtonText = Config . PrimaryButtonStart ;
109+ ChangeButtonBlue ( ) ;
110+ _ui . ChangeWindowTitle ( Config . WindowTitle ) ;
111+ break ;
112+ default :
113+ PrimaryButtonText = e . PrimaryBtn . Value . ToString ( ) ;
114+ break ;
115+ }
127116 }
128117 }
129118
@@ -132,7 +121,7 @@ private void UpdateIU(UiUpdatedEventArgs e)
132121 #region IDisposable Support
133122 private bool disposedValue = false ; // To detect redundant calls
134123
135- protected virtual void Dispose ( bool disposing )
124+ protected override void Dispose ( bool disposing )
136125 {
137126 if ( ! disposedValue )
138127 {
@@ -145,19 +134,9 @@ protected virtual void Dispose(bool disposing)
145134
146135 disposedValue = true ;
147136 }
137+ base . Dispose ( disposing ) ;
148138 }
149139
150- ~ StopwatchViewModel ( )
151- {
152- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
153- Dispose ( false ) ;
154- }
155-
156- public void Dispose ( )
157- {
158- Dispose ( true ) ;
159- GC . SuppressFinalize ( this ) ;
160- }
161140 #endregion
162141 }
163142}
0 commit comments