From 943cdec951684648b0e906158561506cbabd814b Mon Sep 17 00:00:00 2001 From: NinjaPug <36635276+programmingPug@users.noreply.github.com> Date: Fri, 9 May 2025 14:37:11 -0400 Subject: [PATCH] Bug fixes --- PCPal/Configurator/AppShell.xaml | 4 +- PCPal/Configurator/AppShell.xaml.cs | 14 ++++++ .../Resources/Styles/Converters.xaml.cs | 47 ++++++++----------- .../ViewModels/OledConfigViewModel.cs | 4 ++ .../ViewModels/SettingsViewModel.cs | 19 +------- .../ViewModels/TftConfigViewModel.cs | 29 +----------- .../Views/OLED/OledConfigView.xaml | 18 +++---- .../Views/Settings/SettingsView.xaml | 4 -- .../Configurator/Views/TFT/TftConfigView.xaml | 12 +---- 9 files changed, 53 insertions(+), 98 deletions(-) diff --git a/PCPal/Configurator/AppShell.xaml b/PCPal/Configurator/AppShell.xaml index 41101e0..beff0d8 100644 --- a/PCPal/Configurator/AppShell.xaml +++ b/PCPal/Configurator/AppShell.xaml @@ -30,7 +30,7 @@ SelectionChanged="OnNavMenuSelectionChanged"> - 1602 LCD Display + 1602 LCD Display 4.6" TFT Display OLED Display Settings @@ -45,7 +45,7 @@ diff --git a/PCPal/Configurator/AppShell.xaml.cs b/PCPal/Configurator/AppShell.xaml.cs index a2ddfbd..653e982 100644 --- a/PCPal/Configurator/AppShell.xaml.cs +++ b/PCPal/Configurator/AppShell.xaml.cs @@ -5,6 +5,8 @@ using PCPal.Configurator.Views.LCD; using PCPal.Configurator.Views.OLED; using PCPal.Configurator.Views.TFT; using System.ComponentModel; +using PCPal.Configurator.Models; +using System.Collections.ObjectModel; namespace PCPal.Configurator; @@ -17,6 +19,7 @@ public partial class AppShell : Shell, INotifyPropertyChanged private readonly IServiceProvider _serviceProvider; + public bool IsConnected { get => _isConnected; @@ -58,6 +61,7 @@ public partial class AppShell : Shell, INotifyPropertyChanged public AppShell() { + InitializeComponent(); _serviceProvider = IPlatformApplication.Current?.Services; @@ -71,6 +75,14 @@ public partial class AppShell : Shell, INotifyPropertyChanged // Start with LCD view NavMenu.SelectedItem = "1602 LCD Display"; + // Just manually load the view + var lcdView = _serviceProvider?.GetService(); + if (lcdView != null) + { + ContentContainer.Content = lcdView; + } + + // Start connection monitoring in the background StartConnectivityMonitoring(); } @@ -91,6 +103,8 @@ public partial class AppShell : Shell, INotifyPropertyChanged { if (e.CurrentSelection.FirstOrDefault() is string selection) { + + ContentView view = selection switch { "1602 LCD Display" => _serviceProvider?.GetService(), diff --git a/PCPal/Configurator/Resources/Styles/Converters.xaml.cs b/PCPal/Configurator/Resources/Styles/Converters.xaml.cs index f2d0f53..0182028 100644 --- a/PCPal/Configurator/Resources/Styles/Converters.xaml.cs +++ b/PCPal/Configurator/Resources/Styles/Converters.xaml.cs @@ -76,38 +76,24 @@ public class ConnectionStatusColorConverter : IValueConverter // Converts a string to a color based on matching public class StringMatchConverter : IValueConverter { + // Default navigation item + private const string DefaultNavItem = "1602 LCD Display"; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // For matching menu items - if (value is string currentValue && parameter is string targetValue) + if (parameter is string targetValue) { - if (currentValue == targetValue) + string currentValue = value as string; + + // Either it's explicitly selected, or it's the default item and nothing is selected yet + if (currentValue == targetValue || (currentValue == null && targetValue == DefaultNavItem)) { - // Default to background coloring - Color returnColor = Application.Current.Resources["PrimaryLight"] as Color ?? Colors.LightBlue; - - // Check for additional parameter context - if (targetValue.EndsWith(":TextColor")) - { - // Strip the ":TextColor" suffix before comparison - string strippedTarget = targetValue.Substring(0, targetValue.Length - 10); - if (currentValue == strippedTarget) - { - return Application.Current.Resources["Primary"] as Color ?? Colors.Black; - } - } - - return returnColor; + return Application.Current.Resources["PrimaryLight"] as Color ?? Colors.LightBlue; } } - // Return default values - if (parameter is string param && param == "TextColor") - { - return Application.Current.Resources["TextSecondary"] as Color ?? Colors.Gray; - } - - // Default background is transparent + // Return transparent for non-selected items return Colors.Transparent; } @@ -283,18 +269,23 @@ public class RelativeTimeConverter : IValueConverter // Add this new converter for text color specifically public class StringMatchTextConverter : IValueConverter { + // Default navigation item + private const string DefaultNavItem = "1602 LCD Display"; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is string currentValue && parameter is string targetValue) + if (parameter is string targetValue) { - if (currentValue == targetValue) + string currentValue = value as string; + + // Either it's explicitly selected, or it's the default item and nothing is selected yet + if (currentValue == targetValue || (currentValue == null && targetValue == DefaultNavItem)) { - // Return text color for selected item return Application.Current.Resources["Primary"] as Color ?? Colors.Blue; } } - // Return default text color + // Return default text color for non-selected items return Application.Current.Resources["TextSecondary"] as Color ?? Colors.Gray; } diff --git a/PCPal/Configurator/ViewModels/OledConfigViewModel.cs b/PCPal/Configurator/ViewModels/OledConfigViewModel.cs index e0597da..f891bf3 100644 --- a/PCPal/Configurator/ViewModels/OledConfigViewModel.cs +++ b/PCPal/Configurator/ViewModels/OledConfigViewModel.cs @@ -657,6 +657,10 @@ public class OledConfigViewModel : BaseViewModel IsMarkupEditorSelected = tab == "markup"; IsTemplatesSelected = tab == "templates"; + OnPropertyChanged(nameof(IsVisualEditorSelected)); + OnPropertyChanged(nameof(IsMarkupEditorSelected)); + OnPropertyChanged(nameof(IsTemplatesSelected)); + switch (tab) { case "visual": diff --git a/PCPal/Configurator/ViewModels/SettingsViewModel.cs b/PCPal/Configurator/ViewModels/SettingsViewModel.cs index 799f942..fcd2fc8 100644 --- a/PCPal/Configurator/ViewModels/SettingsViewModel.cs +++ b/PCPal/Configurator/ViewModels/SettingsViewModel.cs @@ -106,8 +106,7 @@ public class SettingsViewModel : BaseViewModel public ICommand StartServiceCommand { get; } public ICommand StopServiceCommand { get; } public ICommand RestartServiceCommand { get; } - public ICommand CheckForUpdatesCommand { get; } - + public SettingsViewModel(IConfigurationService configService, ISerialPortService serialPortService) { Title = "Settings"; @@ -142,8 +141,7 @@ public class SettingsViewModel : BaseViewModel StartServiceCommand = new Command(async () => await StartServiceAsync()); StopServiceCommand = new Command(async () => await StopServiceAsync()); RestartServiceCommand = new Command(async () => await RestartServiceAsync()); - CheckForUpdatesCommand = new Command(async () => await CheckForUpdatesAsync()); - + // Subscribe to serial port connection changes _serialPortService.ConnectionStatusChanged += OnConnectionStatusChanged; } @@ -421,19 +419,6 @@ public class SettingsViewModel : BaseViewModel } } - private async Task CheckForUpdatesAsync() - { - try - { - await Shell.Current.DisplayAlert("Check for Updates", - "You are currently running the latest version (1.0.0).", "OK"); - } - catch (Exception ex) - { - await Shell.Current.DisplayAlert("Error", $"Failed to check for updates: {ex.Message}", "OK"); - } - } - private void OnConnectionStatusChanged(object sender, bool isConnected) { MainThread.BeginInvokeOnMainThread(() => diff --git a/PCPal/Configurator/ViewModels/TftConfigViewModel.cs b/PCPal/Configurator/ViewModels/TftConfigViewModel.cs index 780e08c..61c23dd 100644 --- a/PCPal/Configurator/ViewModels/TftConfigViewModel.cs +++ b/PCPal/Configurator/ViewModels/TftConfigViewModel.cs @@ -1,39 +1,12 @@ -using System.Windows.Input; - -namespace PCPal.Configurator.ViewModels; +namespace PCPal.Configurator.ViewModels; public class TftConfigViewModel : BaseViewModel { - public ICommand NotifyCommand { get; } public TftConfigViewModel() { Title = "TFT Display Configuration"; - // Initialize commands - NotifyCommand = new Command(async () => await NotifyWhenAvailableAsync()); } - private async Task NotifyWhenAvailableAsync() - { - // Display a prompt for the user's email - string result = await Shell.Current.DisplayPromptAsync( - "Notification Sign-up", - "Enter your email to be notified when TFT display support becomes available:", - "Subscribe", - "Cancel", - "email@example.com", - keyboard: Keyboard.Email); - - if (!string.IsNullOrWhiteSpace(result)) - { - // In a real app, we would save this email to a notification list - - // Display confirmation - await Shell.Current.DisplayAlert( - "Thank You!", - "We'll notify you when TFT display support is ready. Your email has been registered for updates.", - "OK"); - } - } } \ No newline at end of file diff --git a/PCPal/Configurator/Views/OLED/OledConfigView.xaml b/PCPal/Configurator/Views/OLED/OledConfigView.xaml index 6eebfc4..d2a2777 100644 --- a/PCPal/Configurator/Views/OLED/OledConfigView.xaml +++ b/PCPal/Configurator/Views/OLED/OledConfigView.xaml @@ -23,14 +23,14 @@ + StrokeShape="RoundRectangle 4,4,0,0" + StrokeThickness="1" + Stroke="{StaticResource BorderColor}" + Padding="20,10" + WidthRequest="160">