public FilterViewModel(ClothesNavigationParameters navigateParameters, IReadOnlyCollection <ClothesViewModelItem> clothes, ReactiveCommand <Unit, IReadOnlyList <ClothesViewModelItem> > clothesFilterCommand) { FilterSizeViewModelItems = FilterAndSortingViewModelFactory.GetFilterSizes(clothes, navigateParameters.ClothesTypeDomain.SizeTypeDefault, clothesFilterCommand); FilterColorViewModelItems = FilterAndSortingViewModelFactory.GetFilterColors(clothes, clothesFilterCommand); FilterPriceViewModelItem = FilterAndSortingViewModelFactory.GetFilterPrices(clothes, clothesFilterCommand); }
public ClothesViewModel(IClothesRestService clothesRestService, IClothesNavigationService clothesNavigationService, IChoiceNavigationService choiceNavigationService, IClothesDetailNavigationService clothesDetailNavigationService) : base(clothesNavigationService) { _clothes = this.WhenAnyValue(x => x.NavigationParameters). Where(clothesParameters => clothesParameters != null). SelectMany(parameters => Observable.FromAsync(() => GetClothes(parameters, clothesRestService, clothesDetailNavigationService))). ToProperty(this, nameof(Clothes), scheduler: RxApp.MainThreadScheduler); ClothesFilterCommand = ReactiveCommand.Create <Unit, IReadOnlyList <ClothesViewModelItem> >( _ => FilterAndSortingViewModelFactory.GetClothesFiltered(Clothes, FilterViewModel.ClothesFilters, SortingViewModel.ClothesSortingType)); _sortingViewModel = Observable.Return(new SortingViewModel(ClothesFilterCommand)). ToProperty(this, nameof(SortingViewModel)); _filterViewModel = this.WhenAnyValue(x => x.Clothes, x => x.NavigationParameters, (clothes, parameters) => (clothes, parameters)). Where(clothesNavigation => clothesNavigation.clothes != null && clothesNavigation.parameters != null). Select(clothesNavigation => new FilterViewModel(clothesNavigation.parameters !, clothesNavigation.clothes, ClothesFilterCommand)). ToProperty(this, nameof(FilterViewModel)); _clothesFiltered = this.WhenAnyValue(x => x.FilterViewModel). Where(filterViewModel => filterViewModel != null). SelectMany(filterViewModel => ClothesFilterCommand). ToProperty(this, nameof(ClothesFiltered)); _clothesViewModelColumnItems = this.WhenAnyValue(x => x.ClothesFiltered). Where(clothes => clothes != null). Select(GetClothesItems). ToProperty(this, nameof(ClothesViewModelColumnItems)); ImagesCommand = ReactiveCommand.CreateFromObservable <int, ImageSource>( itemIndex => ClothesViewModelColumnItems[itemIndex].ClothesViewModelItemLeft !. ImageCommand.Execute(Unit.Default)); ChoiceNavigateCommand = ReactiveCommand.CreateFromTask(_ => choiceNavigationService.NavigateTo(new ChoiceNavigationParameters())); this.WhenAnyValue(x => x.Clothes, x => x.FilterViewModel, (clothes, filterViewModel) => (clothes, filterViewModel)). Where(clothes => clothes.clothes != null && clothes.filterViewModel != null). Select(_ => Unit.Default). InvokeCommand(ClothesFilterCommand); }