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

Updated the format to use MVVM, which will help with long term development.

parent 0fb18d65
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
File added
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace RobobinApp
{
public partial class MainPage : ContentPage
{
public ICommand ConnectToRobobinCommand { get; }
public MainPage()
{
InitializeComponent();
// Create the command and assign it to the handler method
ConnectToRobobinCommand = new Command(OnConnectToRobobin);
BindingContext = this; // Set the BindingContext to the current page
}
// Command handler method
private void OnConnectToRobobin()
{
// Logic to connect to Robobin goes here
DisplayAlert("Connection", "Connecting to Robobin...", "OK");
}
}
}
...@@ -5,9 +5,5 @@ ...@@ -5,9 +5,5 @@
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework> <ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile> <ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup />
<MauiXaml Update="LeftBox.xaml">
<SubType>Designer</SubType>
</MauiXaml>
</ItemGroup>
</Project> </Project>
\ No newline at end of file
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace RobobinApp
{
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;
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));
}
}
}
File moved
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RobobinApp" xmlns:local="clr-namespace:RobobinApp"
x:Class="RobobinApp.MainPage" x:Class="RobobinApp.MainPage"
Title=""> Title="">
<ContentPage.Resources> <ContentPage.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> <ResourceDictionary Source="../Resources/Styles/Styles.xaml" />
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<ContentPage.MenuBarItems> <ContentPage.BindingContext>
<MenuBarItem Text="Admin"> <local:MainPageViewModel />
<MenuFlyoutItem Text="Connect to Robobin" Command="{Binding ConnectToRobobinCommand}" /> </ContentPage.BindingContext>
</MenuBarItem>
</ContentPage.MenuBarItems> <ContentPage.MenuBarItems>
<MenuBarItem Text="Admin">
<!-- Main grid that holds all elements --> <MenuFlyoutItem Text="Connect to Robobin" Command="{Binding ConnectToRobobinCommand}" />
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> </MenuBarItem>
</ContentPage.MenuBarItems>
<Grid.RowDefinitions>
<RowDefinition Height="*"/> <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<!-- Only one row filling the available height --> <Grid.RowDefinitions>
</Grid.RowDefinitions> <RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" />
<!-- Left box --> <ColumnDefinition Width="2*" />
<ColumnDefinition Width="2*" /> <ColumnDefinition Width="1*" />
<!-- Center box (bigger) --> </Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<!-- Right box -->
</Grid.ColumnDefinitions>
<!-- Left side box -->
<local:LeftBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> <local:LeftBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<Frame BackgroundColor="White" BorderColor="Black" CornerRadius="5"
<!-- Center (big) box --> HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
<Frame BackgroundColor="White" BorderColor="Black" CornerRadius="5" Grid.Column="1" Grid.Row="0">
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" <Label Text="{Binding StatusMessage}" HorizontalOptions="Center" VerticalOptions="Center"/>
Grid.Column="1" Grid.Row="0"> </Frame>
<Label Text="Center Box" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame> <Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
<!-- Right side box --> Grid.Column="2" Grid.Row="0">
<Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5" <Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/>
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" </Frame>
Grid.Column="2" Grid.Row="0">
<Label Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center"/> <ActivityIndicator IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}"
</Frame> VerticalOptions="Center" HorizontalOptions="Center"/>
</Grid>
</Grid> </ContentPage>
</ContentPage>
using Microsoft.Maui.Controls;
namespace RobobinApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
}
...@@ -91,3 +91,10 @@ For open source projects, say how it is licensed. ...@@ -91,3 +91,10 @@ For open source projects, say how it is licensed.
## Project status ## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
for the application, we are following MVVM
Model: Handles data and business logic (e.g., represents a Robobin object).
View: Displays the UI and interacts with the user (e.g., buttons, labels).
ViewModel: Connects the Model to the View, providing data and commands (e.g., logic to connect to Robobin and update the status).
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment