mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-05-21 08:26:34 +02:00
Version 3.0.371
This commit is contained in:
parent
bdb2dec1c1
commit
6d22dbf40b
145 changed files with 2289 additions and 764 deletions
|
@ -2,32 +2,35 @@ using Serilog;
|
|||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public class Battery : IBattery
|
||||
{
|
||||
private Battery() { }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
public double CurrentChargePercent { get; private set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in bars, null if unknown.
|
||||
/// Gets the current charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? CurrentChargeBars { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the maximum charging level of the battery in bars, null if unknown.
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? MaxChargeBars { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether backend is aware of battery charging level.
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
public bool? IsBackendAccessible { get; private set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Holds whether to display battery level or not.
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
public bool? IsHidden { get; private set; } = null;
|
||||
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
using System.ComponentModel;
|
||||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public class BatteryMutable : IBatteryMutable, INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
IBattery _battery;
|
||||
|
||||
public BatteryMutable(IBattery battery)
|
||||
{
|
||||
_battery = battery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
public double CurrentChargePercent => _battery.CurrentChargePercent;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? CurrentChargeBars
|
||||
{
|
||||
get => _battery.CurrentChargeBars;
|
||||
set
|
||||
{
|
||||
double GetCurrentChargePercent()
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
// Filling level is unknown.
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
if (_battery.MaxChargeBars == null || _battery.MaxChargeBars == 0)
|
||||
{
|
||||
// Percentage filling level can not be calculated.
|
||||
return _battery.CurrentChargePercent;
|
||||
}
|
||||
|
||||
return (int)(100 * value / _battery.MaxChargeBars);
|
||||
}
|
||||
|
||||
if (_battery.CurrentChargeBars == value)
|
||||
{
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
|
||||
_battery = new Battery.Builder
|
||||
{
|
||||
MaxChargeBars = _battery.MaxChargeBars,
|
||||
IsBackendAccessible = _battery.IsBackendAccessible,
|
||||
IsHidden = _battery.IsHidden,
|
||||
CurrentChargeBars = value,
|
||||
CurrentChargePercent = GetCurrentChargePercent(),
|
||||
}.Build();
|
||||
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentChargeBars)));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CurrentChargePercent)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
public int? MaxChargeBars => _battery.MaxChargeBars;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
public bool? IsBackendAccessible => _battery.IsBackendAccessible;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
public bool? IsHidden => _battery.IsHidden;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
public interface IBattery
|
||||
public interface IBattery
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the current charging level of the battery in percent, double.NaN if unknown.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
using System.ComponentModel;
|
||||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the state of a chargeable battery.
|
||||
/// </summary>
|
||||
public interface IBatteryMutable : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the current charging level of the battery in percent, double.NaN if unknown.
|
||||
/// </summary>
|
||||
double CurrentChargePercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current charging level of the battery in bars. Must not be larger than MaxChargeBars, null if unknown.
|
||||
/// </summary>
|
||||
int? CurrentChargeBars { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum charging level of the battery in bars, null if unknown.
|
||||
/// </summary>
|
||||
int? MaxChargeBars { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether backend is aware of battery charging level.
|
||||
/// </summary>
|
||||
bool? IsBackendAccessible { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to display battery level or not.
|
||||
/// </summary>
|
||||
bool? IsHidden { get; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
||||
using TINK.Model.Bikes.BikeInfoNS.DriveNS.EngineNS;
|
||||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
|
||||
|
@ -6,32 +6,32 @@ namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
|
|||
public enum DriveType
|
||||
{
|
||||
/// <summary>
|
||||
/// Bike without pedalling aid.
|
||||
/// Bike without pedaling aid.
|
||||
/// </summary>
|
||||
SoleHumanPowered,
|
||||
|
||||
/// <summary>
|
||||
/// pedal electric cycle: Pedalling is assisted by an electric engine.
|
||||
/// pedal electric cycle: Pedaling is assisted by an electric engine.
|
||||
/// </summary>
|
||||
Pedelec
|
||||
}
|
||||
|
||||
public class Drive
|
||||
public class DriveMutable
|
||||
{
|
||||
public Drive(
|
||||
public DriveMutable(
|
||||
IEngine engine = null,
|
||||
IBattery battery = null)
|
||||
{
|
||||
if (engine == null)
|
||||
{
|
||||
Engine = new Engine();
|
||||
Battery = new Battery.Builder().Build();
|
||||
Battery = new BatteryMutable(new Battery.Builder().Build());
|
||||
Type = DriveType.SoleHumanPowered;
|
||||
return;
|
||||
}
|
||||
|
||||
Engine = engine;
|
||||
Battery = battery ?? new Battery.Builder().Build();
|
||||
Battery = new BatteryMutable(battery ?? new Battery.Builder().Build());
|
||||
Type = DriveType.Pedelec;
|
||||
}
|
||||
|
||||
|
@ -48,15 +48,6 @@ namespace TINK.Model.Bikes.BikeInfoNS.DriveNS
|
|||
/// <summary>
|
||||
/// Battery powering the engine.
|
||||
/// </summary>
|
||||
public IBattery _Battery = new Battery.Builder().Build();
|
||||
|
||||
/// <summary>
|
||||
/// Battery powering the engine.
|
||||
/// </summary>
|
||||
public IBattery Battery
|
||||
{
|
||||
get => _Battery;
|
||||
set => _Battery = value ?? new Battery.Builder().Build();
|
||||
}
|
||||
public IBatteryMutable Battery { get; private set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue