using System.ComponentModel;
using TINK.MultilingualResources;
namespace ShareeSharedGuiLib.ViewModel
{
///
/// Bar based filling level indicator view.
///
public class BarLevelViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public int? _Maximum = null;
///
/// Holds the maximum count of bars.
///
public int? Maximum
{
get => _Maximum;
set
{
if (_Maximum == value)
{
// Nothing to do because nothing changed.
return;
}
_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)));
}
}
public int? _Current = null;
///
/// Holds the current count of bars.
///
public int? Current
{
get => _Current;
set
{
if (_Current == value)
{
// Nothing to do because nothing changed.
return;
}
_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)));
}
}
///
/// Gets the battery filling level or pedelecs.
///
public string BatteryChargeLevelBarsText => Maximum != null
? string.Format(
AppResources.MarkingDriveBatteryChargingLevel,
Current != null ? Current.ToString() : "-",
Maximum != null ? Maximum.ToString() : "-")
: AppResources.MarkingDriveBatteryChargingLevelNotAvailable;
///
/// Gets a value indicating whether battery label is visible or not.
///
public bool IsBatteryChargeLevelLabelVisible => Maximum.HasValue && Maximum.Value != 5;
///
/// Gets name of battery image ressource.
///
public string BatteryChargeLevelImageSourceString => Current.HasValue && Maximum.HasValue && Maximum.Value == 5
? $"battery_{Current.Value}_{Maximum.Value}.png"
: "battery_undefined.png";
///
/// Gets a value indicating whether battery image is visible or not.
///
public bool IsBatteryChargeLevelImageVisible => Maximum.HasValue && Maximum.Value == 5;
}
}