mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-02-22 19:06:28 +01:00
Continued implementing FindBike functionality by using MyBikes as template.
This commit is contained in:
parent
874166f26f
commit
8e84b6deda
5 changed files with 269 additions and 20 deletions
|
@ -1,12 +1,50 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="TINK.View.FindBike.FindBikePage">
|
x:Class="TINK.View.FindBike.FindBikePage"
|
||||||
|
xmlns:local_bike="clr-namespace:TINK.View.Bike">
|
||||||
|
<ContentPage.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<local_bike:BikeViewCellTemplateSelector x:Key="bikeTemplateSelector"/>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</ContentPage.Resources>
|
||||||
<ContentPage.Content>
|
<ContentPage.Content>
|
||||||
<StackLayout>
|
<Frame>
|
||||||
<Label Text="Welcome to Xamarin.Forms!"
|
<StackLayout>
|
||||||
|
<Label Text="Welcome to Xamarin.Forms!"
|
||||||
VerticalOptions="CenterAndExpand"
|
VerticalOptions="CenterAndExpand"
|
||||||
HorizontalOptions="CenterAndExpand" />
|
HorizontalOptions="CenterAndExpand" />
|
||||||
</StackLayout>
|
<ListView
|
||||||
|
x:Name="FindBikeListView"
|
||||||
|
SelectionMode="None"
|
||||||
|
SelectedItem="{Binding SelectedBike}"
|
||||||
|
IsEnabled="{Binding IsIdle}"
|
||||||
|
IsVisible="{Binding IsBikesListVisible}"
|
||||||
|
HasUnevenRows="True"
|
||||||
|
ItemTemplate="{StaticResource bikeTemplateSelector}"/>
|
||||||
|
<StackLayout
|
||||||
|
VerticalOptions="EndAndExpand"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<Label
|
||||||
|
HeightRequest="20"
|
||||||
|
Text="{Binding StatusInfoText}"
|
||||||
|
VerticalOptions="Center"
|
||||||
|
HorizontalOptions="FillAndExpand"/>
|
||||||
|
<ActivityIndicator IsRunning="{Binding IsRunning}"
|
||||||
|
IsVisible="{Binding IsRunning}"
|
||||||
|
HeightRequest="20"
|
||||||
|
VerticalOptions="CenterAndExpand"
|
||||||
|
HorizontalOptions="End">
|
||||||
|
<ActivityIndicator.WidthRequest>
|
||||||
|
<OnPlatform x:TypeArguments="x:Double" iOS="40" Android="40" WinPhone="40" />
|
||||||
|
</ActivityIndicator.WidthRequest>
|
||||||
|
<ActivityIndicator.Color>
|
||||||
|
<OnPlatform x:TypeArguments="Color"
|
||||||
|
iOS="#2499CE" WinPhone="#2499CE" />
|
||||||
|
</ActivityIndicator.Color>
|
||||||
|
</ActivityIndicator>
|
||||||
|
</StackLayout>
|
||||||
|
</StackLayout>
|
||||||
|
</Frame>
|
||||||
</ContentPage.Content>
|
</ContentPage.Content>
|
||||||
</ContentPage>
|
</ContentPage>
|
|
@ -1,14 +1,144 @@
|
||||||
using Xamarin.Forms;
|
using Serilog;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TINK.ViewModel.FindBike;
|
||||||
|
using Xamarin.CommunityToolkit.Extensions;
|
||||||
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Xaml;
|
using Xamarin.Forms.Xaml;
|
||||||
|
|
||||||
namespace TINK.View.FindBike
|
namespace TINK.View.FindBike
|
||||||
{
|
{
|
||||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||||
public partial class FindBikePage : ContentPage
|
public partial class FindBikePage : ContentPage, IViewService
|
||||||
{
|
{
|
||||||
public FindBikePage ()
|
/// <summary> Refernce to view model. </summary>
|
||||||
{
|
FindBikePageViewModel m_oViewModel = null;
|
||||||
InitializeComponent ();
|
|
||||||
}
|
public FindBikePage () { }
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when page is shown.
|
||||||
|
/// Starts update process.
|
||||||
|
/// </summary>
|
||||||
|
protected async override void OnAppearing()
|
||||||
|
{
|
||||||
|
if (m_oViewModel != null)
|
||||||
|
{
|
||||||
|
// No need to create view model, set binding context an items source if already done.
|
||||||
|
// If done twice tap events are fired multiple times (when hiding page using home button).
|
||||||
|
await m_oViewModel.OnAppearing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = App.ModelRoot;
|
||||||
|
|
||||||
|
// Backup synchronization context when called from GUI-thread.
|
||||||
|
var synchronizationContext = SynchronizationContext.Current;
|
||||||
|
|
||||||
|
m_oViewModel = new FindBikePageViewModel(
|
||||||
|
model.ActiveUser,
|
||||||
|
App.PermissionsService,
|
||||||
|
App.BluetoothService,
|
||||||
|
Device.RuntimePlatform,
|
||||||
|
() => model.GetIsConnected(),
|
||||||
|
(isConnected) => model.GetConnector(isConnected),
|
||||||
|
App.GeolocationServicesContainer.Active,
|
||||||
|
model.LocksServices.Active,
|
||||||
|
model.Polling,
|
||||||
|
(d, obj) => synchronizationContext.Post(d, obj),
|
||||||
|
model.SmartDevice,
|
||||||
|
this)
|
||||||
|
{
|
||||||
|
IsReportLevelVerbose = model.IsReportLevelVerbose
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Log.ForContext<FindBikePage>().Error("Displaying bikes at station page failed. {Exception}", exception);
|
||||||
|
await DisplayAlert("Fehler", $"Seite Fahrrad Wählen kann nicht angezeigt werden. ${exception.Message}", "OK");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
BindingContext = m_oViewModel;
|
||||||
|
FindBikeListView.ItemsSource = m_oViewModel;
|
||||||
|
|
||||||
|
await m_oViewModel.OnAppearing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays alert message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p_strTitle">Title of message.</param>
|
||||||
|
/// <param name="p_strMessage">Message to display.</param>
|
||||||
|
/// <param name="p_strCancel">Type of buttons.</param>
|
||||||
|
public new async Task DisplayAlert(string p_strTitle, string p_strMessage, string p_strCancel)
|
||||||
|
=> await App.Current.MainPage.DisplayAlert(p_strTitle, p_strMessage, p_strCancel);
|
||||||
|
|
||||||
|
/// <summary> Displays alert message.</summary>
|
||||||
|
/// <param name="title">Title of message.</param>
|
||||||
|
/// <param name="message">Message to display.</param>
|
||||||
|
/// <param name="details">Detailed error description.</param>
|
||||||
|
/// <param name="cancel">Type of buttons.</param>
|
||||||
|
public async Task DisplayAdvancedAlert(
|
||||||
|
string title,
|
||||||
|
string message,
|
||||||
|
string details,
|
||||||
|
string cancel)
|
||||||
|
=> await App.Current.MainPage.DisplayAlert(title, $"{message}\r\nDetails:\r\n{details}", cancel);
|
||||||
|
|
||||||
|
/// <summary> Displays detailed alert message.</summary>
|
||||||
|
/// <param name="title">Title of message.</param>
|
||||||
|
/// <param name="message">Message to display.</param>
|
||||||
|
/// <param name="details">Detailed error description.</param>
|
||||||
|
/// <param name="accept">Text of accept button.</param>
|
||||||
|
/// <param name="cancel">Text of cancel button.</param>
|
||||||
|
/// <returns>True if user pressed accept.</returns>
|
||||||
|
public async Task<bool> DisplayAdvancedAlert(string title, string message, string details, string accept, string cancel)
|
||||||
|
=> await App.Current.MainPage.DisplayAlert(title, $"{message}\r\nDetails:\r\n{details}", accept, cancel);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays alert message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p_strTitle">Title of message.</param>
|
||||||
|
/// <param name="p_strMessage">Message to display.</param>
|
||||||
|
/// <param name="p_strAccept">Text of accept button.</param>
|
||||||
|
/// <param name="p_strCancel">Text of button.</param>
|
||||||
|
/// <returns>True if user pressed accept.</returns>
|
||||||
|
public new async Task<bool> DisplayAlert(string p_strTitle, string p_strMessage, string p_strAccept, string p_strCancel)
|
||||||
|
=> await App.Current.MainPage.DisplayAlert(p_strTitle, p_strMessage, p_strAccept, p_strCancel);
|
||||||
|
|
||||||
|
#if USEMASTERDETAIL || USEFLYOUT
|
||||||
|
public void ShowPage(ViewTypes p_oType, string p_strTitle = null)
|
||||||
|
=> throw new NotImplementedException();
|
||||||
|
#else
|
||||||
|
/// <summary> Shows a page.</summary>
|
||||||
|
/// <param name="route">Route of the page to show.</param>
|
||||||
|
public async Task ShowPage(string route) => await Shell.Current.GoToAsync(route);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary> Pushes a page onto the modal stack. </summary>
|
||||||
|
/// <param name="p_oTypeOfPage">Page to display.</param>
|
||||||
|
public Task PushModalAsync(ViewTypes p_oTypeOfPage) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
/// <summary> Pops a page from the modal stack. </summary>
|
||||||
|
public Task PopModalAsync() => throw new NotSupportedException();
|
||||||
|
|
||||||
|
/// <summary> Pushes a page onto the stack. </summary>
|
||||||
|
/// <param name="p_oTypeOfPage">Page to display.</param>
|
||||||
|
public Task PushAsync(ViewTypes p_oTypeOfPage) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
#if USCSHARP9
|
||||||
|
public async Task<IViewService.IUserFeedback> DisplayUserFeedbackPopup() => await Navigation.ShowPopupAsync<FeedbackPopup.Result>(new FeedbackPopup());
|
||||||
|
#else
|
||||||
|
public async Task<IUserFeedback> DisplayUserFeedbackPopup() => await Navigation.ShowPopupAsync<FeedbackPopup.Result>(new FeedbackPopup());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ namespace TINK.Model.Bike
|
||||||
// Needed to remove bikes which switched state and have to be removed from collection.
|
// Needed to remove bikes which switched state and have to be removed from collection.
|
||||||
var bikesToBeRemoved = this.Select(x => x.Id).ToList();
|
var bikesToBeRemoved = this.Select(x => x.Id).ToList();
|
||||||
|
|
||||||
foreach (var bikeInfo in (bikesAll ?? new List<BikeInfo>()))
|
foreach (var bikeInfo in bikesAll ?? new List<BikeInfo>())
|
||||||
{
|
{
|
||||||
/// Check if bike has to be added to list of existing station.
|
/// Check if bike has to be added to list of existing station.
|
||||||
if (ContainsKey(bikeInfo.Id) == false)
|
if (ContainsKey(bikeInfo.Id) == false)
|
||||||
|
|
88
TINKLib/ViewModel/FindBike/FindBikePageViewModel.cs
Normal file
88
TINKLib/ViewModel/FindBike/FindBikePageViewModel.cs
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
|
||||||
|
using Serilog;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TINK.Model.Bike;
|
||||||
|
using TINK.Model.Connector;
|
||||||
|
using TINK.Model.User;
|
||||||
|
using TINK.View;
|
||||||
|
using TINK.Settings;
|
||||||
|
using TINK.Model.Bike.BluetoothLock;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TINK.Services.BluetoothLock;
|
||||||
|
using TINK.Model.Services.Geolocation;
|
||||||
|
using System.Linq;
|
||||||
|
using TINK.Model;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using TINK.ViewModel.Bikes;
|
||||||
|
using TINK.Services.BluetoothLock.Tdo;
|
||||||
|
using Plugin.Permissions;
|
||||||
|
using Plugin.Permissions.Abstractions;
|
||||||
|
using Plugin.BLE.Abstractions.Contracts;
|
||||||
|
using TINK.MultilingualResources;
|
||||||
|
using TINK.Model.Device;
|
||||||
|
|
||||||
|
namespace TINK.ViewModel.FindBike
|
||||||
|
{
|
||||||
|
public class FindBikePageViewModel : BikesViewModel, INotifyCollectionChanged, INotifyPropertyChanged
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs bike collection view model in case information about occupied bikes is available.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="p_oUser">Mail address of active user.</param>
|
||||||
|
/// <param name="isReportLevelVerbose">True if report level is verbose, false if not.</param>
|
||||||
|
/// <param name="permissions">Holds object to query location permisions.</param>
|
||||||
|
/// <param name="bluetoothLE">Holds object to query bluetooth state.</param>
|
||||||
|
/// <param name="runtimPlatform">Specifies on which platform code is run.</param>
|
||||||
|
/// <param name="isConnectedDelegate">Returns if mobile is connected to web or not.</param>
|
||||||
|
/// <param name="connectorFactory">Connects system to copri.</param>
|
||||||
|
/// <param name="lockService">Service to control lock retrieve info.</param>
|
||||||
|
/// <param name="polling"> 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="viewService">Interface to actuate methodes on GUI.</param>
|
||||||
|
public FindBikePageViewModel(
|
||||||
|
User p_oUser,
|
||||||
|
IPermissions permissions,
|
||||||
|
IBluetoothLE bluetoothLE,
|
||||||
|
string runtimPlatform,
|
||||||
|
Func<bool> isConnectedDelegate,
|
||||||
|
Func<bool, IConnector> connectorFactory,
|
||||||
|
IGeolocation geolocation,
|
||||||
|
ILocksService lockService,
|
||||||
|
PollingParameters polling,
|
||||||
|
Action<SendOrPostCallback, object> postAction,
|
||||||
|
ISmartDevice smartDevice,
|
||||||
|
IViewService viewService) : base(p_oUser, permissions, bluetoothLE, runtimPlatform, isConnectedDelegate, connectorFactory, geolocation, lockService, polling, postAction, smartDevice, viewService, () => new MyBikeInUseStateInfoProvider())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when page is shown.
|
||||||
|
/// Starts update process.
|
||||||
|
/// </summary>
|
||||||
|
public async Task OnAppearing()
|
||||||
|
{
|
||||||
|
// Get my bikes from COPRI
|
||||||
|
Log.ForContext<FindBikePageViewModel>().Information("User request to show page MyBikes/ page re-appearing");
|
||||||
|
|
||||||
|
ActionText = AppResources.ActivityTextMyBikesLoadingBikes;
|
||||||
|
|
||||||
|
var bikes = await ConnectorFactory(IsConnected).Query.GetBikesAsync();
|
||||||
|
|
||||||
|
Exception = bikes.Exception; // Update communication error from query for bikes occupied.
|
||||||
|
|
||||||
|
BikeIds = bikes.Response.Select(x => x.Id);
|
||||||
|
|
||||||
|
ActionText = "";
|
||||||
|
IsIdle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IEnumerable<string> BikeIds { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
|
|
||||||
namespace TINK.ViewModel.FindBike
|
|
||||||
{
|
|
||||||
public class FindBikeViewModel
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue