public CatalogCategoryListViewModel(ICatalogCategoryRepo catalogCategoryRepo = null, IViewStackService viewStackService = null) : base(viewStackService) { catalogCategoryRepo = catalogCategoryRepo ?? Locator.Current.GetService <ICatalogCategoryRepo>(); LoadCatalogCategories = ReactiveCommand.CreateFromObservable( () => { return(catalogCategoryRepo.GetItems() .SelectMany(x => x) .Select(x => new CatalogCategoryCellViewModel(x) as ICatalogCategoryCellViewModel) .ToList() .Select(x => x as IReadOnlyList <ICatalogCategoryCellViewModel>) .SubscribeOn(RxApp.TaskpoolScheduler)); }); _catalogCategories = LoadCatalogCategories .ToProperty(this, x => x.CatalogCategories, scheduler: RxApp.MainThreadScheduler); this .WhenAnyValue(vm => vm.SelectedItem) .Where(x => x != null) .SelectMany(x => ViewStackService.PushPage(new CatalogCategoryViewModel(x.Id))) .Subscribe(); _isRefreshing = LoadCatalogCategories .IsExecuting .ToProperty(this, vm => vm.IsRefreshing, true); }
public CatalogSynchronizer( ICatalogCategoryRepo categoryRepo = null, ICatalogItemRepoFactory itemRepoFactory = null, IAdminVarRepo adminVarRepo = null) { _categoryRepo = categoryRepo ?? Locator.Current.GetService <ICatalogCategoryRepo>(); _itemRepoFactory = itemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>(); _adminVarRepo = adminVarRepo ?? Locator.Current.GetService <IAdminVarRepo>(); }
public CatalogCategoryListViewModel( ICatalogCategoryRepo categoryRepo = null, ICatalogSynchronizer catalogSynchronizer = null, IViewStackService viewStackService = null) { categoryRepo = categoryRepo ?? Locator.Current.GetService <ICatalogCategoryRepo>(); catalogSynchronizer = catalogSynchronizer ?? Locator.Current.GetService <ICatalogSynchronizer>(); viewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); _categoryCache = new SourceCache <CatalogCategory, string>(x => x.Id); SyncWithPosSystem = ReactiveCommand.CreateFromObservable( () => { return(catalogSynchronizer .PullFromPosSystemAndStoreInFirebase(_categoryCache)); }); LoadCategories = ReactiveCommand.CreateFromObservable( () => { return(categoryRepo .GetItems() .Do(x => _categoryCache.AddOrUpdate(x)) .Select(_ => Unit.Default)); }); //LoadCategories.InvokeCommand(this, x => x.SyncWithPosSystem); _categoryCache .Connect() //.Filter(dynamicFilter) .Transform(x => new CatalogCategoryCellViewModel(x, categoryRepo) as ICatalogCategoryCellViewModel) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _categoryCells) .DisposeMany() .Subscribe(); NavigateToCategory = ReactiveCommand.CreateFromObservable <ICatalogCategoryCellViewModel, Unit>( categoryCell => { return(viewStackService.PushPage(new CatalogItemListViewModel(categoryCell.Id))); }); this .WhenAnyValue(x => x.SelectedItem) .Where(x => x != null) .SelectMany(categoryCell => viewStackService.PushPage(new CatalogItemListViewModel(categoryCell.Id))) .Subscribe(); }