moerfixes
This commit is contained in:
@@ -13,8 +13,7 @@ public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
|||||||
string? text = null,
|
string? text = null,
|
||||||
string? icon = null,
|
string? icon = null,
|
||||||
RelayCommand? command = null) :
|
RelayCommand? command = null) :
|
||||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command),
|
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command)
|
||||||
IInitialization
|
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private PlaybackButtonType playbackButtonType = playbackButtonType;
|
private PlaybackButtonType playbackButtonType = playbackButtonType;
|
||||||
@@ -38,6 +37,8 @@ public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public override async Task InitializeAsync() =>
|
//public override Task OnInitializeAsync()
|
||||||
|
//{
|
||||||
// await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
// await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,15 @@ public class MediaController :
|
|||||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||||
await session.TryGetMediaPropertiesAsync();
|
await session.TryGetMediaPropertiesAsync();
|
||||||
|
|
||||||
IRandomAccessStreamWithContentType randomAccessStream = await mediaProperties.Thumbnail.OpenReadAsync();
|
IRandomAccessStreamWithContentType? randomAccessStream = null;
|
||||||
|
if (mediaProperties.Thumbnail is not null)
|
||||||
|
{
|
||||||
|
randomAccessStream =
|
||||||
|
await mediaProperties.Thumbnail.OpenReadAsync();
|
||||||
|
}
|
||||||
|
|
||||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||||
mediaProperties.Artist, randomAccessStream.AsStream())));
|
mediaProperties.Artist, randomAccessStream is not null ? randomAccessStream.AsStream() : default)));
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class MediaControllerService(IMediator mediator,
|
|||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InitializeSessionAsync(GlobalSystemMediaTransportControlsSession session)
|
private async Task InitializeSessionAsync(GlobalSystemMediaTransportControlsSession session)
|
||||||
|
|||||||
@@ -4,9 +4,8 @@
|
|||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||||
<Button>sfsdf</Button>
|
<FlipView
|
||||||
<!--<FlipView
|
|
||||||
Width="360"
|
Width="360"
|
||||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||||
ItemsSource="{Binding}" />-->
|
ItemsSource="{Binding}" />
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public record MediaInformation(string Title,
|
public record MediaInformation(string Title,
|
||||||
string Description,
|
string Description,
|
||||||
Stream ThumbnailSource);
|
Stream? ThumbnailSource);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Microsoft.UI.Xaml.Media;
|
|
||||||
|
|
||||||
namespace Hyperbar.Widget.MediaController.Windows;
|
namespace Hyperbar.Widget.MediaController.Windows;
|
||||||
|
|
||||||
@@ -8,7 +7,6 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
|||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
ITemplateFactory templateFactory) :
|
ITemplateFactory templateFactory) :
|
||||||
WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory),
|
WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory),
|
||||||
IInitialization,
|
|
||||||
INotificationHandler<Changed<MediaInformation>>
|
INotificationHandler<Changed<MediaInformation>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -33,6 +31,6 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task InitializeAsync() =>
|
public override async Task OnInitializeAsync() =>
|
||||||
await Mediator.PublishAsync<Request<MediaInformation>>();
|
await Mediator.PublishAsync<Request<MediaInformation>>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ public static class IServiceCollectionExtensions
|
|||||||
services.AddHandler<WidgetViewModelEnumerator>();
|
services.AddHandler<WidgetViewModelEnumerator>();
|
||||||
|
|
||||||
services.AddTransient<IWidgetView, WidgetView>();
|
services.AddTransient<IWidgetView, WidgetView>();
|
||||||
services.AddTransient<IInitialization, WidgetResourceInitializer>();
|
services.AddTransient<IInitializer, WidgetResourceInitializer>();
|
||||||
services.AddTransient<IInitialization, WidgetXamlMetadataInitializer>();
|
services.AddTransient<IInitializer, WidgetXamlMetadataInitializer>();
|
||||||
|
|
||||||
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||||
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using Windows.Storage;
|
|||||||
namespace Hyperbar.Widget.Windows;
|
namespace Hyperbar.Widget.Windows;
|
||||||
|
|
||||||
internal class WidgetResourceInitializer(IWidgetAssembly widgetAssembly) :
|
internal class WidgetResourceInitializer(IWidgetAssembly widgetAssembly) :
|
||||||
IInitialization
|
IInitializer
|
||||||
{
|
{
|
||||||
public async Task InitializeAsync()
|
public async Task InitializeAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Hyperbar.Widget.Windows;
|
|||||||
|
|
||||||
public class WidgetXamlMetadataInitializer(IWidgetAssembly widgetAssembly,
|
public class WidgetXamlMetadataInitializer(IWidgetAssembly widgetAssembly,
|
||||||
IList<IXamlMetadataProvider> xamlMetadataProviders) :
|
IList<IXamlMetadataProvider> xamlMetadataProviders) :
|
||||||
IInitialization
|
IInitializer
|
||||||
{
|
{
|
||||||
public Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public static class IServiceCollectionExtensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddWidget(this IServiceCollection services)
|
public static IServiceCollection AddWidget(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<IInitialization, WidgetExtensionInitializer>();
|
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||||
|
|
||||||
services.AddHandler<WidgetExtensionEnumerator>();
|
services.AddHandler<WidgetExtensionEnumerator>();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Hyperbar.Widget;
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
public class WidgetExtensionInitializer(IMediator mediator) :
|
public class WidgetExtensionInitializer(IMediator mediator) :
|
||||||
IInitialization
|
IInitializer
|
||||||
{
|
{
|
||||||
public async Task InitializeAsync() =>
|
public async Task InitializeAsync() =>
|
||||||
await mediator.PublishAsync<Enumerate<WidgetExtension>>();
|
await mediator.PublishAsync<Enumerate<WidgetExtension>>();
|
||||||
|
|||||||
@@ -9,16 +9,17 @@ public sealed class WidgetHost :
|
|||||||
private readonly IServiceProvider services;
|
private readonly IServiceProvider services;
|
||||||
private readonly IMediator mediator;
|
private readonly IMediator mediator;
|
||||||
private readonly IProxyService<IMediator> proxyMediator;
|
private readonly IProxyService<IMediator> proxyMediator;
|
||||||
|
private readonly IEnumerable<IHostedService> hostedServices;
|
||||||
|
|
||||||
public WidgetHost(IServiceProvider services,
|
public WidgetHost(IServiceProvider services,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IProxyService<IMediator> proxyMediator)
|
IProxyService<IMediator> proxyMediator,
|
||||||
|
IEnumerable<IHostedService> hostedServices)
|
||||||
{
|
{
|
||||||
this.services = services;
|
this.services = services;
|
||||||
this.mediator = mediator;
|
this.mediator = mediator;
|
||||||
this.proxyMediator = proxyMediator;
|
this.proxyMediator = proxyMediator;
|
||||||
|
this.hostedServices = hostedServices;
|
||||||
mediator.Subscribe(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WidgetConfiguration Configuration =>
|
public WidgetConfiguration Configuration =>
|
||||||
@@ -33,6 +34,11 @@ public sealed class WidgetHost :
|
|||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken = default)
|
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
foreach (IHostedService service in hostedServices)
|
||||||
|
{
|
||||||
|
await service.StartAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
if (proxyMediator.Proxy is IMediator mediator)
|
if (proxyMediator.Proxy is IMediator mediator)
|
||||||
{
|
{
|
||||||
await mediator.PublishAsync(new Started<IWidgetHost>(this),
|
await mediator.PublishAsync(new Started<IWidgetHost>(this),
|
||||||
@@ -43,8 +49,11 @@ public sealed class WidgetHost :
|
|||||||
cancellationToken);
|
cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken = default)
|
public async Task StopAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
foreach(IHostedService service in hostedServices)
|
||||||
|
{
|
||||||
|
await service.StopAsync(cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ public class WidgetHostHandler :
|
|||||||
{
|
{
|
||||||
if (notification.Value is IWidgetHost host)
|
if (notification.Value is IWidgetHost host)
|
||||||
{
|
{
|
||||||
if (host.Services.GetServices<IInitialization>() is
|
if (host.Services.GetServices<IInitializer>() is
|
||||||
IEnumerable<IInitialization> initializations)
|
IEnumerable<IInitializer> initializations)
|
||||||
{
|
{
|
||||||
foreach (IInitialization initialization in initializations)
|
foreach (IInitializer initialization in initializations)
|
||||||
{
|
{
|
||||||
await initialization.InitializeAsync();
|
await initialization.InitializeAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
namespace Hyperbar.Widget;
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
public class WidgetMonitor :
|
public class WidgetMonitor :
|
||||||
IInitialization
|
IInitializer
|
||||||
{
|
{
|
||||||
public Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ namespace Hyperbar.Widget;
|
|||||||
public class WidgetService :
|
public class WidgetService :
|
||||||
IHostedService
|
IHostedService
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<IInitialization> initializers;
|
private readonly IEnumerable<IInitializer> initializers;
|
||||||
|
|
||||||
public WidgetService(IEnumerable<IInitialization> initializers)
|
public WidgetService(IEnumerable<IInitializer> initializers)
|
||||||
{
|
{
|
||||||
this.initializers = initializers;
|
this.initializers = initializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
foreach (IInitialization initializer in initializers)
|
foreach (IInitializer initializer in initializers)
|
||||||
{
|
{
|
||||||
await initializer.InitializeAsync();
|
await initializer.InitializeAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public partial class App :
|
|||||||
args.Placement = DesktopBarPlacemenet.Top;
|
args.Placement = DesktopBarPlacemenet.Top;
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddTransient<IInitialization, AppInitializer>();
|
services.AddTransient<IInitializer, AppInitializer>();
|
||||||
|
|
||||||
services.AddSingleton<DesktopBar>();
|
services.AddSingleton<DesktopBar>();
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class AppInitializer([FromKeyedServices(nameof(WidgetViewModel))] WidgetB
|
|||||||
[FromKeyedServices(nameof(WidgetViewModel))] WidgetViewModel viewModel,
|
[FromKeyedServices(nameof(WidgetViewModel))] WidgetViewModel viewModel,
|
||||||
DesktopBar desktopFlyout,
|
DesktopBar desktopFlyout,
|
||||||
AppConfiguration configuration) :
|
AppConfiguration configuration) :
|
||||||
IInitialization
|
IInitializer
|
||||||
{
|
{
|
||||||
public Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public class ConfigurationInitializer<TConfiguration>(IMediator mediator,
|
|||||||
IConfigurationWriter<TConfiguration> writer,
|
IConfigurationWriter<TConfiguration> writer,
|
||||||
IConfigurationFactory<TConfiguration> factory) :
|
IConfigurationFactory<TConfiguration> factory) :
|
||||||
IConfigurationInitializer<TConfiguration>,
|
IConfigurationInitializer<TConfiguration>,
|
||||||
IInitialization
|
IInitializer
|
||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
class
|
class
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public interface IConfigurationMonitor<TConfiguration> :
|
public interface IConfigurationMonitor<TConfiguration> :
|
||||||
IInitialization
|
IInitializer
|
||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
class;
|
class;
|
||||||
@@ -117,7 +117,7 @@ public static class IServiceCollectionExtensions
|
|||||||
services.AddTransient<IConfigurationFactory<TConfiguration>>(provider => new ConfigurationFactory<TConfiguration>(() =>
|
services.AddTransient<IConfigurationFactory<TConfiguration>>(provider => new ConfigurationFactory<TConfiguration>(() =>
|
||||||
configuration ?? provider.GetRequiredService<TConfiguration>()));
|
configuration ?? provider.GetRequiredService<TConfiguration>()));
|
||||||
|
|
||||||
services.AddTransient<IInitialization, ConfigurationInitializer<TConfiguration>>();
|
services.AddTransient<IInitializer, ConfigurationInitializer<TConfiguration>>();
|
||||||
services.AddTransient<IConfigurationInitializer<TConfiguration>, ConfigurationInitializer<TConfiguration>>();
|
services.AddTransient<IConfigurationInitializer<TConfiguration>, ConfigurationInitializer<TConfiguration>>();
|
||||||
|
|
||||||
services.AddTransient<IWritableConfiguration<TConfiguration>, WritableConfiguration<TConfiguration>>();
|
services.AddTransient<IWritableConfiguration<TConfiguration>, WritableConfiguration<TConfiguration>>();
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public class AppService(IEnumerable<IInitialization> initializers) :
|
public class AppService(IEnumerable<IInitializer> initializers) :
|
||||||
IHostedService
|
IHostedService
|
||||||
{
|
{
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
foreach (IInitialization initializer in initializers)
|
foreach (IInitializer initializer in initializers)
|
||||||
{
|
{
|
||||||
await initializer.InitializeAsync();
|
await initializer.InitializeAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public interface IInitialization2
|
public interface IInitialization
|
||||||
{
|
{
|
||||||
ICommand Initialize { get; }
|
ICommand Initialize { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public interface IInitialization
|
public interface IInitializer
|
||||||
{
|
{
|
||||||
Task InitializeAsync();
|
Task InitializeAsync();
|
||||||
}
|
}
|
||||||
@@ -20,14 +20,17 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
INotificationHandler<Inserted<TItem>>,
|
INotificationHandler<Inserted<TItem>>,
|
||||||
INotificationHandler<Moved<TItem>>,
|
INotificationHandler<Moved<TItem>>,
|
||||||
INotificationHandler<Replaced<TItem>>,
|
INotificationHandler<Replaced<TItem>>,
|
||||||
IDisposable
|
IDisposable,
|
||||||
|
IInitialization
|
||||||
where TItem :
|
where TItem :
|
||||||
IDisposable
|
IDisposable
|
||||||
{
|
{
|
||||||
private readonly ObservableCollection<TItem> collection = new();
|
private readonly ObservableCollection<TItem> collection = [];
|
||||||
|
|
||||||
|
private bool isInitialized;
|
||||||
|
|
||||||
public ObservableCollectionViewModel(IServiceFactory serviceFactory,
|
public ObservableCollectionViewModel(IServiceFactory serviceFactory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IDisposer disposer)
|
IDisposer disposer)
|
||||||
{
|
{
|
||||||
ServiceFactory = serviceFactory;
|
ServiceFactory = serviceFactory;
|
||||||
@@ -268,11 +271,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
int IList.IndexOf(object? value) =>
|
int IList.IndexOf(object? value) =>
|
||||||
IsCompatibleObject(value) ?
|
IsCompatibleObject(value) ?
|
||||||
IndexOf((TItem)value!) : -1;
|
IndexOf((TItem)value!) : -1;
|
||||||
|
public void Insert(int index, TItem item) =>
|
||||||
public virtual async Task InitializeAsync() =>
|
|
||||||
await Mediator.PublishAsync<Enumerate<TItem>>();
|
|
||||||
|
|
||||||
public void Insert(int index, TItem item) =>
|
|
||||||
InsertItem(index, item);
|
InsertItem(index, item);
|
||||||
|
|
||||||
void IList.Insert(int index,
|
void IList.Insert(int index,
|
||||||
@@ -284,22 +283,6 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Replace(int index, TItem item)
|
|
||||||
{
|
|
||||||
if (index <= Count - 1)
|
|
||||||
{
|
|
||||||
RemoveItem(index);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
index = Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
Insert(index, item);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Move(int index, TItem item)
|
public bool Move(int index, TItem item)
|
||||||
{
|
{
|
||||||
int oldIndex = collection.IndexOf(item);
|
int oldIndex = collection.IndexOf(item);
|
||||||
@@ -314,6 +297,11 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual Task OnInitializeAsync()
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Remove(TItem item)
|
public bool Remove(TItem item)
|
||||||
{
|
{
|
||||||
int index = collection.IndexOf(item);
|
int index = collection.IndexOf(item);
|
||||||
@@ -339,7 +327,23 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
public void RemoveAt(int index) =>
|
public void RemoveAt(int index) =>
|
||||||
RemoveItem(index);
|
RemoveItem(index);
|
||||||
|
|
||||||
protected virtual void ClearItems() =>
|
public bool Replace(int index, TItem item)
|
||||||
|
{
|
||||||
|
if (index <= Count - 1)
|
||||||
|
{
|
||||||
|
RemoveItem(index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
Insert(index, item);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void ClearItems() =>
|
||||||
collection.Clear();
|
collection.Clear();
|
||||||
|
|
||||||
protected virtual void InsertItem(int index,
|
protected virtual void InsertItem(int index,
|
||||||
@@ -357,15 +361,27 @@ public partial class ObservableCollectionViewModel<TItem> :
|
|||||||
collection.Insert(index, value);
|
collection.Insert(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RemoveItem(int index) =>
|
protected virtual void RemoveItem(int index) =>
|
||||||
collection.RemoveAt(index);
|
collection.RemoveAt(index);
|
||||||
|
|
||||||
protected virtual void SetItem(int index, TItem item) =>
|
protected virtual void SetItem(int index, TItem item) =>
|
||||||
collection[index] = item;
|
collection[index] = item;
|
||||||
|
|
||||||
private static bool IsCompatibleObject(object? value) =>
|
private static bool IsCompatibleObject(object? value) =>
|
||||||
(value is TItem) || (value == null && default(TItem) == null);
|
(value is TItem) || (value == null && default(TItem) == null);
|
||||||
|
|
||||||
|
public async Task InitializeAsync()
|
||||||
|
{
|
||||||
|
if (isInitialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isInitialized = true;
|
||||||
|
|
||||||
|
await Mediator.PublishAsync<Enumerate<TItem>>();
|
||||||
|
await OnInitializeAsync();
|
||||||
|
}
|
||||||
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) =>
|
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) =>
|
||||||
CollectionChanged?.Invoke(this, args);
|
CollectionChanged?.Invoke(this, args);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user