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

92 lines
2.6 KiB
C#
Raw Normal View History

2023-04-19 12:14:14 +02: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
{
2022-09-06 16:08:19 +02:00
[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(
IBattery battery = null,
string co2Saving = null)
{
InitializeComponent();
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
if (string.IsNullOrEmpty(co2Saving))
Co2SavingFrame.IsVisible = false;
else
Co2SavingLabel.Text = co2Saving;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +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;
}
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
BarLevelInputView.IsVisible = battery?.MaxChargeBars != null;
BarLevelInputView.Current = battery?.CurrentChargeBars?.ToString() ?? string.Empty;
BarLevelInputView.Maximum = battery?.MaxChargeBars != null ? battery?.MaxChargeBars.ToString() : String.Empty;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
protected override FeedbackPopup.Result GetLightDismissResult()
{
return new Result
{
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
2023-05-11 17:39:28 +02:00
IsBikeBroken = bikeIsOkSwitch.IsToggled,
2022-09-06 16:08:19 +02:00
Message = feedbackMessage.Text
};
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
private void OnOkClicked(object sender, EventArgs eventArgs)
{
var result = new Result
{
CurrentChargeBars = int.TryParse(BarLevelInputView.Current, out int current) ? (int?)current : null,
2023-05-11 17:39:28 +02:00
IsBikeBroken = bikeIsOkSwitch.IsToggled,
2022-09-06 16:08:19 +02:00
Message = feedbackMessage.Text
};
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
Dismiss(result);
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Feedback given by user when returning bike.
/// </summary>
2021-11-07 19:42:59 +01:00
#if USCSHARP9
public class Result : IViewService.IUserFeedback
#else
2022-09-06 16:08:19 +02:00
public new class Result : IUserFeedback
2021-11-07 19:42:59 +01:00
#endif
2022-09-06 16:08:19 +02:00
{
/// <summary>
2023-04-19 12:14:14 +02:00
/// Holds the current charging level of the battery entered by user in bars, null if unknown.
2022-09-06 16:08:19 +02:00
/// </summary>
public int? CurrentChargeBars { get; set; }
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds whether bike is broken or not.
/// </summary>
public bool IsBikeBroken { get; set; }
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds either
/// - general feedback
/// - error description of broken bike
/// or both.
/// </summary>
public string Message { get; set; }
}
}
2023-04-19 12:14:14 +02:00
}