mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using System.ComponentModel;
|
|
using TINK.MultilingualResources;
|
|
|
|
namespace ShareeSharedGuiLib.ViewModel
|
|
{
|
|
/// <summary>
|
|
/// Bar based filling level indicator view.
|
|
/// </summary>
|
|
public class BarLevelViewModel : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public int? _Maximum = null;
|
|
|
|
/// <summary>
|
|
/// Holds the maximum count of bars.
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Holds the current count of bars.
|
|
/// </summary>
|
|
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)));
|
|
}
|
|
}
|
|
|
|
/// <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;
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether battery label is visible or not.
|
|
/// </summary>
|
|
public bool IsBatteryChargeLevelLabelVisible => Maximum.HasValue && Maximum.Value != 5;
|
|
|
|
/// <summary>
|
|
/// Gets name of battery image resource.
|
|
/// </summary>
|
|
public string BatteryChargeLevelImageSourceString => Current.HasValue && Maximum.HasValue && Maximum.Value == 5
|
|
? $"battery_{Current.Value}_{Maximum.Value}.png"
|
|
: "battery_undefined.png";
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether battery image is visible or not.
|
|
/// </summary>
|
|
public bool IsBatteryChargeLevelImageVisible => Maximum.HasValue && Maximum.Value == 5;
|
|
|
|
}
|
|
}
|