diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index edad2944383fffb584973cd763e95ac8251948f6..f1e2a1d8e4e8c7291713d7e5765ea83bd5c35858 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/App/RobobinApp/App.xaml.cs b/App/RobobinApp/App.xaml.cs index 54855d76c62e51159d415adbd5fe94943c7a9a54..0feb8e721587139b919707a528d8a3459cdc0913 100644 --- a/App/RobobinApp/App.xaml.cs +++ b/App/RobobinApp/App.xaml.cs @@ -1,11 +1,29 @@ -namespace RobobinApp; +using Microsoft.Extensions.Logging; +namespace RobobinApp; public partial class App : Application { - public App() - { - InitializeComponent(); + public App() + { + InitializeComponent(); + ConfigureLogging(); + MainPage = new AppShell(); + } + private void ConfigureLogging() + { + // Create a LoggerFactory + var loggerFactory = LoggerFactory.Create(builder => + { + builder + .AddConsole() + .AddDebug(); + }); - MainPage = new AppShell(); - } + // Store the logger factory for later use + Logger = loggerFactory.CreateLogger<App>(); + } + + public ILogger<App> Logger { get; private set; } } + + diff --git a/App/RobobinApp/AppShell.xaml b/App/RobobinApp/AppShell.xaml index 2785781bd00f4bee7c280ed448ad370baf09024b..270d8c2c43d06395bee14da8e8b033b79bb315ac 100644 --- a/App/RobobinApp/AppShell.xaml +++ b/App/RobobinApp/AppShell.xaml @@ -1,14 +1,8 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<Shell - x:Class="RobobinApp.AppShell" - xmlns="http://schemas.microsoft.com/dotnet/2021/maui" - xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" - xmlns:local="clr-namespace:RobobinApp" - Title="RobobinApp"> +<?xml version="1.0" encoding="utf-8" ?> +<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:views="clr-namespace:RobobinApp.Views" + x:Class="RobobinApp.AppShell"> - <ShellContent - Title="Home" - ContentTemplate="{DataTemplate local:MainPage}" - Route="MainPage" /> - -</Shell> + <ShellContent ContentTemplate="{DataTemplate views:MainPage}" /> +</Shell> \ No newline at end of file diff --git a/App/RobobinApp/RobobinApp.csproj b/App/RobobinApp/RobobinApp.csproj index fc923e6d29e3f18e9a68ed82427fdd54940a8134..fe8ef06b6563ae3d0be1d94040e532c88a417eb4 100644 --- a/App/RobobinApp/RobobinApp.csproj +++ b/App/RobobinApp/RobobinApp.csproj @@ -57,6 +57,7 @@ </ItemGroup> <ItemGroup> + <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" /> <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> @@ -66,12 +67,18 @@ <Compile Update="LeftBox.xaml.cs"> <DependentUpon>LeftBox.xaml</DependentUpon> </Compile> + <Compile Update="Views\ConnectionPage.xaml.cs"> + <DependentUpon>ConnectionPage.xaml</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> <MauiXaml Update="LeftBox.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> + <MauiXaml Update="Views\ConnectionPage.xaml"> + <Generator>MSBuild:Compile</Generator> + </MauiXaml> </ItemGroup> </Project> diff --git a/App/RobobinApp/RobobinApp.csproj.user b/App/RobobinApp/RobobinApp.csproj.user index 1c649b0efce9a13abc7e4fca338a5ee46e7d5ec1..5ac6ce85f74619c22e653ccc66e3362a9450ec3b 100644 --- a/App/RobobinApp/RobobinApp.csproj.user +++ b/App/RobobinApp/RobobinApp.csproj.user @@ -5,5 +5,9 @@ <ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework> <ActiveDebugProfile>Windows Machine</ActiveDebugProfile> </PropertyGroup> - <ItemGroup /> + <ItemGroup> + <MauiXaml Update="Views\ConnectionPage.xaml"> + <SubType>Designer</SubType> + </MauiXaml> + </ItemGroup> </Project> \ No newline at end of file diff --git a/App/RobobinApp/ViewModels/BaseViewModel.cs b/App/RobobinApp/ViewModels/BaseViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..7d99c718b35afb474a4089bdf94f72b66f2974c0 --- /dev/null +++ b/App/RobobinApp/ViewModels/BaseViewModel.cs @@ -0,0 +1,15 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace RobobinApp.ViewModels +{ + public class BaseViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..3c91b6642807d942c7e472ee47e74b86ecdb4ad4 --- /dev/null +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using System.Windows.Input; +using Microsoft.Maui.Controls; + +namespace RobobinApp.ViewModels +{ + public class ConnectionPageViewModel : BaseViewModel + { + private BluetoothDevice _selectedDevice; + + public ObservableCollection<BluetoothDevice> BluetoothDevices { get; } + public ICommand ConnectCommand { get; } + + public ConnectionPageViewModel() + { + BluetoothDevices = new ObservableCollection<BluetoothDevice>(); + ConnectCommand = new Command(OnConnect); + LoadBluetoothDevices(); // Load available devices + } + + public BluetoothDevice SelectedDevice + { + get => _selectedDevice; + set + { + _selectedDevice = value; + OnPropertyChanged(); // Notify UI that SelectedDevice has changed + } + } + + private async void LoadBluetoothDevices() + { + // Logic to load available Bluetooth devices + // This is a placeholder for your Bluetooth device discovery logic + BluetoothDevices.Add(new BluetoothDevice { Name = "Device 1" }); + BluetoothDevices.Add(new BluetoothDevice { Name = "Device 2" }); + } + + private async void OnConnect() + { + if (SelectedDevice == null) return; + + // Logic to connect to the selected Bluetooth device + await Application.Current.MainPage.DisplayAlert("Connection", $"Connecting to {SelectedDevice.Name}...", "OK"); + // Implement actual connection logic here + } + } + + public class BluetoothDevice // Define this class to represent a Bluetooth device + { + public string Name { get; set; } + } +} diff --git a/App/RobobinApp/ViewModels/MainPageViewModel.cs b/App/RobobinApp/ViewModels/MainPageViewModel.cs index fd52b835b428c35dfa0c837468178e173789b2ea..ddc5ff7b5c24ba1ab0d527fbc7ff0a9a1aca5d3d 100644 --- a/App/RobobinApp/ViewModels/MainPageViewModel.cs +++ b/App/RobobinApp/ViewModels/MainPageViewModel.cs @@ -1,67 +1,26 @@ -using System.ComponentModel; -using System.Runtime.CompilerServices; using System.Windows.Input; using Microsoft.Maui.Controls; +using RobobinApp.Views; -namespace RobobinApp +namespace RobobinApp.ViewModels { - public class MainPageViewModel : INotifyPropertyChanged + public class MainPageViewModel : BaseViewModel { - private bool _isBusy; - private string _statusMessage; - - public ICommand ConnectToRobobinCommand { get; } + public ICommand NavigateToConnectionPageCommand { get; } public MainPageViewModel() { - ConnectToRobobinCommand = new Command(async () => await OnConnectToRobobin()); - } - - public bool IsBusy - { - get => _isBusy; - set - { - _isBusy = value; - OnPropertyChanged(); - } + NavigateToConnectionPageCommand = new Command(OnNavigateToConnectionPage); } - public string StatusMessage + private async void OnNavigateToConnectionPage() { - get => _statusMessage; - set + // Navigate to the ConnectionPage + var connectionPage = new ConnectionPage { - _statusMessage = value; - OnPropertyChanged(); - } - } - - private async Task OnConnectToRobobin() - { - try - { - IsBusy = true; - StatusMessage = "Connecting to Robobin..."; - StatusMessage = "Connected to Robobin!"; - await Application.Current.MainPage.DisplayAlert("Connection", StatusMessage, "OK"); - } - 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)); + BindingContext = new ConnectionPageViewModel() + }; + await Application.Current.MainPage.Navigation.PushAsync(connectionPage); } } } diff --git a/App/RobobinApp/Views/ConnectionPage.xaml b/App/RobobinApp/Views/ConnectionPage.xaml new file mode 100644 index 0000000000000000000000000000000000000000..28b40f621b157fbde8cb35e9f09e6d3c1baf151a --- /dev/null +++ b/App/RobobinApp/Views/ConnectionPage.xaml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8" ?> +<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="RobobinApp.Views.ConnectionPage" + Title="Connect to Robobin"> + <StackLayout Padding="20"> + <Label Text="Select a Bluetooth Device" + FontSize="Medium" + HorizontalOptions="Center" + VerticalOptions="Start" /> + + <!-- ListView to display available Bluetooth devices --> + <ListView x:Name="DeviceListView" + ItemsSource="{Binding BluetoothDevices}" + SelectedItem="{Binding SelectedDevice}" + VerticalOptions="FillAndExpand"> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text="{Binding Name}" /> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + + <!-- Connect Button --> + <Button Text="Connect" + Command="{Binding ConnectCommand}" + IsEnabled="{Binding SelectedDevice, Converter={StaticResource NullToBooleanConverter}}" + HorizontalOptions="Center" + VerticalOptions="End" /> + </StackLayout> +</ContentPage> diff --git a/App/RobobinApp/Views/ConnectionPage.xaml.cs b/App/RobobinApp/Views/ConnectionPage.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..446d016579e3e40a5c7a3a520c15d146add14b27 --- /dev/null +++ b/App/RobobinApp/Views/ConnectionPage.xaml.cs @@ -0,0 +1,9 @@ +namespace RobobinApp.Views; + +public partial class ConnectionPage : ContentPage +{ + public ConnectionPage() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/App/RobobinApp/Views/LeftBox.xaml b/App/RobobinApp/Views/LeftBox.xaml index bd9a8a54a191fdaafa6a1b3edc80fcba797438f5..6b5fff0d0d3177e238940953023d162dfc8afca3 100644 --- a/App/RobobinApp/Views/LeftBox.xaml +++ b/App/RobobinApp/Views/LeftBox.xaml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" - x:Class="RobobinApp.LeftBox" + x:Class="RobobinApp.Views.LeftBox" BackgroundColor="Lavender"> <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Label BackgroundColor="Black">Test</Label> diff --git a/App/RobobinApp/Views/LeftBox.xaml.cs b/App/RobobinApp/Views/LeftBox.xaml.cs index cbc9a908a3dfab87948b4929c8bd042785bd67bf..6a829747ea9ad2b2689a75204e926cbf0f237edd 100644 --- a/App/RobobinApp/Views/LeftBox.xaml.cs +++ b/App/RobobinApp/Views/LeftBox.xaml.cs @@ -1,6 +1,6 @@ using Microsoft.Maui.Controls; -namespace RobobinApp +namespace RobobinApp.Views { public partial class LeftBox : ContentView { diff --git a/App/RobobinApp/Views/MainPage.xaml b/App/RobobinApp/Views/MainPage.xaml index 50c57893ae4276fe151c4b67bc99ee753bb06885..983bcd12495213e5119ecb9bcb3aa90451ca1b34 100644 --- a/App/RobobinApp/Views/MainPage.xaml +++ b/App/RobobinApp/Views/MainPage.xaml @@ -1,9 +1,13 @@ <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" - xmlns:local="clr-namespace:RobobinApp" - x:Class="RobobinApp.MainPage" + xmlns:local="clr-namespace:RobobinApp.Views" + xmlns:viewModels="clr-namespace:RobobinApp.ViewModels" + x:Class="RobobinApp.Views.MainPage" Title=""> + <ContentPage.BindingContext> + <viewModels:MainPageViewModel /> + </ContentPage.BindingContext> <ContentPage.Resources> <ResourceDictionary> @@ -11,10 +15,6 @@ </ResourceDictionary> </ContentPage.Resources> - <ContentPage.BindingContext> - <local:MainPageViewModel /> - </ContentPage.BindingContext> - <ContentPage.MenuBarItems> <MenuBarItem Text="Admin"> <MenuFlyoutItem Text="Connect to Robobin" Command="{Binding ConnectToRobobinCommand}" /> @@ -44,8 +44,5 @@ Grid.Column="2" Grid.Row="0"> <Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/> </Frame> - - <ActivityIndicator IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" - VerticalOptions="Center" HorizontalOptions="Center"/> </Grid> </ContentPage> diff --git a/App/RobobinApp/Views/MainPage.xaml.cs b/App/RobobinApp/Views/MainPage.xaml.cs index 12de2551ca87df74faab0d3aa8a2d759f648c1ad..849c542164db32ba8b3f48a21b93939e6f01bb29 100644 --- a/App/RobobinApp/Views/MainPage.xaml.cs +++ b/App/RobobinApp/Views/MainPage.xaml.cs @@ -1,6 +1,7 @@ using Microsoft.Maui.Controls; +using Microsoft.Extensions.DependencyInjection; -namespace RobobinApp +namespace RobobinApp.Views { public partial class MainPage : ContentPage {