private async Task LogoutCommandExecute() { if (await _firebaseAuthService.Logout()) { await NavigationService.NavigateToAsync <LoginViewModel>(); } }
public RegistrationTypeSelectionPageViewModel( INavigationService navigationService, IAnalyticService analyticService, IFirebaseAuthService authService, IUserDialogs dialogs) : base(navigationService) { Title = "Registration Type"; analyticService.TrackScreen("registration-type"); Tradesman = ReactiveCommand.CreateFromTask(async() => { await dialogs.AlertAsync("Coming Soon!").ConfigureAwait(false); analyticService.TrackTapEvent("register-as-tradesman"); //await navigationService.NavigateAsync(nameof(TradesmentRegistrationPage)).ConfigureAwait(false); }); Contractor = ReactiveCommand.CreateFromTask(async() => { analyticService.TrackTapEvent("register-as-contractor"); await navigationService.NavigateAsync( nameof(ContractorRegistrationPage), new NavigationParameters { { "user_id", _userId } }).ConfigureAwait(false); }); GoBack = ReactiveCommand.CreateFromTask <Unit, Unit>(async _ => { var result = await dialogs.ConfirmAsync( new ConfirmConfig { Title = "Cancel Account Creation?", Message = "Are you sure you want to cancel account creation? This will discard any information you have entered so far", OkText = "Yes", CancelText = "No" }); if (result) { analyticService.TrackTapEvent("cancel-account-creation"); // make sure we log out so the user has to log in again await authService.Logout(); await NavigationService.NavigateToLoginPageAsync().ConfigureAwait(false); } return(Unit.Default); }); NavigatingTo .Where(args => args.ContainsKey("user_id")) .Select(args => args["user_id"].ToString()) .BindTo(this, x => x._userId); }
public ExtendedSplashPageViewModel( INavigationService navigationService, IContainerRegistry containerRegistry, IUserDataStore userDataStore, IFirebaseAuthService firebaseAuthService) : base(navigationService) { const int Home = 1; const int Login = 2; Initialize = ReactiveCommand.CreateFromTask(async() => { // make sure we're running this on a background thread this.Log().Debug($"Loading projects on thread: {Thread.CurrentThread.ManagedThreadId}, IsBackground = {Thread.CurrentThread.IsBackground}"); AssertRunningOnBackgroundThread(); if (firebaseAuthService.IsUserSigned()) { var currentUserId = firebaseAuthService.GetCurrentUserId(); if (string.IsNullOrWhiteSpace(currentUserId)) { await firebaseAuthService.Logout(); return(Login); } // try to get the user from our database var user = await userDataStore.GetUserById(currentUserId); if (user == null) { await firebaseAuthService.Logout(); return(Login); } containerRegistry.RegisterInstance <IUserService>(new UserService(user)); return(Home); } return(Login); }); Initialize .SubscribeOn(RxApp.MainThreadScheduler) .SelectMany(async nextPage => { if (nextPage == Home) { await NavigationService.NavigateHomeAsync().ConfigureAwait(false); } else { await NavigationService.NavigateToLoginPageAsync().ConfigureAwait(false); } return(Observable.Return(Unit.Default)); }) .Subscribe(); // when the command is executing, update the busy state Initialize.IsExecuting .StartWith(false) .ToProperty(this, x => x.IsBusy, out _isBusy); Initialize.ThrownExceptions .Subscribe(exception => System.Diagnostics.Debug.WriteLine($"Error: {exception}")); }
public RootPageViewModel( INavigationService navigationService, IUserService userService, IFirebaseAuthService firebaseAuthService) : base(navigationService) { User = userService.AuthenticatedUser; MenuItems = new ReactiveList <CustomMenuItem> { new CustomMenuItem { Title = "Home", IconSource = "\xf015", TapCommand = CreateNavigationCommand($"Details/{nameof(MainPage)}?page={nameof(ProjectsPage)}") }, //new CustomMenuItem //{ // Title = "Messages", // IconSource = "\xf0e0", // TapCommand = CreateNavigationCommand($"Details/{nameof(Messages.MessagesPage)}") //}, //new CustomMenuItem //{ // Title = "Communities", // IconSource = "\xf0c0", // TapCommand = CreateNavigationCommand($"Details/{nameof(CommunitiesPage)}") //}, //new CustomMenuItem //{ // Title = "Explore", // IconSource = "\xf002" //}, new CustomMenuItem { Title = "Contact Us", IconSource = "\xf007", TapCommand = CreateNavigationCommand($"{nameof(ModalNavigationPage)}/{nameof(ContactUsPage)}", useModalNavigation: true) }, new CustomMenuItem { Title = "About Us", IconSource = "\xf05a", TapCommand = CreateNavigationCommand($"{nameof(ModalNavigationPage)}/{nameof(AboutUsPage)}", useModalNavigation: true) }, new CustomMenuItem { Title = "Privacy Policy", IconSource = "\xf3ed", TapCommand = CreateNavigationCommand($"{nameof(ModalNavigationPage)}/{nameof(PrivacyPolicyPage)}", useModalNavigation: true) }, new CustomMenuItem { Title = "Sign Out", IconSource = "\xf2f5", TapCommand = ReactiveCommand.CreateFromTask(async() => { await firebaseAuthService.Logout(); await NavigationService.NavigateToLoginPageAsync().ConfigureAwait(false); }) } }; ViewProfile = ReactiveCommand.CreateFromTask(async() => { var parameters = new NavigationParameters { { "user", User } }; await NavigationService .NavigateAsync($"Details/{nameof(ProfileViewTabbedPage)}", parameters) .ConfigureAwait(false); }); IObservable <Exception> commandObservable = null; foreach (var item in MenuItems.Where(x => x.TapCommand != null)) { if (commandObservable == null) { commandObservable = item.TapCommand.ThrownExceptions; } else { commandObservable = commandObservable.Merge(item.TapCommand.ThrownExceptions); } } if (commandObservable != null) { commandObservable .SelectMany(exception => { this.Log().ErrorException("Error in menu items", exception); return(SharedInteractions.Error.Handle(exception)); }) .Subscribe(); } ReactiveCommand <Unit, Unit> CreateNavigationCommand(string path, bool?useModalNavigation = null) { return(ReactiveCommand.CreateFromTask(async() => await NavigationService .NavigateAsync(path, useModalNavigation: useModalNavigation) .ConfigureAwait(false))); } }