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.Windows.Input;
using Microsoft.Maui.Controls;
using RobobinApp.Views;
namespace RobobinApp.ViewModels
{
public class ConnectionPageViewModel : BaseViewModel
{
private BluetoothDevice _selectedDevice;
public ICommand GoHomeCommand { get; }
public ObservableCollection<BluetoothDevice> BluetoothDevices { get; }
public ICommand ConnectCommand { get; }
......@@ -16,8 +17,12 @@ namespace RobobinApp.ViewModels
BluetoothDevices = new ObservableCollection<BluetoothDevice>();
ConnectCommand = new Command(OnConnect);
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
{
get => _selectedDevice;
......
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls;
using RobobinApp.Views;
namespace RobobinApp.ViewModels
{
public class MainPageViewModel : BaseViewModel
{
public ICommand NavigateToConnectionPageCommand { get; }
public MainPageViewModel()
{
NavigateToConnectionPageCommand = new Command(OnNavigateToConnectionPage);
}
private async void OnNavigateToConnectionPage()
{
// Navigate to the ConnectionPage
var connectionPage = new ConnectionPage
{
BindingContext = new ConnectionPageViewModel()
};
await Application.Current.MainPage.Navigation.PushAsync(connectionPage);
}
}
public class MainPageViewModel : INotifyPropertyChanged
{
private bool _isBusy;
private string _statusMessage;
public ICommand ConnectToRobobinCommand { get; }
public MainPageViewModel()
{
ConnectToRobobinCommand = new Command(async () => await OnConnectToRobobin());
}
public bool IsBusy
{
get => _isBusy;
set
{
_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 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RobobinApp.Views.ConnectionPage"
Title="Connect to Robobin">
<ContentPage.MenuBarItems>
<MenuBarItem Text="Menu">
<MenuFlyoutItem Text="Back" Command="{Binding GoHomeCommand}" />
</MenuBarItem>
</ContentPage.MenuBarItems>
<StackLayout Padding="20">
<Label Text="Select a Bluetooth Device"
FontSize="Medium"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment