sharee.bike-App/ShareeSharedGuiLib/ViewModel/BarLevelViewModel.cs

90 lines
2.7 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +02:00
using System.ComponentModel;
using TINK.MultilingualResources;
namespace ShareeSharedGuiLib.ViewModel
{
2022-09-06 16:08:19 +02:00
/// <summary>
/// Bar based filling level indicator view.
/// </summary>
public class BarLevelViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? _Maximum = null;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the maximum count of bars.
/// </summary>
public int? Maximum
{
get => _Maximum;
set
{
if (_Maximum == value)
{
// Nothing to do because nothing changed.
return;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
_Maximum = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBatteryChargeLevelLabelVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BatteryChargeLevelBarsText)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BatteryChargeLevelImageSourceString)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBatteryChargeLevelImageVisible)));
}
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
public int? _Current = null;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the current count of bars.
/// </summary>
public int? Current
{
get => _Current;
set
{
if (_Current == value)
{
// Nothing to do because nothing changed.
return;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
_Current = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBatteryChargeLevelLabelVisible)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BatteryChargeLevelBarsText)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(BatteryChargeLevelImageSourceString)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsBatteryChargeLevelImageVisible)));
}
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets the battery filling level or pedelecs.
/// </summary>
public string BatteryChargeLevelBarsText => Maximum != null
? string.Format(
AppResources.MarkingDriveBatteryChargingLevel,
Current != null ? Current.ToString() : "-",
Maximum != null ? Maximum.ToString() : "-")
: AppResources.MarkingDriveBatteryChargingLevelNotAvailable;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets a value indicating whether battery label is visible or not.
/// </summary>
public bool IsBatteryChargeLevelLabelVisible => Maximum.HasValue && Maximum.Value != 5;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets name of battery image ressource.
/// </summary>
public string BatteryChargeLevelImageSourceString => Current.HasValue && Maximum.HasValue && Maximum.Value == 5
? $"battery_{Current.Value}_{Maximum.Value}.png"
: "battery_undefined.png";
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Gets a value indicating whether battery image is visible or not.
/// </summary>
public bool IsBatteryChargeLevelImageVisible => Maximum.HasValue && Maximum.Value == 5;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
}