diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index f1e2a1d8e4e8c7291713d7e5765ea83bd5c35858..ddce4cda1e8734ebd50cba8503c15bb5c329d3f6 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index 3c91b6642807d942c7e472ee47e74b86ecdb4ad4..9802d25ee5ff90ea672e7112f239e28392acc894 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -1,13 +1,14 @@ 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; diff --git a/App/RobobinApp/ViewModels/MainPageViewModel.cs b/App/RobobinApp/ViewModels/MainPageViewModel.cs index ddc5ff7b5c24ba1ab0d527fbc7ff0a9a1aca5d3d..d2387784a0e14eed25d5602d06b4f41951c9b65f 100644 --- a/App/RobobinApp/ViewModels/MainPageViewModel.cs +++ b/App/RobobinApp/ViewModels/MainPageViewModel.cs @@ -1,26 +1,73 @@ +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)); + } + } } diff --git a/App/RobobinApp/Views/ConnectionPage.xaml b/App/RobobinApp/Views/ConnectionPage.xaml index 28b40f621b157fbde8cb35e9f09e6d3c1baf151a..ab9493fd7b02f4571fc53cf632a1d64ea5fc49c2 100644 --- a/App/RobobinApp/Views/ConnectionPage.xaml +++ b/App/RobobinApp/Views/ConnectionPage.xaml @@ -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"