allow setting to be toggled from the json file
This commit is contained in:
@@ -39,7 +39,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddContentTemplate<WidgetConfigurationNavigationViewModel, WidgetConfigurationNavigationView>();
|
||||
services.AddContentTemplate<WidgetConfigurationViewModel, WidgetConfigurationView>("WidgetSettings");
|
||||
|
||||
services.AddContentTemplate<WidgetConfigurationViewModel<WidgetAvailability, bool>, WidgetAvailabilityConfigurationView>();
|
||||
services.AddContentTemplate<WidgetConfigurationViewModel<WidgetAvailability, bool>, WidgetToggleConfigurationView>();
|
||||
})));
|
||||
|
||||
return services;
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetConfigurationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ItemsControl ItemTemplateSelector="{Binding ViewModelTemplateSelector}" ItemsSource="{Binding Mode=TwoWay}" />
|
||||
<ItemsControl ItemTemplateSelector="{Binding ViewModelTemplateSelector}" ItemsSource="{x:Bind ViewModel, Mode=OneWay}" />
|
||||
</UserControl>
|
||||
|
||||
@@ -1,22 +1,47 @@
|
||||
using Hyperbar.UI.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetConfigurationViewModel<TConfiguration, TValue> :
|
||||
public partial class WidgetConfigurationViewModel<TConfiguration, TValue> :
|
||||
ValueViewModel<TValue>,
|
||||
INotificationHandler<Changed<TConfiguration>>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
private readonly Func<TConfiguration, TValue> valueFactory;
|
||||
private readonly Func<TConfiguration, TValue> read;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? description;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? title;
|
||||
|
||||
public WidgetConfigurationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
IDisposer disposer,
|
||||
Func<TConfiguration, TValue> valueFactory) : base(serviceProvider, serviceFactory, publisher, disposer)
|
||||
ISubscriber subscriber,
|
||||
string? title,
|
||||
Func<TConfiguration, TValue> read) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
this.valueFactory = valueFactory;
|
||||
this.title = title;
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
public WidgetConfigurationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
IDisposer disposer,
|
||||
ISubscriber subscriber,
|
||||
string? title,
|
||||
string? description,
|
||||
Func<TConfiguration, TValue> read) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
public Task Handle(Changed<TConfiguration> args,
|
||||
@@ -24,7 +49,7 @@ public class WidgetConfigurationViewModel<TConfiguration, TValue> :
|
||||
{
|
||||
if (args.Value is TConfiguration configuration)
|
||||
{
|
||||
valueFactory.Invoke(configuration);
|
||||
Value = read.Invoke(configuration);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -44,7 +69,7 @@ public class WidgetConfigurationViewModel :
|
||||
ViewModelTemplateSelector = viewModelTemplateSelector;
|
||||
|
||||
Add<WidgetConfigurationViewModel<WidgetAvailability,
|
||||
bool>>((Func<WidgetAvailability, bool>)(config => config.Value));
|
||||
bool>>("Widget", (Func<WidgetAvailability, bool>)(config => config.Value));
|
||||
}
|
||||
|
||||
public IViewModelTemplateSelector ViewModelTemplateSelector { get; }
|
||||
|
||||
@@ -5,5 +5,6 @@ namespace Hyperbar.Widget.Windows;
|
||||
public sealed partial class WidgetSplitButtonView :
|
||||
UserControl
|
||||
{
|
||||
public WidgetSplitButtonView() => InitializeComponent();
|
||||
public WidgetSplitButtonView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<controls:SettingsCard
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetAvailabilityConfigurationView"
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetToggleConfigurationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
Description="foo foo foo" />
|
||||
Description="{Binding Description}"
|
||||
Header="{Binding Title}">
|
||||
<ToggleSwitch IsOn="{Binding Value}" />
|
||||
</controls:SettingsCard>
|
||||
+2
-2
@@ -2,9 +2,9 @@ using CommunityToolkit.WinUI.Controls;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public sealed partial class WidgetAvailabilityConfigurationView :
|
||||
public sealed partial class WidgetToggleConfigurationView :
|
||||
SettingsCard
|
||||
{
|
||||
public WidgetAvailabilityConfigurationView() =>
|
||||
public WidgetToggleConfigurationView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -6,5 +6,6 @@ public sealed partial class WidgetView :
|
||||
UserControl,
|
||||
IWidgetView
|
||||
{
|
||||
public WidgetView() => InitializeComponent();
|
||||
public WidgetView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -6,8 +6,9 @@ public partial class SettingsButtonViewModel(IViewModelTemplateSelector viewMode
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, disposer)
|
||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
||||
}
|
||||
@@ -4,30 +4,41 @@ using System.Windows.Input;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ObservableViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
IDisposer disposer) :
|
||||
public class ObservableViewModel :
|
||||
ObservableObject,
|
||||
IObservableViewModel
|
||||
{
|
||||
private bool isInitialized;
|
||||
|
||||
public IDisposer Disposer => disposer;
|
||||
public ObservableViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
ServiceFactory = serviceFactory;
|
||||
Publisher = publisher;
|
||||
Disposer = disposer;
|
||||
|
||||
subscriber.Add(this);
|
||||
}
|
||||
|
||||
public IDisposer Disposer { get; }
|
||||
|
||||
public ICommand InitializeCommand =>
|
||||
new AsyncRelayCommand(CoreInitializeAsync);
|
||||
|
||||
public IPublisher Publisher => publisher;
|
||||
public IPublisher Publisher { get; }
|
||||
|
||||
public IServiceFactory ServiceFactory => serviceFactory;
|
||||
public IServiceFactory ServiceFactory { get; }
|
||||
|
||||
public IServiceProvider ServiceProvider => serviceProvider;
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
disposer.Dispose(this);
|
||||
Disposer.Dispose(this);
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync() => Task.CompletedTask;
|
||||
|
||||
@@ -7,7 +7,7 @@ public class SubscriptionManager(SubscriptionCollection subscriptions) :
|
||||
{
|
||||
public IEnumerable<object?> GetHandlers(Type notificationType, object key)
|
||||
{
|
||||
if (subscriptions.TryGetValue($"{key?.ToString()}:{notificationType}",
|
||||
if (subscriptions.TryGetValue($"{(key is not null ? $"{key}:" : "")}{notificationType}",
|
||||
out List<WeakReference>? subscribers))
|
||||
{
|
||||
foreach (WeakReference weakRef in subscribers.ToArray())
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
namespace Hyperbar;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public partial class ValueViewModel<TValue>(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, disposer)
|
||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
public TValue? Value { get; set; }
|
||||
[ObservableProperty]
|
||||
private TValue? value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user