From 10adbe940c028707bef2065f38dd1cfca1225789 Mon Sep 17 00:00:00 2001 From: Paul-Winpenny <92634321+Paul-Winpenny@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:25:55 +0100 Subject: [PATCH] Css added, now making it pretty is key --- App/RobobinApp/App.xaml | 4 +- App/RobobinApp/Interfaces/BLEClasses.cs | 21 ++++++ App/RobobinApp/MauiProgram.cs | 5 +- App/RobobinApp/Resources/Styles/appstyle.css | 75 +++++++++++++++++++ .../ViewModels/ConnectionPageViewModel.cs | 20 +++++ App/RobobinApp/Views/LeftBox.xaml | 12 --- App/RobobinApp/Views/LeftBox.xaml.cs | 12 --- App/RobobinApp/Views/MainPage.xaml | 18 ++++- 8 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 App/RobobinApp/Interfaces/BLEClasses.cs create mode 100644 App/RobobinApp/Resources/Styles/appstyle.css delete mode 100644 App/RobobinApp/Views/LeftBox.xaml delete mode 100644 App/RobobinApp/Views/LeftBox.xaml.cs diff --git a/App/RobobinApp/App.xaml b/App/RobobinApp/App.xaml index 56a59004..d16152ef 100644 --- a/App/RobobinApp/App.xaml +++ b/App/RobobinApp/App.xaml @@ -1,4 +1,4 @@ -<?xml version = "1.0" encoding = "UTF-8" ?> +<?xml version="1.0" encoding="UTF-8" ?> <Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:RobobinApp" @@ -9,6 +9,8 @@ <ResourceDictionary Source="Resources/Styles/Colors.xaml" /> <ResourceDictionary Source="Resources/Styles/Styles.xaml" /> </ResourceDictionary.MergedDictionaries> + + <StyleSheet Source="/Resources/Styles/appstyle.css" /> </ResourceDictionary> </Application.Resources> </Application> diff --git a/App/RobobinApp/Interfaces/BLEClasses.cs b/App/RobobinApp/Interfaces/BLEClasses.cs new file mode 100644 index 00000000..d0823784 --- /dev/null +++ b/App/RobobinApp/Interfaces/BLEClasses.cs @@ -0,0 +1,21 @@ +using Plugin.BLE.Abstractions.Contracts; +using Plugin.BLE; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Robobin.Interfaces +{ + public class BluetoothLEService : IBluetoothLEService + { + public IBluetoothLE Current => CrossBluetoothLE.Current; + } + + public class AdapterService : IAdapterService + { + public IAdapter Adapter => CrossBluetoothLE.Current.Adapter; + } + +} diff --git a/App/RobobinApp/MauiProgram.cs b/App/RobobinApp/MauiProgram.cs index df11d1d0..b66f8298 100644 --- a/App/RobobinApp/MauiProgram.cs +++ b/App/RobobinApp/MauiProgram.cs @@ -1,5 +1,4 @@  -using Shiny; namespace RobobinApp; @@ -11,7 +10,7 @@ public static class MauiProgram var builder = MauiApp .CreateBuilder() .UseMauiApp<App>() - .UseShiny() + .ConfigureFonts(fonts => { @@ -20,7 +19,7 @@ public static class MauiProgram }); - builder.Services.AddBluetoothLE(); + return builder.Build(); } diff --git a/App/RobobinApp/Resources/Styles/appstyle.css b/App/RobobinApp/Resources/Styles/appstyle.css new file mode 100644 index 00000000..e7f7ab9e --- /dev/null +++ b/App/RobobinApp/Resources/Styles/appstyle.css @@ -0,0 +1,75 @@ +navigationpage { + -maui-bar-background-color: lightgray; +} + +^contentpage { + background-color: lightgray; +} + +#listView { + background-color: lightgray; +} + +stacklayout { + margin: 20; + -maui-spacing: 6; +} + +grid { + row-gap: 6; + column-gap: 6; +} + +.mainPageTitle { + font-style: bold; + font-size: 14; +} + +.mainPageSubtitle { + margin-top: 15; +} + +.detailPageTitle { + font-style: bold; + font-size: 14; + text-align: center; +} + +.detailPageSubtitle { + text-align: center; + font-style: italic; +} + +listview image { + height: 60; + width: 60; +} + +stacklayout > image { + height: 200; + width: 200; +} +.mainFrame { + background-color: White; + border-color: Black; + corner-radius: 5; +} + +.sideFrame { + background-color: #2B333E; + border-color: Black; + corner-radius: 5; +} + +.sideBox { + background-color: lightgray; /* Change to your preferred background color */ + border: 1px solid black; /* Optional: adds a border */ + padding: 20px; /* Space inside the box */ + margin: auto; /* Centers the box horizontally */ + width: 150px; /* Fixed width, adjust as needed */ + height: 100px; /* Fixed height, adjust as needed */ + display: flex; /* Enables flexbox for centering content */ + justify-content: center; /* Centers content horizontally */ + align-items: center; /* Centers content vertically */ + border-radius: 8px; /* Optional: rounded corners */ +} \ No newline at end of file diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index 9a4c2b1f..9afd9cff 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -272,6 +272,7 @@ namespace RobobinApp.ViewModels Debug.WriteLine("Starting scanning for devices..."); await _adapter.StartScanningForDevicesAsync(); + } catch (Exception ex) { @@ -289,12 +290,30 @@ namespace RobobinApp.ViewModels e.Device.Id.ToString() ); + // Check if the device is already in the list if (!BluetoothDevices.Any(d => d.MacAddress == bluetoothDevice.MacAddress)) { + // Device is new, add it Microsoft.Maui.Controls.Device.BeginInvokeOnMainThread(() => BluetoothDevices.Add(bluetoothDevice)); } } + private void RemoveUnavailableDevices(IEnumerable<IDevice> availableDevices) + { + var currentDevices = BluetoothDevices.ToList(); // Copy current list + + foreach (var device in currentDevices) + { + if (!availableDevices.Any(d => d.Id.ToString() == device.MacAddress)) + { + // Device is no longer available, remove it + Microsoft.Maui.Controls.Device.BeginInvokeOnMainThread(() => BluetoothDevices.Remove(device)); + Debug.WriteLine($"Removed unavailable device: {device.MacAddress}"); + } + } + } + + private async Task<IDevice> TryConnectAsync(Guid deviceId, int retryCount = 3) { @@ -367,6 +386,7 @@ namespace RobobinApp.ViewModels Debug.WriteLine($"{characteristic.Uuid} |{characteristic.Name}"); if (characteristic.Name.Equals(readCharacteristicName)) + { ReadCharacteristic = characteristic; var result = await ReadOperationAsync(); diff --git a/App/RobobinApp/Views/LeftBox.xaml b/App/RobobinApp/Views/LeftBox.xaml deleted file mode 100644 index 6b5fff0d..00000000 --- a/App/RobobinApp/Views/LeftBox.xaml +++ /dev/null @@ -1,12 +0,0 @@ -<?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.Views.LeftBox" - BackgroundColor="Lavender"> - <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center"> - <Label BackgroundColor="Black">Test</Label> - - <Label BackgroundColor="Black">Test</Label> - - </VerticalStackLayout> -</ContentView> diff --git a/App/RobobinApp/Views/LeftBox.xaml.cs b/App/RobobinApp/Views/LeftBox.xaml.cs deleted file mode 100644 index 6a829747..00000000 --- a/App/RobobinApp/Views/LeftBox.xaml.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Maui.Controls; - -namespace RobobinApp.Views -{ - public partial class LeftBox : ContentView - { - public LeftBox() - { - InitializeComponent(); - } - } -} diff --git a/App/RobobinApp/Views/MainPage.xaml b/App/RobobinApp/Views/MainPage.xaml index 75869e06..804bf685 100644 --- a/App/RobobinApp/Views/MainPage.xaml +++ b/App/RobobinApp/Views/MainPage.xaml @@ -2,6 +2,8 @@ <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:RobobinApp.Views" + + xmlns:viewModels="clr-namespace:RobobinApp.ViewModels" x:Class="RobobinApp.Views.MainPage" Title=""> @@ -12,6 +14,8 @@ <ContentPage.Resources> <ResourceDictionary> <ResourceDictionary Source="../Resources/Styles/Styles.xaml" /> + + <StyleSheet Source="/Resources/Styles/appstyle.css" /> </ResourceDictionary> </ContentPage.Resources> @@ -31,18 +35,24 @@ <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> - <local:LeftBox Grid.Column="0" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> + <Frame StyleClass="sideFrame" + HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" + Grid.Column="0" Grid.Row="0"> + + - <Frame BackgroundColor="White" BorderColor="Black" CornerRadius="5" + <Button Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center" Command="{Binding ConnectToRobobinCommand}"/> + </Frame> + <Frame StyleClass="mainFrame" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="1" Grid.Row="0"> <Label Text="{Binding StatusMessage}" HorizontalOptions="Center" VerticalOptions="Center"/> </Frame> - <Frame BackgroundColor="Lavender" BorderColor="Black" CornerRadius="5" + <Frame StyleClass="sideFrame" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Column="2" Grid.Row="0"> - <Button Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center" Command="{Binding ConnectToRobobinCommand}"/> + <Button Text="Right Box" HorizontalOptions="Center" VerticalOptions="Center" Command="{Binding ConnectToRobobinCommand}"/> </Frame> </Grid> </ContentPage> -- GitLab