|
| 1 | +/* |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) Léo Corporation |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +*/ |
| 24 | +using InternetTest.Helpers; |
| 25 | +using InternetTest.Models; |
| 26 | +using System.Windows.Media; |
| 27 | + |
| 28 | +namespace InternetTest.ViewModels.Components; |
| 29 | +public class HistoryItemViewModel : ViewModelBase |
| 30 | +{ |
| 31 | + private string _name = string.Empty; |
| 32 | + public string Name { get => _name; set { _name = value; OnPropertyChanged(nameof(Name)); } } |
| 33 | + |
| 34 | + private string _statusText = string.Empty; |
| 35 | + public string StatusText { get => _statusText; set { _statusText = value; OnPropertyChanged(nameof(StatusText)); } } |
| 36 | + |
| 37 | + private string _dateText = string.Empty; |
| 38 | + public string DateText { get => _dateText; set { _dateText = value; OnPropertyChanged(nameof(DateText)); } } |
| 39 | + |
| 40 | + private SolidColorBrush? _statusForeground; |
| 41 | + public SolidColorBrush? StatusForeground { get => _statusForeground; set { _statusForeground = value; OnPropertyChanged(nameof(StatusForeground)); } } |
| 42 | + |
| 43 | + private SolidColorBrush? _statusBackground; |
| 44 | + public SolidColorBrush? StatusBackground { get => _statusBackground; set { _statusBackground = value; OnPropertyChanged(nameof(StatusBackground)); } } |
| 45 | + |
| 46 | + public HistoryItemViewModel(Activity activity) |
| 47 | + { |
| 48 | + Name = activity.Name; |
| 49 | + StatusText = activity.Result; |
| 50 | + DateText = activity.Date.ToString("g"); |
| 51 | + |
| 52 | + switch (activity.Success) |
| 53 | + { |
| 54 | + case true: |
| 55 | + StatusBackground = ThemeHelper.GetSolidColorBrush("LightGreen"); |
| 56 | + StatusForeground = ThemeHelper.GetSolidColorBrush("ForegroundGreen"); |
| 57 | + break; |
| 58 | + case false: |
| 59 | + StatusBackground = ThemeHelper.GetSolidColorBrush("LightOrange"); |
| 60 | + StatusForeground = ThemeHelper.GetSolidColorBrush("ForegroundOrange"); |
| 61 | + break; |
| 62 | + default: |
| 63 | + StatusBackground = ThemeHelper.GetSolidColorBrush("LightFAccent"); |
| 64 | + StatusForeground = ThemeHelper.GetSolidColorBrush("DarkFAccent"); |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments