Example #1
0
        public MainViewModel()
        {
            _windowState  = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
            _dialogScreen = new DialogScreenViewModel();

            _fullScreen = new DialogScreenViewModel(NavigationTarget.FullScreen);

            _compactDialogScreen = new DialogScreenViewModel(NavigationTarget.CompactDialogScreen);

            MainScreen = new TargettedNavigationStack(NavigationTarget.HomeScreen);

            NavigationState.Register(MainScreen, DialogScreen, FullScreen, CompactDialogScreen);

            _isMainContentEnabled  = true;
            _isDialogScreenEnabled = true;
            _isFullScreenEnabled   = true;

            _statusBar = new StatusBarViewModel();

            UiServices.Initialize();

            _addWalletPage = new AddWalletPageViewModel();
            _settingsPage  = new SettingsPageViewModel();
            _privacyMode   = new PrivacyModeViewModel();
            _searchPage    = new SearchPageViewModel();
            _navBar        = new NavBarViewModel(MainScreen);

            NavigationManager.RegisterType(_navBar);

            RegisterCategories(_searchPage);
            RegisterViewModels();

            RxApp.MainThreadScheduler.Schedule(async() => await _navBar.InitialiseAsync());

            _searchPage.Initialise();

            this.WhenAnyValue(x => x.WindowState)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(windowState => Services.UiConfig.WindowState = windowState.ToString());

            this.WhenAnyValue(x => x.DialogScreen !.IsDialogOpen)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => IsMainContentEnabled = !x);

            this.WhenAnyValue(x => x.FullScreen !.IsDialogOpen)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => IsMainContentEnabled = !x);

            this.WhenAnyValue(x => x.CompactDialogScreen !.IsDialogOpen)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => IsMainContentEnabled = !x);

            if (!Services.WalletManager.HasWallet())
            {
                _dialogScreen.To(_addWalletPage, NavigationMode.Clear);
            }
        }
        public MainViewModel()
        {
            _windowState  = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
            _dialogScreen = new DialogScreenViewModel();

            _fullScreen = new DialogScreenViewModel(NavigationTarget.FullScreen);

            _compactDialogScreen = new DialogScreenViewModel(NavigationTarget.CompactDialogScreen);

            MainScreen = new TargettedNavigationStack(NavigationTarget.HomeScreen);

            NavigationState.Register(MainScreen, DialogScreen, FullScreen, CompactDialogScreen);

            _isMainContentEnabled  = true;
            _isDialogScreenEnabled = true;
            _isFullScreenEnabled   = true;

            _statusBar = new StatusBarViewModel();

            UiServices.Initialize();

            _addWalletPage = new AddWalletPageViewModel();
            _settingsPage  = new SettingsPageViewModel();
            _privacyMode   = new PrivacyModeViewModel();
            _searchPage    = new SearchPageViewModel();
            _navBar        = new NavBarViewModel(MainScreen);

            NavigationManager.RegisterType(_navBar);

            RegisterCategories(_searchPage);
            RegisterViewModels();

            RxApp.MainThreadScheduler.Schedule(async() => await _navBar.InitialiseAsync());

            _searchPage.Initialise();

            this.WhenAnyValue(x => x.WindowState)
            .Where(x => x != WindowState.Minimized)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(windowState => Services.UiConfig.WindowState = windowState.ToString());

            this.WhenAnyValue(
                x => x.DialogScreen !.IsDialogOpen,
                x => x.FullScreen !.IsDialogOpen,
                x => x.CompactDialogScreen !.IsDialogOpen)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(tup =>
            {
                var(dialogScreenIsOpen, fullScreenIsOpen, compactDialogScreenIsOpen) = tup;

                IsMainContentEnabled = !(dialogScreenIsOpen || fullScreenIsOpen || compactDialogScreenIsOpen);
            });

            this.WhenAnyValue(
                x => x.DialogScreen.CurrentPage,
                x => x.CompactDialogScreen.CurrentPage,
                x => x.FullScreen.CurrentPage,
                x => x.MainScreen.CurrentPage)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(tup =>
            {
                var(dialog, compactDialog, fullscreenDialog, mainsScreen) = tup;

                /*
                 * Order is important.
                 * Always the topmost content will be the active one.
                 */

                if (compactDialog is { })
                {
                    compactDialog.SetActive();
                    return;
                }

                if (dialog is { })