Пример #1
0
        public NavBarViewModel(IScreen screen, RoutingState router, WalletManagerViewModel walletManager)
        {
            Router         = router;
            _walletManager = walletManager;
            _topItems      = new ObservableCollection <NavBarItemViewModel>();
            _bottomItems   = new ObservableCollection <NavBarItemViewModel>();

            var addWalletPage = new AddWalletPageViewModel(screen);

            SelectedItem = new HomePageViewModel(screen, walletManager, addWalletPage);
            _topItems.Add(_selectedItem);
            _bottomItems.Add(addWalletPage);
            _bottomItems.Add(new SettingsPageViewModel(screen));

            Router.CurrentViewModel
            .OfType <NavBarItemViewModel>()
            .Subscribe(x =>
            {
                if (walletManager.Items.Contains(x) || _topItems.Contains(x) || _bottomItems.Contains(x))
                {
                    if (!_isNavigating)
                    {
                        _isNavigating = true;
                        SelectedItem  = x;
                        _isNavigating = false;
                    }
                }
            });

            this.WhenAnyValue(x => x.SelectedItem)
            .OfType <IRoutableViewModel>()
            .Subscribe(x =>
            {
                if (!_isNavigating)
                {
                    _isNavigating = true;
                    Router.NavigateAndReset.Execute(x);
                    CollapseOnClickAction?.Invoke();

                    _isNavigating = false;
                }
            });

            Observable.FromEventPattern(Router.NavigationStack, nameof(Router.NavigationStack.CollectionChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => IsBackButtonVisible = Router.NavigationStack.Count > 1);

            this.WhenAnyValue(x => x.IsOpen)
            .Subscribe(x => SelectedItem.IsExpanded = x);
        }
Пример #2
0
        private void RegisterViewModels()
        {
            HomePageViewModel.Register(_homePage);

            SearchPageViewModel.Register(_searchPage);
            PrivacyModeViewModel.Register(_privacyMode);
            AddWalletPageViewModel.Register(_addWalletPage);
            SettingsPageViewModel.Register(_settingsPage);

            GeneralSettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 0;
                return(_settingsPage);
            });

            PrivacySettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 1;
                return(_settingsPage);
            });

            NetworkSettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 2;
                return(_settingsPage);
            });

            BitcoinTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 3;
                return(_settingsPage);
            });

            AboutViewModel.RegisterLazy(() => new AboutViewModel());

            LegalDocumentsViewModel.RegisterAsyncLazy(
                async() =>
            {
                var content = await File.ReadAllTextAsync(_global.LegalDocuments.FilePath);

                var legalDocs = new LegalDocumentsViewModel(content);

                return(legalDocs);
            });
        }
Пример #3
0
        public NavBarViewModel(IScreen screen, RoutingState router, WalletManager walletManager, UiConfig uiConfig)
        {
            _screen      = screen;
            Router       = router;
            _topItems    = new ObservableCollection <NavBarItemViewModel>();
            _items       = new ObservableCollection <WalletViewModelBase>();
            _bottomItems = new ObservableCollection <NavBarItemViewModel>();

            _walletDictionary = new Dictionary <Wallet, WalletViewModelBase>();

            SelectedItem = new HomePageViewModel(screen);
            _topItems.Add(_selectedItem);
            _bottomItems.Add(new AddWalletPageViewModel(screen));
            _bottomItems.Add(new SettingsPageViewModel(screen));

            Router.CurrentViewModel
            .OfType <NavBarItemViewModel>()
            .Subscribe(x =>
            {
                if (_items.Contains(x) || _topItems.Contains(x) || _bottomItems.Contains(x))
                {
                    if (!_isNavigating)
                    {
                        _isNavigating = true;
                        SelectedItem  = x;
                        _isNavigating = false;
                    }
                }
            });

            this.WhenAnyValue(x => x.SelectedItem)
            .OfType <IRoutableViewModel>()
            .Subscribe(x =>
            {
                if (!_isNavigating)
                {
                    _isNavigating = true;
                    Router.NavigateAndReset.Execute(x);
                    CollapseOnClickAction?.Invoke();

                    _isNavigating = false;
                }
            });

            Observable.FromEventPattern(Router.NavigationStack, nameof(Router.NavigationStack.CollectionChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => IsBackButtonVisible = Router.NavigationStack.Count > 1);

            Observable
            .FromEventPattern <WalletState>(walletManager, nameof(WalletManager.WalletStateChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x =>
            {
                var wallet = x.Sender as Wallet;

                if (wallet is { } && _walletDictionary.ContainsKey(wallet))
                {
                    if (wallet.State == WalletState.Stopping)
                    {
                        RemoveWallet(_walletDictionary[wallet]);
                    }
                    else if (_walletDictionary[wallet] is ClosedWalletViewModel cwvm && wallet.State == WalletState.Started)
                    {
                        OpenClosedWallet(walletManager, uiConfig, cwvm);
                    }
                }

                AnyWalletStarted = Items.OfType <WalletViewModelBase>().Any(x => x.WalletState == WalletState.Started);
            });
Пример #4
0
        public MainViewModel(Global global)
        {
            _global = global;

            _dialogScreen = new DialogScreenViewModel();

            MainScreen = new TargettedNavigationStack(NavigationTarget.HomeScreen);

            NavigationState.Register(MainScreen, DialogScreen, () => this);

            Network = global.Network;

            _currentDialog = null;

            _isMainContentEnabled  = true;
            _isDialogScreenEnabled = true;

            _statusBar = new StatusBarViewModel(
                global.DataDir,
                global.Network,
                global.Config,
                global.HostedServices,
                global.BitcoinStore.SmartHeaderChain,
                global.Synchronizer,
                global.LegalDocuments);

            var walletManager = new WalletManagerViewModel(global.WalletManager, global.UiConfig);

            _addWalletPage = new AddWalletPageViewModel(
                global.LegalDocuments,
                global.WalletManager,
                global.BitcoinStore,
                global.Network);

            _settingsPage = new SettingsPageViewModel(global.Config, global.UiConfig);
            _privacyMode  = new PrivacyModeViewModel(global.UiConfig);
            _homePage     = new HomePageViewModel(walletManager, _addWalletPage);
            _searchPage   = new SearchPageViewModel();

            _navBar = new NavBarViewModel(MainScreen, walletManager);

            RegisterCategories(_searchPage);
            RegisterViewModels();

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

            _searchPage.Initialise();

            MainScreen.To(_homePage);

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

            this.WhenAnyValue(x => x.CurrentDialog !.IsDialogOpen)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(x => IsDialogScreenEnabled = !x);

            walletManager.WhenAnyValue(x => x.Items.Count)
            .Subscribe(x => _navBar.IsHidden = x == 0);
        }
Пример #5
0
        private void RegisterViewModels()
        {
            HomePageViewModel.Register(_homePage);

            SearchPageViewModel.Register(_searchPage);
            PrivacyModeViewModel.Register(_privacyMode);
            AddWalletPageViewModel.Register(_addWalletPage);
            SettingsPageViewModel.Register(_settingsPage);

            GeneralSettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 0;
                return(_settingsPage);
            });

            PrivacySettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 1;
                return(_settingsPage);
            });

            NetworkSettingsTabViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 2;
                return(_settingsPage);
            });

            BitcoinTabSettingsViewModel.RegisterLazy(
                () =>
            {
                _settingsPage.SelectedTab = 3;
                return(_settingsPage);
            });

            AboutViewModel.RegisterLazy(() => new AboutViewModel());

            BroadcastTransactionViewModel.RegisterAsyncLazy(
                async() =>
            {
                var result = await DialogScreen.NavigateDialog(new LoadTransactionViewModel(_global.Network));

                if (result is { })
                {
                    while (_global.TransactionBroadcaster is null)
                    {
                        await Task.Delay(100);
                    }

                    DialogScreen.Back();

                    return(new BroadcastTransactionViewModel(
                               _global.BitcoinStore,
                               _global.Network,
                               _global.TransactionBroadcaster,
                               result));
                }

                DialogScreen.Back();

                return(null);
            });