mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-09-26 00:46:28 +02:00
170 lines
No EOL
6.1 KiB
C#
170 lines
No EOL
6.1 KiB
C#
using Plugin.Connectivity;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using TINK.Model.Bike.BluetoothLock;
|
|
using TINK.View.MasterDetail;
|
|
using TINK.ViewModel;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Xaml;
|
|
|
|
namespace TINK.View.MyBikes
|
|
{
|
|
using Plugin.Permissions.Abstractions;
|
|
using Plugin.Permissions;
|
|
using TINK.Model;
|
|
using TINK.Services.BluetoothLock.Tdo;
|
|
using System.Collections.Generic;
|
|
using Serilog;
|
|
using Plugin.BLE;
|
|
using TINK.Services.BluetoothLock;
|
|
using TINK.ViewModel.MyBikes;
|
|
using Xamarin.CommunityToolkit.Extensions;
|
|
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
public partial class MyBikesPage : ContentPage, IViewService
|
|
{
|
|
/// <summary> Refernce to view model. </summary>
|
|
MyBikesPageViewModel m_oViewModel = null;
|
|
|
|
/// <summary>
|
|
/// Constructs a my bikes page.
|
|
/// </summary>
|
|
public MyBikesPage()
|
|
{
|
|
}
|
|
|
|
/// <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 MyBikesPageViewModel(
|
|
model.ActiveUser,
|
|
model.Permissions,
|
|
CrossBluetoothLE.Current,
|
|
Device.RuntimePlatform,
|
|
() => model.GetIsConnected(),
|
|
(isConnected) => model.GetConnector(isConnected),
|
|
model.Geolocation,
|
|
model.LocksServices.Active,
|
|
model.Polling,
|
|
(d, obj) => synchronizationContext.Post(d, obj),
|
|
this);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Log.ForContext<MyBikesPage>().Error("Displaying bikes at station page failed. {Exception}", exception);
|
|
this.DisplayAlert("Fehler", $"Seite Räder an Station kann nicht angezeigt werden. ${exception.Message}", "OK");
|
|
return;
|
|
|
|
}
|
|
|
|
InitializeComponent();
|
|
|
|
BindingContext = m_oViewModel;
|
|
MyBikesListView.ItemsSource = m_oViewModel;
|
|
|
|
await m_oViewModel.OnAppearing();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invoked when pages is closed/ hidden.
|
|
/// Stops update process.
|
|
/// </summary>
|
|
protected async override void OnDisappearing()
|
|
{
|
|
if (m_oViewModel == null)
|
|
{
|
|
// View model might be null (Example: Occured when page to querry for location permissions was opened)
|
|
return;
|
|
}
|
|
|
|
await m_oViewModel.OnDisappearing();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Displays altert 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 altert 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 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)
|
|
{
|
|
return await App.Current.MainPage.DisplayAlert(p_strTitle, p_strMessage, p_strAccept, p_strCancel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates and a page an shows it.
|
|
/// </summary>
|
|
/// <param name="p_oTypeOfPage">Type of page to show.</param>
|
|
public void ShowPage(ViewTypes p_oType, string p_strTitle = null)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
/// <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();
|
|
}
|
|
|
|
public async Task<IViewService.IUserFeedback> DisplayUserFeedbackPopup() => await Navigation.ShowPopupAsync<FeedbackPopup.Result>(new FeedbackPopup());
|
|
}
|
|
} |