mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-22 15:06:26 +01:00
86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
|
|
using Xamarin.CommunityToolkit.UI.Views;
|
|
using Xamarin.Forms.Xaml;
|
|
|
|
namespace ShareeBike.View
|
|
{
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
public partial class FeedbackPopup : Popup<FeedbackPopup.Result>
|
|
{
|
|
/// <summary> Constructs user feedback popup.</summary>
|
|
/// <param name="battery">Object holding info about battery. For some batteries charging level might need to be updated by user.</param>
|
|
/// <param name="co2Saving"> Co2 saving information.</param>
|
|
public FeedbackPopup(
|
|
IBatteryMutable battery = null,
|
|
string co2Saving = null)
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (battery == null
|
|
|| (battery.IsBackendAccessible.HasValue && battery.IsBackendAccessible.Value))
|
|
{
|
|
// Either
|
|
// - bike has no engine or
|
|
// - backend can access battery level information
|
|
// No need to ask user for input.
|
|
return;
|
|
}
|
|
|
|
BarLevelInputView.IsVisible = battery?.MaxChargeBars != null;
|
|
BarLevelInputView.Current = battery?.CurrentChargeBars?.ToString() ?? string.Empty;
|
|
BarLevelInputView.Maximum = battery?.MaxChargeBars != null ? battery?.MaxChargeBars.ToString() : String.Empty;
|
|
|
|
}
|
|
|
|
protected override FeedbackPopup.Result GetLightDismissResult()
|
|
{
|
|
return new Result
|
|
{
|
|
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
|
|
IsBikeBroken = bikeIsOkSwitch.IsToggled,
|
|
Message = feedbackMessage.Text
|
|
};
|
|
}
|
|
|
|
private void OnOkClicked(object sender, EventArgs eventArgs)
|
|
{
|
|
var result = new Result
|
|
{
|
|
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
|
|
IsBikeBroken = bikeIsOkSwitch.IsToggled,
|
|
Message = feedbackMessage.Text
|
|
};
|
|
|
|
Dismiss(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Feedback given by user when returning bike.
|
|
/// </summary>
|
|
#if USCSHARP9
|
|
public class Result : IViewService.IUserFeedback
|
|
#else
|
|
public new class Result : IUserFeedback
|
|
#endif
|
|
{
|
|
/// <summary>
|
|
/// Holds the current charging level of the battery entered by user in bars, null if unknown.
|
|
/// </summary>
|
|
public int? CurrentChargeBars { get; set; }
|
|
|
|
/// <summary>
|
|
/// Holds whether bike is broken or not.
|
|
/// </summary>
|
|
public bool IsBikeBroken { get; set; }
|
|
|
|
/// <summary>
|
|
/// Holds either
|
|
/// - general feedback
|
|
/// - error description of broken bike
|
|
/// or both.
|
|
/// </summary>
|
|
public string Message { get; set; }
|
|
}
|
|
}
|
|
}
|