Skip to content
Snippets Groups Projects
Commit 654aa726 authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Can now go back on the bluetooth page. Getting the bluetooth and wifi...

Can now go back on the bluetooth page. Getting the bluetooth and wifi connection is being done first then Styles.
parent cb67f4fc
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
No preview for this file type
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using RobobinApp.Views;
namespace RobobinApp.ViewModels namespace RobobinApp.ViewModels
{ {
public class ConnectionPageViewModel : BaseViewModel public class ConnectionPageViewModel : BaseViewModel
{ {
private BluetoothDevice _selectedDevice; private BluetoothDevice _selectedDevice;
public ICommand GoHomeCommand { get; }
public ObservableCollection<BluetoothDevice> BluetoothDevices { get; } public ObservableCollection<BluetoothDevice> BluetoothDevices { get; }
public ICommand ConnectCommand { get; } public ICommand ConnectCommand { get; }
...@@ -16,8 +17,12 @@ namespace RobobinApp.ViewModels ...@@ -16,8 +17,12 @@ namespace RobobinApp.ViewModels
BluetoothDevices = new ObservableCollection<BluetoothDevice>(); BluetoothDevices = new ObservableCollection<BluetoothDevice>();
ConnectCommand = new Command(OnConnect); ConnectCommand = new Command(OnConnect);
LoadBluetoothDevices(); // Load available devices LoadBluetoothDevices(); // Load available devices
GoHomeCommand = new Command(async () => await OnGoHome());
}
public async Task OnGoHome()
{
await Application.Current.MainPage.Navigation.PushAsync(new MainPage());
} }
public BluetoothDevice SelectedDevice public BluetoothDevice SelectedDevice
{ {
get => _selectedDevice; get => _selectedDevice;
......
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using RobobinApp.Views; using RobobinApp.Views;
namespace RobobinApp.ViewModels namespace RobobinApp.ViewModels
{ {
public class MainPageViewModel : BaseViewModel public class MainPageViewModel : INotifyPropertyChanged
{ {
public ICommand NavigateToConnectionPageCommand { get; } private bool _isBusy;
private string _statusMessage;
public MainPageViewModel()
{ public ICommand ConnectToRobobinCommand { get; }
NavigateToConnectionPageCommand = new Command(OnNavigateToConnectionPage);
} public MainPageViewModel()
{
private async void OnNavigateToConnectionPage() ConnectToRobobinCommand = new Command(async () => await OnConnectToRobobin());
{ }
// Navigate to the ConnectionPage
var connectionPage = new ConnectionPage public bool IsBusy
{ {
BindingContext = new ConnectionPageViewModel() get => _isBusy;
}; set
await Application.Current.MainPage.Navigation.PushAsync(connectionPage); {
} _isBusy = value;
} OnPropertyChanged();
}
}
public string StatusMessage
{
get => _statusMessage;
set
{
_statusMessage = value;
OnPropertyChanged();
}
}
private async Task OnConnectToRobobin()
{
try
{
IsBusy = true;
var connectionPage = new ConnectionPage
{
BindingContext = new ConnectionPageViewModel()
};
await Application.Current.MainPage.Navigation.PushAsync(connectionPage);
}
catch (Exception ex)
{
StatusMessage = $"Failed to connect: {ex.Message}";
await Application.Current.MainPage.DisplayAlert("Error", StatusMessage, "OK");
}
finally
{
IsBusy = false;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
} }
...@@ -3,6 +3,13 @@ ...@@ -3,6 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RobobinApp.Views.ConnectionPage" x:Class="RobobinApp.Views.ConnectionPage"
Title="Connect to Robobin"> Title="Connect to Robobin">
<ContentPage.MenuBarItems>
<MenuBarItem Text="Menu">
<MenuFlyoutItem Text="Back" Command="{Binding GoHomeCommand}" />
</MenuBarItem>
</ContentPage.MenuBarItems>
<StackLayout Padding="20"> <StackLayout Padding="20">
<Label Text="Select a Bluetooth Device" <Label Text="Select a Bluetooth Device"
FontSize="Medium" FontSize="Medium"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment