59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using Ke.Bee.Localization.Localizer.Abstractions;
|
|
using Plugin.Cowain.Driver.IServices;
|
|
using Plugin.Cowain.Driver.Models;
|
|
|
|
namespace Plugin.Cowain.Driver.ViewModels;
|
|
|
|
public partial class DriverSelectedDialogViewModel : ObservableObject
|
|
{
|
|
|
|
[ObservableProperty]
|
|
private DriverInfo? _driver;
|
|
[ObservableProperty]
|
|
private List<DeviceTypeInfo>? _deviceTypes;
|
|
|
|
private readonly ILocalizer _l;
|
|
private readonly IDriverPluginService _driverService;
|
|
|
|
public DriverSelectedDialogViewModel(ILocalizer l, IDriverPluginService driverService)
|
|
{
|
|
_l = l;
|
|
_driverService = driverService;
|
|
DeviceTypes = GetDrivers(_driverService.GetDriverInfos());
|
|
}
|
|
|
|
public List<DeviceTypeInfo> GetDrivers(List<DriverInfo> driverInfoList)
|
|
{
|
|
var multiLevelDataSource = driverInfoList
|
|
.GroupBy(d => d.DeviceType)
|
|
.Select(deviceTypeGroup => new DeviceTypeInfo
|
|
{
|
|
Name = deviceTypeGroup.Key,
|
|
Groups = deviceTypeGroup
|
|
.GroupBy(d => d.Group)
|
|
.Select(groupGroup => new DriverInfoGroup
|
|
{
|
|
Name = groupGroup.Key,
|
|
Drivers = groupGroup
|
|
.Select(d => new DriverInfo
|
|
{
|
|
Name = d.Name,
|
|
DeviceType = d.DeviceType,
|
|
Group = d.Group,
|
|
Desc = d.Desc,
|
|
})
|
|
.ToList()
|
|
})
|
|
.ToList()
|
|
})
|
|
.ToList();
|
|
|
|
return multiLevelDataSource;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|