This commit is contained in:
Oliver Hauff 2022-01-22 18:32:22 +01:00
parent 6ed1579494
commit 3c97e2f4aa
34 changed files with 278 additions and 135 deletions

View file

@ -477,7 +477,11 @@ namespace TINK.Model
},
{
new Version(3, 0, 276),
AppResources.ChangeLog3_0_276
AppResources.ChangeLog3_0_276
},
{
new Version(3, 0, 277),
AppResources.ChangeLog3_0_277
}
};

View file

@ -920,6 +920,15 @@ namespace TINK.MultilingualResources {
}
}
/// <summary>
/// Looks up a localized string similar to Bugfix: No more closing of app on Select Bike page..
/// </summary>
public static string ChangeLog3_0_277 {
get {
return ResourceManager.GetString("ChangeLog3_0_277", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lock of rented bike can not be found..
/// </summary>
@ -1736,6 +1745,24 @@ namespace TINK.MultilingualResources {
}
}
/// <summary>
/// Looks up a localized string similar to No bike with id {0} found..
/// </summary>
public static string MessageErrorSelectBikeNoBikeFound {
get {
return ResourceManager.GetString("MessageErrorSelectBikeNoBikeFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error Selecting Bike!.
/// </summary>
public static string MessageErrorSelectBikeTitle {
get {
return ResourceManager.GetString("MessageErrorSelectBikeTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Login cookie must not be empty. {0}.
/// </summary>

View file

@ -742,4 +742,13 @@ Fehlerbehebung: Supportmails können wieder verschickt werden.</value>
<value>Beim Umschalten zwischen Lasten-/ Stadträdern ist ein Fehler aufgetreten.
{0}</value>
</data>
<data name="MessageErrorSelectBikeNoBikeFound" xml:space="preserve">
<value>Kein Fahrrad mit Id {0} gefunden.</value>
</data>
<data name="MessageErrorSelectBikeTitle" xml:space="preserve">
<value>Fehler beim Rad Wählen!</value>
</data>
<data name="ChangeLog3_0_277" xml:space="preserve">
<value>Fehlerbehebung: App schließt sich nicht mehr auf Fahrrad Wählen-Seite.</value>
</data>
</root>

View file

@ -837,4 +837,13 @@ Bugfix: Sending support mails works again. </value>
<value>An error occurred switching from cargo bikes/ city bikes.
{0}</value>
</data>
<data name="MessageErrorSelectBikeNoBikeFound" xml:space="preserve">
<value>No bike with id {0} found.</value>
</data>
<data name="MessageErrorSelectBikeTitle" xml:space="preserve">
<value>Error Selecting Bike!</value>
</data>
<data name="ChangeLog3_0_277" xml:space="preserve">
<value>Bugfix: No more closing of app on Select Bike page.</value>
</data>
</root>

View file

@ -998,6 +998,18 @@ Fehlerbehebung: Supportmails können wieder verschickt werden.</target>
<target state="translated">Beim Umschalten zwischen Lasten-/ Stadträdern ist ein Fehler aufgetreten.
{0}</target>
</trans-unit>
<trans-unit id="MessageErrorSelectBikeNoBikeFound" translate="yes" xml:space="preserve">
<source>No bike with id {0} found.</source>
<target state="translated">Kein Fahrrad mit Id {0} gefunden.</target>
</trans-unit>
<trans-unit id="MessageErrorSelectBikeTitle" translate="yes" xml:space="preserve">
<source>Error Selecting Bike!</source>
<target state="translated">Fehler beim Rad Wählen!</target>
</trans-unit>
<trans-unit id="ChangeLog3_0_277" translate="yes" xml:space="preserve">
<source>Bugfix: No more closing of app on Select Bike page.</source>
<target state="translated">Fehlerbehebung: App schließt sich nicht mehr auf Fahrrad Wählen-Seite.</target>
</trans-unit>
</group>
</body>
</file>

View file

@ -2,6 +2,9 @@
using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
#if !USEFLYOUT
using System.Threading.Tasks;
#endif
using TINK.Model.Connector;
using TINK.Model.Device;
using TINK.Model.State;
@ -323,7 +326,7 @@ namespace TINK.ViewModel.Bikes.Bike
#if USEFLYOUT
=> new Xamarin.Forms.Command(() => ShowAgbPageAsync());
#else
=> new Xamarin.Forms.Command(async () => await OpenLoginPageAsync());
=> new Xamarin.Forms.Command(async () => await ShowAgbPageAsync());
#endif
/// <summary> Opens login page. </summary>

View file

@ -462,9 +462,12 @@ namespace TINK.ViewModel.Contact
typeof(BikesAtStationPage),
p_strStationName);
#else
#if USEFLYOUT
// Show page.
ViewService.ShowPage(ViewTypes.ContactPage, AppResources.MarkingContactPageTitle);
#else
await ViewService.ShowPage("//ContactPage");
#endif
IsMapPageEnabled = true;
ActionText = "";
}
@ -480,14 +483,14 @@ namespace TINK.ViewModel.Contact
"OK");
}
#endif
}
}
/// <summary>
/// Gets the list of station color for all stations.
/// </summary>
/// <param name="stationsId">Station id list to get color for.</param>
/// <returns></returns>
private static IList<Color> GetStationColors(
private static IList<Color> GetStationColors(
IEnumerable<string> stationsId,
BikeCollection bikesAll)
{

View file

@ -47,11 +47,28 @@ namespace TINK.ViewModel.FindBike
}
}
/// <summary>
/// True if any action can be performed (request and cancel request)
/// </summary>
public override bool IsIdle
{
get => base.IsIdle;
set
{
if (value == IsIdle)
return;
Log.ForContext<FindBikePageViewModel>().Debug($"Switch value of {nameof(IsIdle)} to {value}.");
base.IsIdle = value;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsSelectBikeEnabled))); // Enable select bike button.
}
}
/// <summary> Holds all bikes available.</summary>
public BikeCollection Bikes { get; set; }
/// <summary> Do not allow to select bike if id is not set.</summary>
public bool IsSelectBikeEnabled => BikeIdUserInput != null && BikeIdUserInput.Length > 0;
public bool IsSelectBikeEnabled => IsIdle && BikeIdUserInput != null && BikeIdUserInput.Length > 0;
/// <summary> Hide id input fields as soon as bike is found.</summary>
public bool IsSelectBikeVisible => BikeCollection != null && BikeCollection.Count == 0;
@ -125,123 +142,137 @@ namespace TINK.ViewModel.FindBike
/// <summary> Select a bike by ID</summary>
public async Task SelectBike()
{
var selectedBike = Bikes.FirstOrDefault(x => x.Id.Equals(BikeIdUserInput.Trim(), StringComparison.OrdinalIgnoreCase));
if (selectedBike == null)
try
{
await ViewService.DisplayAlert("Fehler bei Radauswahl!", $"Kein Rad mit Id {BikeIdUserInput} gefunden.", "OK");
return;
}
var selectedBike = Bikes.FirstOrDefault(x => x.Id.Equals(BikeIdUserInput.Trim(), StringComparison.OrdinalIgnoreCase));
var bikeCollection = new BikeCollection(new Dictionary<string, Model.Bike.BC.BikeInfo> { { selectedBike.Id, selectedBike } });
var lockIdList = bikeCollection
.GetLockIt()
.Cast<BikeInfo>()
.Select(x => x.LockInfo)
.ToList();
if (LockService is ILocksServiceFake serviceFake)
{
serviceFake.UpdateSimulation(bikeCollection);
}
// Check bluetooth and location permission and states
ActionText = AppResources.ActivityTextCheckBluetoothState;
if (bikeCollection.FirstOrDefault(x => x is BikeInfo btBike) != null
&& RuntimePlatform == Device.Android)
{
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (status != Status.Granted)
if (selectedBike == null)
{
var permissionResult = await PermissionsService.RequestAsync();
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
string.Format(AppResources.MessageErrorSelectBikeNoBikeFound, BikeIdUserInput),
AppResources.MessageAnswerOk);
return;
}
if (permissionResult != Status.Granted)
var bikeCollection = new BikeCollection(new Dictionary<string, Model.Bike.BC.BikeInfo> { { selectedBike.Id, selectedBike } });
var lockIdList = bikeCollection
.GetLockIt()
.Cast<BikeInfo>()
.Select(x => x.LockInfo)
.ToList();
if (LockService is ILocksServiceFake serviceFake)
{
serviceFake.UpdateSimulation(bikeCollection);
}
// Check bluetooth and location permission and states
ActionText = AppResources.ActivityTextCheckBluetoothState;
if (bikeCollection.FirstOrDefault(x => x is BikeInfo btBike) != null
&& RuntimePlatform == Device.Android)
{
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (status != Status.Granted)
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
var permissionResult = await PermissionsService.RequestAsync();
if (!dialogResult)
if (permissionResult != Status.Granted)
{
// User decided not to give access to locations permissions.
BikeCollection.Update(bikeCollection, Stations);
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
//await OnAppearing(() => UpdateTask());
if (!dialogResult)
{
// User decided not to give access to locations permissions.
BikeCollection.Update(bikeCollection, Stations);
ActionText = "";
IsIdle = true;
return;
//await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
// Open permissions dialog.
PermissionsService.OpenAppSettings();
}
}
// Open permissions dialog.
PermissionsService.OpenAppSettings();
// Location state
if (Geolocation.IsGeolcationEnabled == false)
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationActivation,
AppResources.MessageAnswerOk);
BikeCollection.Update(bikeCollection, Stations);
await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
// Bluetooth state
if (await BluetoothService.GetBluetoothState() != BluetoothState.On)
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementBluetoothActivation,
AppResources.MessageAnswerOk);
BikeCollection.Update(bikeCollection, Stations);
await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
}
// Location state
if (Geolocation.IsGeolcationEnabled == false)
// Connect to bluetooth devices.
ActionText = AppResources.ActivityTextSearchBikes;
IEnumerable<LockInfoTdo> locksInfoTdo;
try
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationActivation,
AppResources.MessageAnswerOk);
BikeCollection.Update(bikeCollection, Stations);
await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
locksInfoTdo = await LockService.GetLocksStateAsync(
lockIdList.Select(x => x.ToLockInfoTdo()).ToList(),
LockService.TimeOut.MultiConnect);
}
catch (Exception exception)
{
Log.ForContext<FindBikePageViewModel>().Error("Getting bluetooth state failed. {Exception}", exception);
locksInfoTdo = new List<LockInfoTdo>();
}
// Bluetooth state
if (await BluetoothService.GetBluetoothState() != BluetoothState.On)
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementBluetoothActivation,
AppResources.MessageAnswerOk);
var locksInfo = lockIdList.UpdateById(locksInfoTdo);
BikeCollection.Update(bikeCollection, Stations);
BikeCollection.Update(bikeCollection.UpdateLockInfo(locksInfo), Stations);
await OnAppearing(() => UpdateTask());
await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
}
// Connect to bluetooth devices.
ActionText = AppResources.ActivityTextSearchBikes;
IEnumerable<LockInfoTdo> locksInfoTdo;
try
ActionText = "";
IsIdle = true;
} catch (Exception exception)
{
locksInfoTdo = await LockService.GetLocksStateAsync(
lockIdList.Select(x => x.ToLockInfoTdo()).ToList(),
LockService.TimeOut.MultiConnect);
await ViewService.DisplayAlert(
AppResources.MessageErrorSelectBikeTitle,
exception.Message,
AppResources.MessageAnswerOk);
Log.ForContext<FindBikePageViewModel>().Error("Running command to select bike failed. {Exception}", exception);
return;
}
catch (Exception exception)
{
Log.ForContext<FindBikePageViewModel>().Error("Getting bluetooth state failed. {Exception}", exception);
locksInfoTdo = new List<LockInfoTdo>();
}
var locksInfo = lockIdList.UpdateById(locksInfoTdo);
BikeCollection.Update(bikeCollection.UpdateLockInfo(locksInfo), Stations);
await OnAppearing(() => UpdateTask());
ActionText = "";
IsIdle = true;
}
/// <summary> Create task which updates my bike view model.</summary>