sharee.bike-App/LastenradBayern/TINK/View/FeedbackPopup.xaml.cs

90 lines
3.1 KiB
C#
Raw Normal View History

2021-11-07 19:42:59 +01:00
using System;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS;
2021-11-07 19:42:59 +01:00
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms.Xaml;
namespace TINK.View
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FeedbackPopup : Popup<FeedbackPopup.Result>
{
2022-01-04 18:54:03 +01:00
/// <summary> Constructs user feedback popup.</summary>
2022-08-30 15:42:25 +02:00
/// <param name="battery">Object holding info about battery. For some batteries charging level might need to be updated by user.</param>
2022-01-04 18:54:03 +01:00
/// <param name="co2Saving"> Co2 saving information.</param>
2022-08-30 15:42:25 +02:00
public FeedbackPopup(
IBattery battery = null,
string co2Saving = null)
2021-11-07 19:42:59 +01:00
{
InitializeComponent();
2022-01-04 18:54:03 +01:00
if (string.IsNullOrEmpty(co2Saving))
Co2SavingFrame.IsVisible = false;
else
Co2SavingLabel.Text = co2Saving;
2022-08-30 15:42:25 +02:00
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;
2021-11-07 19:42:59 +01:00
}
protected override FeedbackPopup.Result GetLightDismissResult()
{
return new Result
{
2022-08-30 15:42:25 +02:00
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
IsBikeBroken = brockenCheckBox.IsChecked,
Message = feedbackMessage.Text
2021-11-07 19:42:59 +01:00
};
}
private void OnOkClicked(object sender, EventArgs eventArgs)
{
var result = new Result
{
2022-08-30 15:42:25 +02:00
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
IsBikeBroken = brockenCheckBox.IsChecked,
Message = feedbackMessage.Text
2021-11-07 19:42:59 +01:00
};
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
{
2022-08-30 15:42:25 +02:00
/// <summary>
/// Holds the current chargeing level of the battery entered by user in bars, null if unkonwn.
/// </summary>
public int? CurrentChargeBars { get; set; }
2021-11-07 19:42:59 +01:00
/// <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; }
}
}
}