mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Mini survey added.
Minor fiexes.
This commit is contained in:
parent
ddfea49ea6
commit
e321764119
73 changed files with 1628 additions and 185 deletions
|
@ -24,7 +24,7 @@ namespace TINK.ViewModel.Account
|
|||
private int? m_iMyBikesCount;
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private readonly IViewService m_oViewService;
|
||||
|
||||
|
@ -56,11 +56,11 @@ namespace TINK.ViewModel.Account
|
|||
/// <param name="p_oPolling"> Holds whether to poll or not and the periode leght is polling is on. </param>
|
||||
/// <param name="p_oDefaultPollingPeriode">Default polling periode lenght.</param>
|
||||
/// <param name="p_oMinimumLogEventLevel">Controls logging level.</param>
|
||||
/// <param name="p_oViewService">Interface to view</param>
|
||||
/// <param name="viewService">Interface to view</param>
|
||||
public AccountPageViewModel(
|
||||
ITinkApp tinkApp,
|
||||
Action<string> openUrlInExternalBrowser,
|
||||
IViewService p_oViewService)
|
||||
IViewService viewService)
|
||||
{
|
||||
TinkApp = tinkApp
|
||||
?? throw new ArgumentException("Can not instantiate settings page view model- object. No tink app object available.");
|
||||
|
@ -68,7 +68,7 @@ namespace TINK.ViewModel.Account
|
|||
OpenUrlInExternalBrowser = openUrlInExternalBrowser
|
||||
?? throw new ArgumentException("Can not instantiate settings page view model- object. No user external browse service available.");
|
||||
|
||||
m_oViewService = p_oViewService
|
||||
m_oViewService = viewService
|
||||
?? throw new ArgumentException("Can not instantiate settings page view model- object. No user view service available.");
|
||||
|
||||
m_oViewUpdateManager = new IdlePollingUpdateTaskManager();
|
||||
|
|
|
@ -31,11 +31,11 @@ namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
|
|||
protected ISmartDevice SmartDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
protected IViewService ViewService { get; }
|
||||
|
||||
/// <summary> Provides an connector object.</summary>
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
protected Func<bool, IConnector> ConnectorFactory { get; }
|
||||
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
|
|||
public string ButtonText => AppResources.ActionReturn; // "Miete beenden"
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
protected IViewService ViewService { get; }
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
|
|||
public string ActionText { get => BikesViewModel.ActionText; private set => BikesViewModel.ActionText = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
protected IViewService ViewService { get; }
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ namespace TINK.ViewModel.Bikes.Bike
|
|||
protected ISmartDevice SmartDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
protected IViewService ViewService { get; }
|
||||
|
||||
/// <summary> Provides an connector object.</summary>
|
||||
/// <summary> Provides a connect orobject.</summary>
|
||||
protected Func<bool, IConnector> ConnectorFactory { get; }
|
||||
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
|
|
|
@ -15,6 +15,7 @@ using TINK.Model.User;
|
|||
using Xamarin.Essentials;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.MiniSurvey;
|
||||
|
||||
namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||||
{
|
||||
|
@ -126,10 +127,10 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
IsConnected = IsConnectedDelegate();
|
||||
|
||||
var feedBackUri = SelectedBike?.OperatorUri;
|
||||
|
||||
MiniSurveyModel miniSurvey;
|
||||
try
|
||||
{
|
||||
await ConnectorFactory(IsConnected).Command.DoReturn(
|
||||
miniSurvey = await ConnectorFactory(IsConnected).Command.DoReturn(
|
||||
SelectedBike,
|
||||
currentLocationDto);
|
||||
|
||||
|
@ -229,11 +230,11 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
if (exception is ResponseException copriException)
|
||||
{
|
||||
// Copri server is not reachable.
|
||||
Log.ForContext<BookedOpen>().Information("User selected booked bike {bike} but returing failed. COPRI returned an error.", SelectedBike);
|
||||
Log.ForContext<BookedOpen>().Information("Submitting feedback for bike {bike} failed. COPRI returned an error.", SelectedBike);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext<BookedOpen>().Error("User selected availalbe bike {bike} but reserving failed. {@l_oException}", SelectedBike.Id, exception);
|
||||
Log.ForContext<BookedOpen>().Error("Submitting feedback for bike {bike} failed. {@l_oException}", SelectedBike.Id, exception);
|
||||
}
|
||||
|
||||
await ViewService.DisplayAlert(
|
||||
|
@ -250,6 +251,10 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
return RequestHandlerFactory.Create(SelectedBike, IsConnectedDelegate, ConnectorFactory, Geolocation, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser);
|
||||
}
|
||||
#endif
|
||||
if (miniSurvey != null && miniSurvey.Questions.Count > 0)
|
||||
{
|
||||
await ViewService.PushModalAsync(ViewTypes.MiniSurvey);
|
||||
}
|
||||
|
||||
// Restart polling again.
|
||||
BikesViewModel.ActionText = AppResources.ActivityTextStartingUpdater;
|
||||
|
|
|
@ -15,6 +15,7 @@ using TINK.Model.Bikes.Bike.BluetoothLock;
|
|||
using TINK.Model.User;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Model.MiniSurvey;
|
||||
|
||||
namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||||
{
|
||||
|
@ -195,10 +196,10 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
IsConnected = IsConnectedDelegate();
|
||||
|
||||
var feedBackUri = SelectedBike?.OperatorUri;
|
||||
|
||||
MiniSurveyModel miniSurvey;
|
||||
try
|
||||
{
|
||||
await ConnectorFactory(IsConnected).Command.DoReturn(
|
||||
miniSurvey = await ConnectorFactory(IsConnected).Command.DoReturn(
|
||||
SelectedBike,
|
||||
currentLocation != null
|
||||
? new LocationDto.Builder
|
||||
|
@ -304,11 +305,11 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
if (exception is ResponseException copriException)
|
||||
{
|
||||
// Copri server is not reachable.
|
||||
Log.ForContext<BookedOpen>().Information("User selected booked bike {bike} but returing failed. COPRI returned an error.", SelectedBike);
|
||||
Log.ForContext<BookedOpen>().Information("Submitting feedback for bike {bike} failed. COPRI returned an error.", SelectedBike);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext<BookedOpen>().Error("User selected availalbe bike {bike} but reserving failed. {@l_oException}", SelectedBike.Id, exception);
|
||||
Log.ForContext<BookedOpen>().Error("Submitting feedback for bike {bike} failed. {@l_oException}", SelectedBike.Id, exception);
|
||||
}
|
||||
|
||||
await ViewService.DisplayAlert(
|
||||
|
@ -325,6 +326,11 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|||
}
|
||||
#endif
|
||||
|
||||
if (miniSurvey != null && miniSurvey.Questions.Count > 0)
|
||||
{
|
||||
await ViewService.PushModalAsync(ViewTypes.MiniSurvey);
|
||||
}
|
||||
|
||||
BikesViewModel.ActionText = AppResources.ActivityTextStartingUpdater;
|
||||
await ViewUpdateManager().StartUpdateAyncPeridically();
|
||||
BikesViewModel.ActionText = string.Empty;
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace TINK.ViewModel.Bikes.Bike.BluetoothLock
|
|||
public string LockitButtonText => GetType().Name;
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private IViewService ViewService { get; }
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace TINK.ViewModel.Bikes
|
|||
protected ISmartDevice SmartDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
protected IViewService ViewService { get; }
|
||||
|
||||
|
@ -34,12 +34,12 @@ namespace TINK.ViewModel.Bikes
|
|||
/// </summary>
|
||||
private Exception m_oException;
|
||||
|
||||
/// <summary> Provides an connector object.</summary>
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
protected Func<bool, IConnector> ConnectorFactory { get; }
|
||||
|
||||
protected IGeolocation Geolocation { get; }
|
||||
|
||||
/// <summary> Provides an connector object.</summary>
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
protected ILocksService LockService { get; }
|
||||
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
|
@ -88,7 +88,7 @@ namespace TINK.ViewModel.Bikes
|
|||
/// <param name="p_oPolling"> Holds whether to poll or not and the periode leght is polling is on. </param>
|
||||
/// <param name="postAction">Executes actions on GUI thread.</param>
|
||||
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...)</param>
|
||||
/// <param name="p_oViewService">Interface to actuate methodes on GUI.</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public BikesViewModel(
|
||||
User user,
|
||||
IPermissions permissions,
|
||||
|
|
|
@ -195,7 +195,7 @@ namespace TINK.ViewModel.BikesAtStation
|
|||
// Switch to map page
|
||||
|
||||
#if USEMASTERDETAIL || USEFLYOUT
|
||||
ViewService.ShowPage(ViewTypes.ContactPage, m_oStation?.OperatorData?.Name ?? AppResources.MarkingFeedbackAndContact);
|
||||
ViewService.ShowPage(ViewTypes.ContactPage, AppResources.MarkingFeedbackAndContact);
|
||||
#else
|
||||
await ViewService.ShowPage("//LoginPage");
|
||||
#endif
|
||||
|
|
|
@ -226,8 +226,14 @@ namespace TINK.ViewModel.Info
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary> Text providing mail address and possilbe reasons to contact. </summary>
|
||||
public FormattedString MaliAddressAndMotivationsText
|
||||
public string ProviderNameText
|
||||
=> string.Format("Betreiber: {0}", SelectedStation?.OperatorData?.Name)
|
||||
;
|
||||
/// <summary> Text providing mail address and possilbe reasons to contact. </summary>
|
||||
public FormattedString MailAddressAndMotivationsText
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace TINK.ViewModel.Contact
|
|||
/// <summary> Holds the count of custom icons availalbe.</summary>
|
||||
private const int CUSTOM_ICONS_COUNT = 30;
|
||||
|
||||
/// <summary> Reference on view servcie to show modal notifications and to perform navigation. </summary>
|
||||
/// <summary> Reference on view service to show modal notifications and to perform navigation. </summary>
|
||||
private IViewService ViewService { get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace TINK.ViewModel.Info.BikeInfo
|
|||
public class BikeInfoViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private readonly IViewService m_oViewService;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace TINK.ViewModel
|
|||
public class LoginPageViewModel : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private readonly IViewService m_oViewService;
|
||||
|
||||
|
@ -178,7 +178,7 @@ namespace TINK.ViewModel
|
|||
{
|
||||
if (CrossConnectivity.Current.IsConnected)
|
||||
{
|
||||
await m_oViewService.PushAsync(ViewTypes.RegisterPage);
|
||||
await m_oViewService.PushAsync(ViewTypes.RegisterPage);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace TINK.ViewModel.Map
|
|||
/// <summary> Holds the count of custom icons availalbe.</summary>
|
||||
private const int CUSTOM_ICONS_COUNT = 30;
|
||||
|
||||
/// <summary> Reference on view servcie to show modal notifications and to perform navigation. </summary>
|
||||
/// <summary> Reference on view service to show modal notifications and to perform navigation. </summary>
|
||||
private IViewService ViewService { get; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -315,55 +315,52 @@ namespace TINK.ViewModel.Map
|
|||
// Update map page filter
|
||||
ActiveFilterMap = TinkApp.GroupFilterMapPage;
|
||||
|
||||
if (Pins.Count <= 0)
|
||||
{
|
||||
ActionText = AppResources.ActivityTextMyBikesLoadingBikes;
|
||||
ActionText = AppResources.ActivityTextMyBikesLoadingBikes;
|
||||
|
||||
// Check location permission
|
||||
var status = await PermissionsService.CheckPermissionStatusAsync<LocationPermission>();
|
||||
if (TinkApp.CenterMapToCurrentLocation
|
||||
&& !GeolocationService.IsSimulation
|
||||
&& status != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
|
||||
{
|
||||
var permissionResult = await PermissionsService.RequestPermissionAsync<LocationPermission>();
|
||||
// Check location permission
|
||||
var status = await PermissionsService.CheckPermissionStatusAsync<LocationPermission>();
|
||||
if (TinkApp.CenterMapToCurrentLocation
|
||||
&& !GeolocationService.IsSimulation
|
||||
&& status != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
|
||||
{
|
||||
var permissionResult = await PermissionsService.RequestPermissionAsync<LocationPermission>();
|
||||
|
||||
if (permissionResult != Plugin.Permissions.Abstractions.PermissionStatus.Granted)
|
||||
{
|
||||
var dialogResult = await ViewService.DisplayAlert(
|
||||
var dialogResult = await m_oViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageCenterMapLocationPermissionOpenDialog,
|
||||
AppResources.MessageAnswerYes,
|
||||
AppResources.MessageAnswerNo);
|
||||
|
||||
if (dialogResult)
|
||||
{
|
||||
// User decided to give access to locations permissions.
|
||||
PermissionsService.OpenAppSettings();
|
||||
ActionText = "";
|
||||
IsRunning = false;
|
||||
IsMapPageEnabled = true;
|
||||
return;
|
||||
}
|
||||
if (dialogResult)
|
||||
{
|
||||
// User decided to give access to locations permissions.
|
||||
PermissionsService.OpenAppSettings();
|
||||
ActionText = "";
|
||||
IsRunning = false;
|
||||
IsMapPageEnabled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Move and scale before getting stations and bikes which takes some time.
|
||||
ActionText = AppResources.ActivityTextCenterMap;
|
||||
Location currentLocation = null;
|
||||
try
|
||||
{
|
||||
currentLocation = TinkApp.CenterMapToCurrentLocation
|
||||
? await GeolocationService.GetAsync()
|
||||
: null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
||||
}
|
||||
|
||||
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, ActiveFilterMap, currentLocation);
|
||||
}
|
||||
|
||||
// Move and scale before getting stations and bikes which takes some time.
|
||||
ActionText = AppResources.ActivityTextCenterMap;
|
||||
Location currentLocation = null;
|
||||
try
|
||||
{
|
||||
currentLocation = TinkApp.CenterMapToCurrentLocation
|
||||
? await GeolocationService.GetAsync()
|
||||
: null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
||||
}
|
||||
|
||||
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, ActiveFilterMap, currentLocation);
|
||||
|
||||
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
|
||||
IsConnected = TinkApp.GetIsConnected();
|
||||
var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
|
||||
|
|
153
TINKLib/ViewModel/MiniSurvey/MiniSurveyViewModel.cs
Normal file
153
TINKLib/ViewModel/MiniSurvey/MiniSurveyViewModel.cs
Normal file
|
@ -0,0 +1,153 @@
|
|||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.MiniSurvey;
|
||||
using TINK.MultilingualResources;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.View;
|
||||
using TINK.ViewModel.MiniSurvey.Question;
|
||||
|
||||
namespace TINK.ViewModel.MiniSurvey
|
||||
{
|
||||
public class MiniSurveyViewModel : ObservableCollection<IMiniSurveyQuestion>
|
||||
{
|
||||
/// <summary> Delegate to retrieve connected state. </summary>
|
||||
protected Func<bool> IsConnectedDelegate { get; }
|
||||
|
||||
/// <summary> Provides a connector object.</summary>
|
||||
private Func<bool, IConnector> ConnectorFactory { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private IViewService ViewService { get; }
|
||||
|
||||
private MiniSurveyModel MiniSurvey { get; }
|
||||
|
||||
/// <summary> Constructs mini survey view model.</summary>
|
||||
/// <param name="connectorFactory">Connects system to copri for purposes of requesting a bike/ cancel request.</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public MiniSurveyViewModel(
|
||||
Func<bool> isConnectedDelegate,
|
||||
Func<bool, IConnector> connectorFactory,
|
||||
IViewService viewService)
|
||||
{
|
||||
IsConnectedDelegate = isConnectedDelegate
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
|
||||
ConnectorFactory = connectorFactory
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No connector available.");
|
||||
|
||||
ViewService = viewService
|
||||
?? throw new ArgumentException($"Can not instantiate {nameof(MiniSurveyViewModel)}-object. No view available.");
|
||||
|
||||
MiniSurvey = new MiniSurveyModel
|
||||
{
|
||||
Title = "Bitte unterstützen Sie unsere Begleitforschung",
|
||||
Subtitle = "Ihre drei Antworten werden anonym gespeichert.",
|
||||
Footer = "Herzlichen Dank und viel Spaß bei der nächsten Fahrt!"
|
||||
};
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q1",
|
||||
new MiniSurveyModel.QuestionModel
|
||||
{
|
||||
Text = "1. Was war der Hauptzweck dieser Ausleihe?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q2",
|
||||
new MiniSurveyModel.QuestionModel
|
||||
{
|
||||
Text = "2. Welches Verkehrsmittel hätten Sie ansonsten benutzt?",
|
||||
Type = MiniSurveyModel.Type.SingleAnswer
|
||||
});
|
||||
|
||||
MiniSurvey.Questions.Add(
|
||||
"q3",
|
||||
new MiniSurveyModel.QuestionModel
|
||||
{
|
||||
Text = "3. Haben Sie Anmerkungen oder Anregungen?",
|
||||
Type = MiniSurveyModel.Type.CustomText
|
||||
});
|
||||
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt1", "a. Einkauf");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt2", "b. Kinderbeförderung");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt3", "c. Lastentransport");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt4", "d. Freizeit");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt5", "e. Ausprobieren");
|
||||
MiniSurvey.Questions["q1"].PossibleAnswers.Add("opt6", "f. Sonstiges");
|
||||
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt1", "a. Auto");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt2", "b. Motorrad oder Motorroller");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt3", "c. Bus oder Bahn");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt4", "d. Eigenes Fahrrad");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt5", "e. Zu Fuß");
|
||||
MiniSurvey.Questions["q2"].PossibleAnswers.Add("opt6", "f. Keines (ich hätte die Fahrt sonst nicht gemacht)");
|
||||
|
||||
Title = MiniSurvey.Title;
|
||||
Subtitle = MiniSurvey.Subtitle;
|
||||
Footer = MiniSurvey.Footer;
|
||||
|
||||
foreach (var question in MiniSurvey.Questions)
|
||||
{
|
||||
switch (question.Value.Type)
|
||||
{
|
||||
case MiniSurveyModel.Type.SingleAnswer:
|
||||
Add(new CheckOneViewModel(
|
||||
new KeyValuePair<string, string>(question.Key, question.Value.Text),
|
||||
question.Value.PossibleAnswers));
|
||||
break;
|
||||
|
||||
case MiniSurveyModel.Type.CustomText:
|
||||
Add(new FreeTextViewModel(new KeyValuePair<string, string>(question.Key, question.Value.Text)));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string Subtitle { get; set; }
|
||||
|
||||
public string Footer { get; set; }
|
||||
|
||||
/// <summary> Processes request to perform a copri action (reserve bike and cancel reservation). </summary>
|
||||
public System.Windows.Input.ICommand OnButtonClicked => new Xamarin.Forms.Command(async () =>
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Information($"User result {this[0].Answer.Value}, {this[1].Answer.Value}");
|
||||
|
||||
var isConnected = IsConnectedDelegate();
|
||||
try
|
||||
{
|
||||
await ConnectorFactory(isConnected).Command.DoSubmitMiniSurvey(this.ToDictionary(x => x.Question.Key, x => x.Answer.Key));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (exception is ResponseException copriException)
|
||||
{
|
||||
// Copri server is not reachable.
|
||||
Log.ForContext<MiniSurveyViewModel>().Information("Submitting mini survay answer failed. COPRI returned an error.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext<MiniSurveyViewModel>().Error("Submitting mini survay answer failed. {@l_oException}", exception);
|
||||
}
|
||||
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.ErrorReturnSubmitFeedbackTitle,
|
||||
AppResources.ErrorReturnSubmitFeedbackMessage,
|
||||
AppResources.MessageAnswerOk);
|
||||
}
|
||||
|
||||
await ViewService.PopModalAsync();
|
||||
});
|
||||
}
|
||||
}
|
45
TINKLib/ViewModel/MiniSurvey/Question/CheckOneViewModel.cs
Normal file
45
TINKLib/ViewModel/MiniSurvey/Question/CheckOneViewModel.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public class CheckOneViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public CheckOneViewModel(
|
||||
KeyValuePair<string, string> question,
|
||||
Dictionary<string, string> answers)
|
||||
{
|
||||
Question = question;
|
||||
Answers = answers ?? new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
|
||||
/// <summary> Holds the list of possible answers with their option keys. </summary>
|
||||
public Dictionary<string, string> Answers { get; }
|
||||
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public IEnumerable<string> AnswersText
|
||||
{
|
||||
get => Answers.Select(x => x.Value).ToList();
|
||||
set => AnswersText = Answers.Select(x => x.Value).ToList();
|
||||
}
|
||||
|
||||
/// <summary> Holds the users selected answer (one of answers) with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
|
||||
/// <summary> Holds the users selected answer (one of answers) in GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => Answer.Value;
|
||||
set => Answer = Answers.FirstOrDefault(x => x.Value == value);
|
||||
}
|
||||
}
|
||||
}
|
32
TINKLib/ViewModel/MiniSurvey/Question/FreeTextViewModel.cs
Normal file
32
TINKLib/ViewModel/MiniSurvey/Question/FreeTextViewModel.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public class FreeTextViewModel : IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Constructs object. </summary>
|
||||
/// <param name="question">Holds the question with key asked to user.</param>
|
||||
/// <param name="answers">Holds the list of possible answers with their option keys.</param>
|
||||
public FreeTextViewModel(
|
||||
KeyValuePair<string, string> question)
|
||||
{
|
||||
Question = question;
|
||||
}
|
||||
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
public KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the question with key asked to user exposed to GUI. </summary>
|
||||
public string QuestionText => Question.Value;
|
||||
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
public KeyValuePair<string, string> Answer { get; private set; }
|
||||
|
||||
/// <summary> Holds the list of possible answers exposed to GUI. </summary>
|
||||
public string AnswerText
|
||||
{
|
||||
get => null;
|
||||
set => Answer = new KeyValuePair<string, string>(value, null);
|
||||
}
|
||||
}
|
||||
}
|
13
TINKLib/ViewModel/MiniSurvey/Question/IMiniSurveyQuestion.cs
Normal file
13
TINKLib/ViewModel/MiniSurvey/Question/IMiniSurveyQuestion.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace TINK.ViewModel.MiniSurvey.Question
|
||||
{
|
||||
public interface IMiniSurveyQuestion
|
||||
{
|
||||
/// <summary> Holds the question with key asked to user. </summary>
|
||||
KeyValuePair<string, string> Question { get; }
|
||||
|
||||
/// <summary> Holds the users selected answer with its option key. </summary>
|
||||
KeyValuePair<string, string> Answer { get; }
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace TINK.ViewModel
|
|||
public class SettingsPageViewModel : INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference on view servcie to show modal notifications and to perform navigation.
|
||||
/// Reference on view service to show modal notifications and to perform navigation.
|
||||
/// </summary>
|
||||
private IViewService m_oViewService;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue