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? _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 GetDrivers(List 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; } }