using System; using TINK.Model.Bikes.BikeInfoNS.DriveNS.BatteryNS; using Xamarin.CommunityToolkit.UI.Views; using Xamarin.Forms.Xaml; namespace TINK.View { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class FeedbackPopup : Popup { /// Constructs user feedback popup. /// Object holding info about battery. For some batteries charging level might need to be updated by user. /// Co2 saving information. public FeedbackPopup( IBattery battery = null, string co2Saving = null) { InitializeComponent(); if (string.IsNullOrEmpty(co2Saving)) Co2SavingFrame.IsVisible = false; else Co2SavingLabel.Text = co2Saving; 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 = brockenCheckBox.IsChecked, 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 = brockenCheckBox.IsChecked, Message = feedbackMessage.Text }; Dismiss(result); } /// /// Feedback given by user when returning bike. /// #if USCSHARP9 public class Result : IViewService.IUserFeedback #else public new class Result : IUserFeedback #endif { /// /// Holds the current charging level of the battery entered by user in bars, null if unknown. /// public int? CurrentChargeBars { get; set; } /// /// Holds whether bike is broken or not. /// public bool IsBikeBroken { get; set; } /// /// Holds either /// - general feedback /// - error description of broken bike /// or both. /// public string Message { get; set; } } } }