diff --git a/App/RobobinApp/App.xaml.cs b/App/RobobinApp/App.xaml.cs index 4ae70a3de0b775dae17d62d0b51f4eaa6425e620..e1472dcdc6f176f8bb282eda54676112f34ef121 100644 --- a/App/RobobinApp/App.xaml.cs +++ b/App/RobobinApp/App.xaml.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using Plugin.BLE; using Plugin.BLE.Abstractions.Contracts; -using RobobinApp.Networking; // Make sure to include the namespace for WifiManager +using RobobinApp.Networking; namespace RobobinApp { diff --git a/App/RobobinApp/AppShell.xaml b/App/RobobinApp/AppShell.xaml index 270d8c2c43d06395bee14da8e8b033b79bb315ac..fc1cc13a4a242795ab3814c32971816117cc98db 100644 --- a/App/RobobinApp/AppShell.xaml +++ b/App/RobobinApp/AppShell.xaml @@ -3,6 +3,4 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:RobobinApp.Views" x:Class="RobobinApp.AppShell"> - - <ShellContent ContentTemplate="{DataTemplate views:MainPage}" /> -</Shell> \ No newline at end of file +</Shell> diff --git a/App/RobobinApp/AppShell.xaml.cs b/App/RobobinApp/AppShell.xaml.cs index 96c315766cec060de27e6d4d452e14c28c5bb078..2b2427762ec47e1ffc2ae6a2e0c66c439e8fcd8d 100644 --- a/App/RobobinApp/AppShell.xaml.cs +++ b/App/RobobinApp/AppShell.xaml.cs @@ -1,9 +1,32 @@ -namespace RobobinApp; +using Microsoft.Maui.Controls; +using RobobinApp.Views; -public partial class AppShell : Shell +namespace RobobinApp { - public AppShell() - { - InitializeComponent(); - } + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + + // Conditionally add ShellContent based on the platform +#if WINDOWS + Items.Add(new ShellContent + { + ContentTemplate = new DataTemplate(typeof(MainPage)) + }); +#elif ANDROID + Items.Add(new ShellContent + { + ContentTemplate = new DataTemplate(typeof(MainPage_Android)) + }); +#else + // Fallback if you need it for other platforms + Items.Add(new ShellContent + { + ContentTemplate = new DataTemplate(typeof(MainPage_Default)) + }); +#endif + } + } } diff --git a/App/RobobinApp/Platforms/Android/AndroidManifest.xml b/App/RobobinApp/Platforms/Android/AndroidManifest.xml index 4dcde8feb0b07e8059b2135c73d79e32de1133fa..d2d79fe139c4bec78d0f6f3e67b950011c92b452 100644 --- a/App/RobobinApp/Platforms/Android/AndroidManifest.xml +++ b/App/RobobinApp/Platforms/Android/AndroidManifest.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1"> - <application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="RoboBin"></application> + <application android:allowBackup="true" android:supportsRtl="true" android:label="RoboBin"></application> <!-- Required permissions --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> @@ -10,6 +10,4 @@ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> - - </manifest> \ No newline at end of file diff --git a/App/RobobinApp/Platforms/Android/Resources/drawable/bin.svg b/App/RobobinApp/Platforms/Android/Resources/drawable/bin.svg new file mode 100644 index 0000000000000000000000000000000000000000..8c4771bf919bdd3a916148a1f91e9fdf69ecd78f --- /dev/null +++ b/App/RobobinApp/Platforms/Android/Resources/drawable/bin.svg @@ -0,0 +1,17 @@ +<?xml version="1.0" ?> + <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> +<svg width="800px" height="800px" viewBox="0 0 48 48" data-name="Layer 1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"> + <defs> + <style>.cls-1{fill:#55aae1;}.cls-2{opacity:0.35;}</style> + </defs> + <title/> + <path class="cls-1" d="M36,44H12a3,3,0,0,1-3-3V12a1,1,0,0,1,1-1H38a1,1,0,0,1,1,1V41A3,3,0,0,1,36,44ZM11,13V41a1,1,0,0,0,1,1H36a1,1,0,0,0,1-1V13Z"/> + <g class="cls-2"> + <path class="cls-1" d="M35,12V38a2,2,0,0,1-2,2H10v1a2,2,0,0,0,2,2H36a2,2,0,0,0,2-2V12Z"/> + </g> + <path class="cls-1" d="M43,13H5a1,1,0,0,1,0-2H43a1,1,0,0,1,0,2Z"/> + <path class="cls-1" d="M17,35a1,1,0,0,1-1-1V20a1,1,0,0,1,2,0V34A1,1,0,0,1,17,35Z"/> + <path class="cls-1" d="M31,35a1,1,0,0,1-1-1V20a1,1,0,0,1,2,0V34A1,1,0,0,1,31,35Z"/> + <path class="cls-1" d="M24,37a1,1,0,0,1-1-1V18a1,1,0,0,1,2,0V36A1,1,0,0,1,24,37Z"/> + <path class="cls-1" d="M33,13H15a1,1,0,0,1-1-1V7a3,3,0,0,1,3-3H31a3,3,0,0,1,3,3v5A1,1,0,0,1,33,13ZM16,11H32V7a1,1,0,0,0-1-1H17a1,1,0,0,0-1,1Z"/> + </svg> \ No newline at end of file diff --git a/App/RobobinApp/Platforms/Android/Resources/mipmap/robobinlogo1.png b/App/RobobinApp/Platforms/Android/Resources/mipmap/robobinlogo1.png new file mode 100644 index 0000000000000000000000000000000000000000..f22f9630a604d4823e7bdd5ff576f0af86627b8e Binary files /dev/null and b/App/RobobinApp/Platforms/Android/Resources/mipmap/robobinlogo1.png differ diff --git a/App/RobobinApp/Resources/AppIcon/appicon.svg b/App/RobobinApp/Resources/AppIcon/appicon.svg deleted file mode 100644 index 5f04fcfca9dea7b0616c19c76138513e131da8a0..0000000000000000000000000000000000000000 --- a/App/RobobinApp/Resources/AppIcon/appicon.svg +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg width="456" height="456" viewBox="0 0 456 456" version="1.1" xmlns="http://www.w3.org/2000/svg"> - <rect x="0" y="0" width="456" height="456" fill="#512BD4" /> -</svg> \ No newline at end of file diff --git a/App/RobobinApp/Resources/AppIcon/appiconfg.svg b/App/RobobinApp/Resources/AppIcon/appiconfg.svg deleted file mode 100644 index 62d66d7a6fa033abe68352bc0d6dfeb5b49a85ee..0000000000000000000000000000000000000000 --- a/App/RobobinApp/Resources/AppIcon/appiconfg.svg +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<svg width="456" height="456" viewBox="0 0 456 456" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"> - <path d="m 105.50037,281.60863 c -2.70293,0 -5.00091,-0.90042 -6.893127,-2.70209 -1.892214,-1.84778 -2.837901,-4.04181 -2.837901,-6.58209 0,-2.58722 0.945687,-4.80389 2.837901,-6.65167 1.892217,-1.84778 4.190197,-2.77167 6.893127,-2.77167 2.74819,0 5.06798,0.92389 6.96019,2.77167 1.93749,1.84778 2.90581,4.06445 2.90581,6.65167 0,2.54028 -0.96832,4.73431 -2.90581,6.58209 -1.89221,1.80167 -4.212,2.70209 -6.96019,2.70209 z" style="fill:#ffffff;fill-rule:nonzero;stroke-width:0.838376" /> - <path d="M 213.56111,280.08446 H 195.99044 L 149.69953,207.0544 c -1.17121,-1.84778 -2.14037,-3.76515 -2.90581,-5.75126 h -0.40578 c 0.36051,2.12528 0.54076,6.67515 0.54076,13.6496 v 65.13172 h -15.54349 v -99.36009 h 18.71925 l 44.7374,71.29798 c 1.89222,2.95695 3.1087,4.98917 3.64945,6.09751 h 0.26996 c -0.45021,-2.6325 -0.67573,-7.09015 -0.67573,-13.37293 v -64.02256 h 15.47557 z" style="fill:#ffffff;fill-rule:nonzero;stroke-width:0.838376" /> - <path d="m 289.25134,280.08446 h -54.40052 v -99.36009 h 52.23835 v 13.99669 h -36.15411 v 28.13085 h 33.31621 v 13.9271 h -33.31621 v 29.37835 h 38.31628 z" style="fill:#ffffff;fill-rule:nonzero;stroke-width:0.838376" /> - <path d="M 366.56466,194.72106 H 338.7222 v 85.3634 h -16.08423 v -85.3634 h -27.77455 v -13.99669 h 71.70124 z" style="fill:#ffffff;fill-rule:nonzero;stroke-width:0.838376" /> -</svg> \ No newline at end of file diff --git a/App/RobobinApp/Resources/Splash/bin.svg b/App/RobobinApp/Resources/Splash/bin.svg new file mode 100644 index 0000000000000000000000000000000000000000..8c4771bf919bdd3a916148a1f91e9fdf69ecd78f --- /dev/null +++ b/App/RobobinApp/Resources/Splash/bin.svg @@ -0,0 +1,17 @@ +<?xml version="1.0" ?> + <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> +<svg width="800px" height="800px" viewBox="0 0 48 48" data-name="Layer 1" id="Layer_1" xmlns="http://www.w3.org/2000/svg"> + <defs> + <style>.cls-1{fill:#55aae1;}.cls-2{opacity:0.35;}</style> + </defs> + <title/> + <path class="cls-1" d="M36,44H12a3,3,0,0,1-3-3V12a1,1,0,0,1,1-1H38a1,1,0,0,1,1,1V41A3,3,0,0,1,36,44ZM11,13V41a1,1,0,0,0,1,1H36a1,1,0,0,0,1-1V13Z"/> + <g class="cls-2"> + <path class="cls-1" d="M35,12V38a2,2,0,0,1-2,2H10v1a2,2,0,0,0,2,2H36a2,2,0,0,0,2-2V12Z"/> + </g> + <path class="cls-1" d="M43,13H5a1,1,0,0,1,0-2H43a1,1,0,0,1,0,2Z"/> + <path class="cls-1" d="M17,35a1,1,0,0,1-1-1V20a1,1,0,0,1,2,0V34A1,1,0,0,1,17,35Z"/> + <path class="cls-1" d="M31,35a1,1,0,0,1-1-1V20a1,1,0,0,1,2,0V34A1,1,0,0,1,31,35Z"/> + <path class="cls-1" d="M24,37a1,1,0,0,1-1-1V18a1,1,0,0,1,2,0V36A1,1,0,0,1,24,37Z"/> + <path class="cls-1" d="M33,13H15a1,1,0,0,1-1-1V7a3,3,0,0,1,3-3H31a3,3,0,0,1,3,3v5A1,1,0,0,1,33,13ZM16,11H32V7a1,1,0,0,0-1-1H17a1,1,0,0,0-1,1Z"/> + </svg> \ No newline at end of file diff --git a/App/RobobinApp/RobobinApp.csproj b/App/RobobinApp/RobobinApp.csproj index 294a17f879eb4303d194b9cbb8fb6f3a0c3708e0..29a2b946e6ba514310eabb82dd49d3cc08164f53 100644 --- a/App/RobobinApp/RobobinApp.csproj +++ b/App/RobobinApp/RobobinApp.csproj @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <!-->TargetFrameworks>net8.0-ios;net8.0-maccatalyst</TargetFrameworks--> + <TargetFrameworks>net8.0-android</TargetFrameworks> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> <OutputType>Exe</OutputType> <RootNamespace>Robobin</RootNamespace> @@ -12,20 +12,38 @@ <ApplicationId>com.companyname.robobin</ApplicationId> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion> - <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion> + <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> + <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'"> + <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk> + </PropertyGroup> <ItemGroup> + <MauiIcon Include="Platforms\Android\Resources\mipmap\robobinlogo1.png" /> <MauiIcon Include="Resources\AppIcon\robobinlogo.png" /> - <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> <MauiImage Include="Resources\Images\*" /> <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> <MauiFont Include="Resources\Fonts\*" /> <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> + <MauiSplashScreen Include="Platforms\Android\Resources\drawable\bin.svg"> + <Color>#512BD4</Color> + <BaseSize>128,128</BaseSize> + </MauiSplashScreen> + <MauiSplashScreen Include="Resources\Splash\bin.svg" Color="#8185b4" BaseSize="128,128" /> + </ItemGroup> + + <ItemGroup> + <AndroidResource Remove="Platforms\Android\Resources\mipmap\robobinlogo1.png" /> + </ItemGroup> + + <ItemGroup> + <None Remove="Platforms\Android\Resources\drawable\bin.svg" /> + <None Remove="Platforms\Android\Resources\mipmap\robobinlogo1.png" /> </ItemGroup> <ItemGroup> @@ -50,6 +68,9 @@ <Compile Update="Views\ConnectionPage.xaml.cs"> <DependentUpon>ConnectionPage.xaml</DependentUpon> </Compile> + <Compile Update="Views\MainPage_Android.xaml.cs"> + <DependentUpon>MainPage_Android.xaml</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> @@ -62,6 +83,9 @@ <MauiXaml Update="Views\ConnectionPage.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> + <MauiXaml Update="Views\MainPage_Android.xaml"> + <Generator>MSBuild:Compile</Generator> + </MauiXaml> <MauiXaml Update="Views\SideBox.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> diff --git a/App/RobobinApp/RobobinApp.csproj.user b/App/RobobinApp/RobobinApp.csproj.user index db9abdfaf1955d4e75f45c85d7c3e46fc4a8892d..8e54b9dbc68330a9ac553f411df2e1967205f7de 100644 --- a/App/RobobinApp/RobobinApp.csproj.user +++ b/App/RobobinApp/RobobinApp.csproj.user @@ -2,9 +2,9 @@ <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen> - <ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework> - <ActiveDebugProfile>Windows Machine</ActiveDebugProfile> - <SelectedPlatformGroup>Emulator</SelectedPlatformGroup> + <ActiveDebugFramework>net8.0-android</ActiveDebugFramework> + <ActiveDebugProfile>Samsung SM-A805F (Android 9.0 - API 28)</ActiveDebugProfile> + <SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup> <DefaultDevice>pixel_5_-_api_34</DefaultDevice> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'"> @@ -26,6 +26,9 @@ <MauiXaml Update="Views\ConnectionPage.xaml"> <SubType>Designer</SubType> </MauiXaml> + <MauiXaml Update="Views\MainPage_Android.xaml"> + <SubType>Designer</SubType> + </MauiXaml> <MauiXaml Update="Views\SideBox.xaml"> <SubType>Designer</SubType> </MauiXaml> diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index 74427aa26684de087699d42edac4a50722d73dec..97e98a2be770afc8aa1de30e5db90f0a2d4f0885 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -13,12 +13,16 @@ using RobobinApp.Models; using System.Net.NetworkInformation; using System.Collections.Generic; +#if WINDOWS using Windows.Networking.Connectivity; using Windows.Devices.WiFi; using System.Reflection.PortableExecutable; using Plugin.BLE.Windows; -using System.Text; using System.Windows.Documents; +#endif + +using System.Text; + using RobobinApp.Networking; namespace RobobinApp.ViewModels @@ -328,8 +332,8 @@ namespace RobobinApp.ViewModels private void OnDeviceDiscovered(object? sender, DeviceEventArgs e) { Debug.WriteLine($"Discovered device: {e.Device.Name ?? e.Device.Id.ToString()}"); - if (e.Device.Name.Equals("RoboBin-BT")) - { + //if (e.Device.Name.Equals("RoboBin-BT")) + //{ var bluetoothDevice = new BluetoothDevice( string.IsNullOrWhiteSpace(e.Device.Name) ? e.Device.Id.ToString() : e.Device.Name, e.Device.Id.ToString() @@ -341,7 +345,7 @@ namespace RobobinApp.ViewModels // Device is new, add it Microsoft.Maui.Controls.Device.BeginInvokeOnMainThread(() => BluetoothDevices.Add(bluetoothDevice)); } - } + //} } diff --git a/App/RobobinApp/Views/MainPage_Android.xaml b/App/RobobinApp/Views/MainPage_Android.xaml new file mode 100644 index 0000000000000000000000000000000000000000..09ba3e2d301a44fd4bbad1ded4d2a3d4293fa661 --- /dev/null +++ b/App/RobobinApp/Views/MainPage_Android.xaml @@ -0,0 +1,69 @@ +<?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.Views" + xmlns:viewModels="clr-namespace:RobobinApp.ViewModels" + xmlns:drawable="clr-namespace:RobobinApp.Views" + x:Class="RobobinApp.Views.MainPage_Android" + Title=""> + + <ContentPage.BindingContext> + <viewModels:MainPageViewModel /> + </ContentPage.BindingContext> + + <ContentPage.Resources> + <ResourceDictionary> + <drawable:GraphicsDrawable x:Key="drawable" /> + <StyleSheet Source="/Resources/Styles/appstyle.css" /> + </ResourceDictionary> + </ContentPage.Resources> + + <!-- Make the entire content scrollable --> + <ScrollView> + <VerticalStackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> + + <!-- Top Frame --> + <VerticalStackLayout StyleClass="sideFrame" + HorizontalOptions="FillAndExpand" + VerticalOptions="Start"> + <HorizontalStackLayout HorizontalOptions="Start" VerticalOptions="End"> + <Button Text="Admin" Command="{Binding ConnectToRobobinCommand}"/> + <Button Text="Setup" Command="{Binding ConnectToRobobinCommand}"/> + <Button Text="Info" /> + <Picker Title="Select Graph" + ItemsSource="{Binding GraphNames}" + SelectedIndexChanged="OnGraphSelected" + HorizontalOptions="Center" /> + </HorizontalStackLayout> + + <local:SideBox HeaderTitle="Queue:" /> + <local:SideBox HeaderTitle="Status:" /> + </VerticalStackLayout> + + <!-- Main Drawable Area with specific HeightRequest to ensure visibility --> + <Frame StyleClass="mainFrame" + HorizontalOptions="FillAndExpand" + VerticalOptions="Center" + HeightRequest="400"> + <!-- Adjust this value as needed --> + <GraphicsView x:Name="GraphicsView" + Drawable="{StaticResource drawable}"> + <GraphicsView.GestureRecognizers> + <TapGestureRecognizer Tapped="OnGraphicsViewTapped" /> + </GraphicsView.GestureRecognizers> + </GraphicsView> + </Frame> + + <!-- Bottom Frame --> + <VerticalStackLayout StyleClass="sideFrame" + HorizontalOptions="FillAndExpand" + VerticalOptions="End"> + + + <local:SideBox HeaderTitle="Mode:" /> + <local:SideBox HeaderTitle="Admin:" /> + </VerticalStackLayout> + + </VerticalStackLayout> + </ScrollView> +</ContentPage> diff --git a/App/RobobinApp/Views/MainPage_Android.xaml.cs b/App/RobobinApp/Views/MainPage_Android.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..2358d155f02791e6764536f76f1da68a0cb4ce2e --- /dev/null +++ b/App/RobobinApp/Views/MainPage_Android.xaml.cs @@ -0,0 +1,91 @@ +using Microsoft.Maui.Controls; +using RobobinApp.ViewModels; +using RobobinApp.Models; +using System.Diagnostics; +using RobobinApp.Views; +using Robobin.Models; + +namespace RobobinApp.Views +{ + public partial class MainPage_Android : ContentPage + { + public MainPage_Android() + { + InitializeComponent(); + + + var drawable = (GraphicsDrawable)Resources["drawable"]; + if (BindingContext is MainPageViewModel viewModel) + { + drawable.SetGraph(viewModel.Graph); + } + } + + private void OnGraphSelected(object sender, EventArgs e) + { + + if (sender is Picker picker && BindingContext is MainPageViewModel viewModel) + { + + viewModel.SelectGraphCommand.Execute(picker.SelectedIndex); + + + var drawable = (GraphicsDrawable)Resources["drawable"]; + var newGraph = viewModel.Graphs.FirstOrDefault(g => g.Name == viewModel.Graph.Name); + + + if (newGraph != null) + { + drawable.SetGraph(newGraph); + GraphicsView.Invalidate(); + Debug.WriteLine("New Graph picked and drawn"); + } + else + { + Debug.WriteLine("Graph not found!"); + } + } + } + + private void OnGraphicsViewTapped(object sender, TappedEventArgs e) + { + var tapPoint = e.GetPosition(GraphicsView); + var drawable = (GraphicsDrawable)Resources["drawable"]; + + float scale = drawable.CurrentScale; + var offset = drawable.CurrentOffset; + + var tapPointX = (float)tapPoint.Value.X; + var tapPointY = (float)tapPoint.Value.Y; + var nearestNode = drawable.FindNearestNode(tapPointX, tapPointY, scale, offset.X, offset.Y); + + // Highlight the nearest node + drawable.HighlightNode(nearestNode); + + if (nearestNode != null) + { + // Find the home node + Node homeNode = drawable.GetHomeNode(); + + if (homeNode != null) + { + + List<Node> path = drawable.AStarPathfinding(nearestNode, homeNode); + drawable.Path = path; + GraphicsView.Invalidate(); + } + + DisplayAlert("Node Clicked", $"You clicked on node: {nearestNode.Name}", "OK"); + } + else + { + DisplayAlert("No Node", "No node was clicked.", "OK"); + } + + // Invalidate to trigger a redraw and highlight the node + GraphicsView.Invalidate(); + } + + } + +}