public AlbumListViewModel(IFacebookPhotoService photoService = null, IViewStackService viewStackService = null) : base(viewStackService) { photoService = photoService ?? Locator.Current.GetService <IFacebookPhotoService>(); LoadAlbums = ReactiveCommand.CreateFromTask( async() => { var albumData = await photoService.GetAlbumsAsync(Config.Constants.FACEBOOK_PAGE_ID, Config.Constants.FACEBOOK_PAGE_ACCESS_TOKEN, default(CancellationToken)); var viewModels = new List <AlbumCellViewModel>(albumData.Data.Count); foreach (var model in albumData.Data) { var vm = new AlbumCellViewModel(model); viewModels.Add(vm); } return(viewModels); }); _albums = LoadAlbums .SubscribeOn(RxApp.TaskpoolScheduler) .ToProperty(this, vm => vm.Albums, scheduler: RxApp.MainThreadScheduler); this .WhenAnyValue(vm => vm.SelectedItem) .Where(x => x != null) .SelectMany(x => LoadSelectedPage(x)) .Subscribe(); LoadAlbums .ThrownExceptions .Subscribe(ex => this.Log().WarnException("Failed to load albums", ex)); }
public void Setup() { _viewStackService = new ViewStackService(new BenchmarkView()); _viewStackService.PushPage(new ViewModel()); _viewStackService.PushPage(new ViewModel()); _viewStackService.PushPage(new ViewModel()); }
protected BaseViewModel(IViewStackService viewStackService = null) { this.Log().Write("", GetType(), LogLevel.Info); ViewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); GoBack = ReactiveCommand.CreateFromObservable(() => ViewStackService.PopPages()); GoBackModal = ReactiveCommand.CreateFromObservable(() => ViewStackService.PopModal()); GoBackToRoot = ReactiveCommand.CreateFromObservable(() => ViewStackService.PopToRoot()); this.WhenActivated((CompositeDisposable disposable) => { GoBack .ThrownExceptions .Subscribe(x => { this.Log().ErrorException(nameof(GoBack), x); }).DisposeWith(disposable); GoBackModal .ThrownExceptions .Subscribe(x => { this.Log().ErrorException(nameof(GoBackModal), x); }).DisposeWith(disposable); GoBackToRoot .ThrownExceptions .Subscribe(x => { this.Log().ErrorException(nameof(GoBackToRoot), x); }).DisposeWith(disposable); }); }
public RedViewModel(IViewStackService viewStackService) : base(viewStackService) { PopModal = ReactiveCommand .CreateFromObservable(() => ViewStackService.PopModal(), outputScheduler: RxApp.MainThreadScheduler); PopPage = ReactiveCommand .CreateFromObservable(() => ViewStackService.PopPage(), outputScheduler: RxApp.MainThreadScheduler); PushPage = ReactiveCommand .CreateFromObservable(() => ViewStackService.PushPage(new RedViewModel(ViewStackService)), outputScheduler: RxApp.MainThreadScheduler); PopToRoot = ReactiveCommand .CreateFromObservable(() => ViewStackService.PopToRootPage(), outputScheduler: RxApp.MainThreadScheduler); PopModal.Subscribe(x => Debug.WriteLine("PagePushed")); PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe()); PopPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe()); PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe()); PopToRoot.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe()); }
public GreenViewModel(IViewStackService viewStackService) : base(viewStackService) { OpenModal = ReactiveCommand .CreateFromObservable(() => ViewStackService.PushModal(new FirstModalViewModel(viewStackService), string.Empty, false), outputScheduler: RxApp.MainThreadScheduler); }
public ViewStackServiceFixture() { View = Substitute.For <IView>(); View.PushPage(Arg.Any <IPageViewModel>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>()).Returns(Observable.Return(Unit.Default)); ModalViewModel = Substitute.For <IPageViewModel>(); PageViewModel = Substitute.For <IPageViewModel>(); ViewStackService = new ViewStackService(View); }
public PhoneAuthPhoneNumberEntryViewModel( AuthAction authAction, IObservable <Unit> whenVerified, IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null) : base(viewStackService) { _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>(); var canExecute = this.WhenAnyValue( vm => vm.PhoneNumber, phoneNumber => { return(!string.IsNullOrEmpty(phoneNumber)); }); VerifyPhoneNumber = ReactiveCommand.CreateFromObservable( () => { if (authAction == AuthAction.SignIn) { return(_firebaseAuthService .SignInWithPhoneNumber(_phoneNumber) .SelectMany(result => HandleResult(authAction, result, whenVerified))); } else { return(_firebaseAuthService.CurrentUser .LinkWithPhoneNumber(PhoneNumberTest) .SelectMany(result => HandleResult(authAction, result, whenVerified))); } }, canExecute); VerifyPhoneNumber.ThrownExceptions .Subscribe( ex => { if (ex is FirebaseAuthException firebaseEx) { switch (firebaseEx.FirebaseAuthExceptionType) { case FirebaseAuthExceptionType.FirebaseAuth: Console.WriteLine(firebaseEx.Message); break; case FirebaseAuthExceptionType.FirebaseAuthInvalidCredentials: Console.WriteLine(firebaseEx.Message); break; } Console.WriteLine(firebaseEx.Message); } else { Console.WriteLine(ex.Message); } }); }
public HomeViewModel(IViewStackService viewStackService) : base(viewStackService) { OpenModal = ReactiveCommand .CreateFromObservable(() => this.ViewStackService.PushModal(new FirstModalViewModel(ViewStackService)), outputScheduler: RxApp.MainThreadScheduler); OpenModal.Subscribe(x => Debug.WriteLine("PagePushed")); }
public RedViewModel(IViewStackService viewStackService) : base(viewStackService) { PopModal = ReactiveCommand .CreateFromObservable(() => this.ViewStackService.PopModal(), outputScheduler: RxApp.MainThreadScheduler); PopModal.Subscribe(x => Debug.WriteLine("PagePushed")); }
public TabViewModel(string tabTitle, string tabIcon, IViewStackService viewStackService, Func <IPageViewModel> pageCreate) : base(viewStackService) { TabIcon = tabIcon; TabTitle = tabTitle; this.WhenActivated(disposable => { viewStackService.PushPage(pageCreate(), resetStack: true).Subscribe().DisposeWith(disposable); }); }
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(); }
public MainViewModel(IFirebaseAuthService authService = null, IViewStackService viewStackService = null) : base(viewStackService) { _authService = authService ?? Locator.Current.GetService <IFirebaseAuthService>(); NavigateToCatalogPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new CatalogCategoryListViewModel())); }); NavigateToAlbumPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new AlbumListViewModel())); }); NavigateToStoreInfoPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new StoreInfoViewModel())); }); if (_authService.CurrentUser.Providers.Contains("phone")) { NavigateToRewardsPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new RewardsViewModel())); }); } else { NavigateToRewardsPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new RewardsProgramActivationViewModel())); }); } this.WhenActivated( d => { Disposable.Empty.DisposeWith(d); }); NavigateToCatalogPage.ThrownExceptions.Subscribe( ex => { System.Console.WriteLine(ex.Message); }); }
public CatalogItemListViewModel( string categoryId, ICatalogItemRepoFactory itemRepoFactory = null, IViewStackService viewStackService = null) { itemRepoFactory = itemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>(); viewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); var itemRepo = itemRepoFactory.Create(categoryId); LoadItems = ReactiveCommand.CreateFromObservable( () => { return(itemRepo .GetItems() .SelectMany(x => x) .Select(x => new CatalogItemCellViewModel(x, itemRepo)) .ToList() .Select(x => x as IReadOnlyList <ICatalogItemCellViewModel>)); }); _items = LoadItems.ToProperty(this, x => x.Items); var firebaseStorageService = Locator.Current.GetService <GameCtor.FirebaseStorage.DotNet.IFirebaseStorageService>(); DownloadImages = ReactiveCommand.CreateFromObservable( () => { return(Items .ToObservable() .SelectMany( itemCell => { return firebaseStorageService .GetDownloadUrl("catalogPhotos/" + itemCell.Id + ".jpg") .Catch <string, Exception>(ex => Observable.Return <string>(null)) .Where(x => x != null) .Do(imageUrl => itemCell.ImageUrl = imageUrl) .Select(_ => itemCell); }) .SelectMany( itemCell => { return itemRepo .Upsert(itemCell.Model); })); }); }
public FirstModalViewModel(IViewStackService viewStackService) : base(viewStackService) { OpenModal = ReactiveCommand .CreateFromObservable(() => this.ViewStackService.PushModal(new SecondModalViewModel(viewStackService)), outputScheduler: RxApp.MainThreadScheduler); PopModal = ReactiveCommand .CreateFromObservable(() => this.ViewStackService.PopModal(), outputScheduler: RxApp.MainThreadScheduler); OpenModal.Subscribe(x => Debug.WriteLine("PagePushed")); PopModal.Subscribe(x => Debug.WriteLine("PagePoped")); PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe()); }
public CatalogCategoryViewModel( string categoryId, ICatalogItemRepoFactory catalogItemRepoFactory = null, IViewStackService viewStackService = null) : base(viewStackService) { catalogItemRepoFactory = catalogItemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>(); ICatalogItemRepo catalogItemRepo = catalogItemRepoFactory.Create(categoryId); CatalogItems = new List <ICatalogItemCellViewModel>(); LoadCatalogItems = ReactiveCommand.CreateFromObservable( () => { return(catalogItemRepo.GetItems() .SelectMany(x => x) .Select(x => new CatalogItemCellViewModel(x) as ICatalogItemCellViewModel) .Do(x => CatalogItems.Add(x))); }); LoadCatalogItems .ThrownExceptions .Subscribe( ex => { this.Log().Debug(ex.Message); }); this .WhenAnyValue(vm => vm.SelectedItem) .Where(x => x != null) .SelectMany(x => LoadSelectedPage(x)) .Subscribe(); //this // .WhenAnyValue(vm => vm.ItemAppearing) // .Where(item => item != null && item.Id == CatalogItems[CatalogItems.Count - 1].Id) // .Select(_ => Unit.Default) // .InvokeCommand(LoadCatalogItems) // .DisposeWith(disposables); //_isRefreshing = LoadCatalogItems // .IsExecuting // .ToProperty(this, vm => vm.IsRefreshing, true); }
public HomeViewModel(IViewStackService viewStackService) : base(viewStackService) { LoadAnimals = ReactiveCommand.CreateFromObservable(() => _animalService.LoadAnimals()); _animalService = new AnimalService(); _animalService .Animals .Connect() .Group(arg => arg.AnimalGroupName) //create a dynamic group .Transform(grouping => new AnimalGroup(grouping)) .Where(x => x.Count > 0) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _animals) .DisposeMany() .Subscribe(); LoadAnimals.Subscribe(); }
public MainViewModel(AppBootstrapper appBootstrapper, IViewStackService viewStackService = null, IFirebaseAuthService firebaseAuthService = null) { viewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>(); MenuItems = GetMenuItems(); NavigateToMenuItem = ReactiveCommand.CreateFromObservable <IPageViewModel, Unit>( pageVm => viewStackService.PushPage(pageVm, resetStack: true)); this.WhenAnyValue(x => x.Selected) .Where(x => x != null) .StartWith(MenuItems.First()) .Select(x => Locator.Current.GetService <IPageViewModel>(x.TargetType.FullName)) .InvokeCommand(NavigateToMenuItem); SignOut = ReactiveCommand.Create(() => firebaseAuthService.SignOut()); SignOut.Subscribe(_ => appBootstrapper.MainView = new SignInViewModel(appBootstrapper)); }
public AutoLoginViewModel( ISchedulerService schedulerService = null, IViewStackService viewStackService = null, IAuthenticationService authenticationService = null, IRuntimeContext runtimeContext = null) : base(schedulerService, viewStackService) { _authenticationService = authenticationService ?? Locator.Current.GetService <IAuthenticationService>(); _runtimeContext = runtimeContext ?? Locator.Current.GetService <IRuntimeContext>(); this.WhenActivated((CompositeDisposable disposables) => { if (_runtimeContext.AccessToken != null && _runtimeContext.RefreshToken != null) { IsRunning = true; _authenticationService .IsTokenExpired(_runtimeContext.AccessToken) .SubscribeOn(_schedulerService.TaskPoolScheduler) .SelectMany(_ => _authenticationService .RenewSession(_runtimeContext.RefreshToken) .Catch <bool, Exception>(ex => Observable.Return(false))) .Select(isLoggedIn => isLoggedIn) .ObserveOn(_schedulerService.MainScheduler) .Select(isLoggedIn => { var navigation = isLoggedIn ? _viewStackService.PushPage(new BottomTabNavigationViewModel(), resetStack: true) : _viewStackService.PushPage(new LoginViewModel(), resetStack: true); navigation.Subscribe(); return(isLoggedIn); }) .ObserveOn(_schedulerService.TaskPoolScheduler) .Subscribe((x) => IsRunning = false);; } else { _viewStackService.PushPage(new LoginViewModel(), resetStack: true).Subscribe(); } }); }
public PhoneAuthVerificationCodeEntryViewModel( AuthAction authAction, string verificationId, IObservable <Unit> whenVerified, IFirebaseAuthService firebaseAuthService = null, IViewStackService viewStackService = null) : base(viewStackService) { _firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>(); var canExecute = this.WhenAnyValue(vm => vm.VerificationCode, code => code != null && code.Length == REQUIRED_CODE_LENGTH); VerifyCode = ReactiveCommand.CreateFromObservable( () => { if (authAction == AuthAction.SignIn) { return(_firebaseAuthService .SignInWithPhoneNumber(verificationId, VerificationCode) .SelectMany(_ => whenVerified)); } else { return(_firebaseAuthService.CurrentUser .LinkWithPhoneNumber(verificationId, VerificationCode) .ObserveOn(RxApp.MainThreadScheduler) .SelectMany(_ => whenVerified)); } }, canExecute); VerifyCode.ThrownExceptions .Subscribe( ex => { Console.WriteLine(ex.Message); }); }
public LoginViewModel(IViewStackService viewStackService) : base(viewStackService) { var canSignIn = this.WhenAnyValue( vm => vm.Email, vm => vm.Password, (email, password) => !string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password)); SignIn = ReactiveCommand.CreateFromObservable( () => { return(Observable .Timer(TimeSpan.FromSeconds(1)) .SelectMany(_ => ViewStackService.PushPage(new HomeViewModel(ViewStackService), null, true)) .TakeUntil(Cancel)); }, canSignIn); SignIn .ThrownExceptions .Subscribe( x => { System.Console.WriteLine(x); }); var canCancel = SignIn.IsExecuting; Cancel = ReactiveCommand.CreateFromObservable( () => { return(Observable .Return(Unit.Default)); }, canCancel); }
public ViewModelBase(IViewStackService viewStackService) { ViewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); ShowAlert = new Interaction <AlertViewModel, Unit>(); }
public ViewModelBase(IViewStackService viewStackService = null) { ViewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>(); }
public SettingsViewModel(IViewStackService viewStackService = null) : base(viewStackService) { }
protected ViewModelBase(IViewStackService viewStackService) { ViewStackService = viewStackService; }
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 AlbumViewModel(string albumId, IFacebookPhotoService photoService = null, IViewStackService viewStackService = null) : base(viewStackService) { photoService = photoService ?? Locator.Current.GetService <IFacebookPhotoService>(); LoadPhotos = ReactiveCommand.CreateFromTask( async() => { var photos = await photoService.GetAlbumPhotos(albumId, Config.Constants.FACEBOOK_PAGE_ACCESS_TOKEN, default(CancellationToken)); var viewModels = new List <PhotoCellViewModel>(photos.Count); foreach (var model in photos) { var vm = new PhotoCellViewModel(model); viewModels.Add(vm); } return(viewModels); }); _photos = LoadPhotos.ToProperty(this, x => x.Photos); }
public PhotoCellViewModel(FacebookPhoto model, IViewStackService viewStackService = null) : base(viewStackService) { _model = model; }
public PageViewModel(IViewStackService viewStackService) : base(viewStackService) { }
public HomeViewModel(IViewStackService viewStackService) : base(viewStackService) { PushPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new HomeViewModel(ViewStackService))); }); PushModalWithNav = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushModal(new NavigationPageViewModel(new HomeViewModel(ViewStackService)))); }); PushModalWithoutNav = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushModal(new HomeViewModel(ViewStackService))); }); PopModal = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PopModal()); }); var canPop = this.WhenAnyValue( vm => vm.PopCount, vm => vm.PageCount, (popCount, pageCount) => popCount > 0 && popCount < pageCount); PopPages = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService .PopPages(_popCount ?? 0, true)); }, canPop); var canPopToNewPage = this.WhenAnyValue( vm => vm.PageIndex, pageIndex => pageIndex >= 0 && pageIndex < PageCount); PopToNewPage = ReactiveCommand.CreateFromObservable( () => { return(Observable .Start(() => ViewStackService.InsertPage(PageIndex ?? 0, new LoginViewModel(ViewStackService)), RxApp.MainThreadScheduler) .SelectMany(_ => ViewStackService.PopToPage(PageIndex ?? 0))); }, canPopToNewPage); this.WhenActivated( disposables => { _pageCount = ViewStackService .PageStack .Select( x => { return(x != null ? x.Count : 0); }) .ToProperty(this, vm => vm.PageCount, default(int), false, RxApp.MainThreadScheduler) .DisposeWith(disposables); }); }
public BaseViewModel(IViewStackService viewStackService) { ViewStackService = viewStackService; }